Class VariableTracker<T>
- java.lang.Object
-
- org.apache.sling.scripting.sightly.compiler.util.VariableTracker<T>
-
public final class VariableTracker<T> extends java.lang.ObjectTracks information related to HTL variables, at different levels of the compiler.
-
-
Constructor Summary
Constructors Constructor Description VariableTracker()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tget(java.lang.String name)Get the data associated with the given variable.java.util.List<T>getAll(java.lang.String name)Get an immutable view of all the data items associated with the specified variable.intgetOccurrenceCount(java.lang.String name)Get how many times a variable was declared in the current scope.booleanisDeclared(java.lang.String name)Checks if the variable identified bynameis tracked by this tracker or not.booleanisEmpty()Checks if the declaration stack is empty.booleanisInScope(java.lang.String name)Check whether a variable was declared and is visible in the current scope.java.util.Map.Entry<java.lang.String,T>peek()Peeks at the top of the declaration stack.java.lang.StringpopVariable()Pops a variable from this tracker.voidpushVariable(java.lang.String name, T data)Pushes a variable to this tracker.
-
-
-
Method Detail
-
isDeclared
public boolean isDeclared(java.lang.String name)
Checks if the variable identified bynameis tracked by this tracker or not.- Parameters:
name- the name of the variable- Returns:
trueif the variable is declared,falseotherwise
-
pushVariable
public void pushVariable(java.lang.String name, T data)Pushes a variable to this tracker. Call this method whenever a variable is declared.- Parameters:
name- the name of the variabledata- the data associated with the variable
-
popVariable
public java.lang.String popVariable()
Pops a variable from this tracker. Call this method whenever a variable goes out of scope.- Returns:
- the name of the popped variable
- Throws:
java.util.NoSuchElementException- if there are no declared variables in the scope
-
peek
public java.util.Map.Entry<java.lang.String,T> peek()
Peeks at the top of the declaration stack.- Returns:
- the most recently declared variable and its associated data
- Throws:
java.util.NoSuchElementException- if there are no variables in scope
-
isEmpty
public boolean isEmpty()
Checks if the declaration stack is empty.- Returns:
trueif the stack is empty,falseotherwise
-
get
public T get(java.lang.String name)
Get the data associated with the given variable.- Parameters:
name- the name of the variable- Returns:
- the associated data or
nullif that variable is not in scope
-
isInScope
public boolean isInScope(java.lang.String name)
Check whether a variable was declared and is visible in the current scope.- Parameters:
name- the name of the variable- Returns:
trueif the variable is visible in the current scope,falseotherwise
-
getAll
public java.util.List<T> getAll(java.lang.String name)
Get an immutable view of all the data items associated with the specified variable.- Parameters:
name- the name of the variable- Returns:
- a list of all the data associated with this variable name. If the variable is not declared in the current scope then that list will be empty. Otherwise it will contain all the data associated for the current scope starting with the data associated at the topmost scope and ending with the most recently associated data
-
getOccurrenceCount
public int getOccurrenceCount(java.lang.String name)
Get how many times a variable was declared in the current scope.- Parameters:
name- the name of the variable- Returns:
- the number of declarations for a variable in the current scope
-
-