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
-
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.int
getOccurrenceCount
(String name) Get how many times a variable was declared in the current scope.boolean
isDeclared
(String name) Checks if the variable identified byname
is tracked by this tracker or not.boolean
isEmpty()
Checks if the declaration stack is empty.boolean
Check 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.void
pushVariable
(String name, T data) Pushes a variable to this tracker.
-
Constructor Details
-
VariableTracker
public VariableTracker()
-
-
Method Details
-
isDeclared
Checks if the variable identified byname
is tracked by this tracker or not.- Parameters:
name
- the name of the variable- Returns:
true
if the variable is declared,false
otherwise
-
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:
true
if the stack is empty,false
otherwise
-
get
Get the data associated with the given variable.- Parameters:
name
- the name of the variable- Returns:
- the associated data or
null
if 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:
true
if the variable is visible in the current scope,false
otherwise
-
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
-