Class Scope
java.lang.Object
org.inferred.freebuilder.processor.source.Scope
- Direct Known Subclasses:
CompilationUnitBuilder.InitialScope,Scope.FileScope,Scope.MethodScope
An append-only, hierarchical map with key-specific value typing.
Scopes allow source generators to cooperate with each other—to avoid namespace clashes
or reuse variables, for example—in a decoupled fashion using a shared key-value space.
The key type dictates the type of the value that can be stored in the map, as well as at what
level in the source the key should be unique at: FILE keys are unique within a
compilation unit, while METHOD keys are scoped to the current method.
While a Scope has to be mutable, it limits the potential for complex bugs by only permitting key-values pairs to be inserted, not modified or removed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classstatic interfacestatic enum(package private) static class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean<V> VcomputeIfAbsent(Scope.Key<V> key, Supplier<V> supplier) Ifkeyis not already associated with a value, computes its value usingsupplierand enters it into the scope.boolean<V> VbooleanisEmpty()<V> Set<V> keysOfType(Class<V> keyType) <V> VputIfAbsent(Scope.Key<V> key, V value) Ifkeyis not already associated with a value, associates it withvalue.
-
Field Details
-
RECURSION_SENTINEL
-
entries
-
parent
-
-
Constructor Details
-
Scope
protected Scope() -
Scope
-
-
Method Details
-
canStore
-
isEmpty
public boolean isEmpty() -
contains
-
get
-
computeIfAbsent
Ifkeyis not already associated with a value, computes its value usingsupplierand enters it into the scope.- Returns:
- the current (existing or computed) value associated with
key
-
keysOfType
-
putIfAbsent
Ifkeyis not already associated with a value, associates it withvalue.- Returns:
- the original value, or
nullif there was no value associated
-