Class VariableTracker<T>
java.lang.Object
org.apache.sling.scripting.sightly.compiler.util.VariableTracker<T>
Tracks information related to HTL variables, at different levels of the compiler.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the data associated with the given variable.Get an immutable view of all the data items associated with the specified variable.intgetOccurrenceCount(String name) Get how many times a variable was declared in the current scope.booleanisDeclared(String name) Checks if the variable identified bynameis tracked by this tracker or not.booleanisEmpty()Checks if the declaration stack is empty.booleanCheck whether a variable was declared and is visible in the current scope.peek()Peeks at the top of the declaration stack.Pops a variable from this tracker.voidpushVariable(String name, T data) Pushes a variable to this tracker.
-
Constructor Details
-
VariableTracker
public VariableTracker()
-
-
Method Details
-
isDeclared
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
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
Pops a variable from this tracker. Call this method whenever a variable goes out of scope.- Returns:
- the name of the popped variable
- Throws:
NoSuchElementException- if there are no declared variables in the scope
-
peek
Peeks at the top of the declaration stack.- Returns:
- the most recently declared variable and its associated data
- Throws:
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
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
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
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
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
-