public abstract class Scope
extends java.lang.Object
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.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Scope.Key<V> |
static class |
Scope.Level |
| Modifier | Constructor and Description |
|---|---|
protected |
Scope() |
protected |
Scope(Scope parent) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract boolean |
canStore(Scope.Key<?> key) |
<V> V |
computeIfAbsent(Scope.Key<V> key,
java.util.function.Supplier<V> supplier)
If
key is not already associated with a value, computes its value using
supplier and enters it into the scope. |
boolean |
contains(Scope.Key<?> key) |
<V> V |
get(Scope.Key<V> key) |
boolean |
isEmpty() |
<V> java.util.Set<V> |
keysOfType(java.lang.Class<V> keyType) |
<V> V |
putIfAbsent(Scope.Key<V> key,
V value)
If
key is not already associated with a value, associates it with value. |
protected Scope()
protected Scope(Scope parent)
protected abstract boolean canStore(Scope.Key<?> key)
public boolean isEmpty()
public boolean contains(Scope.Key<?> key)
public <V> V get(Scope.Key<V> key)
public <V> V computeIfAbsent(Scope.Key<V> key, java.util.function.Supplier<V> supplier)
key is not already associated with a value, computes its value using
supplier and enters it into the scope.keypublic <V> java.util.Set<V> keysOfType(java.lang.Class<V> keyType)
public <V> V putIfAbsent(Scope.Key<V> key, V value)
key is not already associated with a value, associates it with value.null if there was no value associated