Class Scope
- All Implemented Interfaces:
UseKey
Manages scope hierarchy and variable access across different context levels in the engine.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddefineVariable(String name) Define a variable in the current scope.Get the name of the application where this scope resides.Get the name of the application where this scope resides as an Optional.getKey()Get a unique key for this scope based on application and substance.Get the name of the stanza where this scope resides.Get the name of the stanza where this scope resides as an Optional.Get the name of the substance where this scope resides.Get the name of the substance where this scope resides as an Optional.getVariable(String name) Get the value of a variable already defined.getWithApplication(String newApplication) Create a new scope derived from this scope at the application level.getWithStanza(String newStanza) Create a new scope derived from this scope at the stanza level.getWithSubstance(String newSubstance) Create a new scope derived from this scope at the substance level.voidsetVariable(String name, EngineNumber value) Set the value of a variable already defined.
-
Constructor Details
-
Scope
Convenience constructor for creating a scope without a variable manager.- Parameters:
stanza- The name of stanza or null if in global scopeapplication- The name of the application or null if in stanza or higher scopesubstance- The name of the substance or null if in application or higher scope
-
Scope
Create a new scope.- Parameters:
stanza- The name of stanza or null if in global scopeapplication- The name of the application or null if in stanza or higher scopesubstance- The name of the substance or null if in application or higher scopevariableManager- The variable manager to reach variables accessible from this scope or null if no variables accessible
-
Scope
public Scope()Default constructor for creating a global scope with no context.Creates a scope with all empty contexts (stanza, application, substance, and key). This is useful for initializing a scope at the global level.
-
-
Method Details
-
getStanza
Get the name of the stanza where this scope resides.- Returns:
- The name of the current stanza or null if in global scope
-
getStanzaOptional
Get the name of the stanza where this scope resides as an Optional.- Returns:
- Optional containing the name of the current stanza, or empty if in global scope
-
getApplication
Get the name of the application where this scope resides.- Specified by:
getApplicationin interfaceUseKey- Returns:
- The name of the current application or null if in stanza or higher scope
-
getApplicationOptional
Get the name of the application where this scope resides as an Optional.- Returns:
- Optional containing the name of the current application, or empty if in stanza or higher scope
-
getSubstance
Get the name of the substance where this scope resides.- Specified by:
getSubstancein interfaceUseKey- Returns:
- The name of the current substance or null if in application or higher scope
-
getSubstanceOptional
Get the name of the substance where this scope resides as an Optional.- Returns:
- Optional containing the name of the current substance, or empty if in application or higher scope
-
getWithSubstance
Create a new scope derived from this scope at the substance level.- Parameters:
newSubstance- The name of the substance in which the new scope resides- Returns:
- New scope at the given substance
-
getWithApplication
Create a new scope derived from this scope at the application level.- Parameters:
newApplication- The name of the application in which the new scope resides- Returns:
- New scope at the given application
-
getWithStanza
Create a new scope derived from this scope at the stanza level.- Parameters:
newStanza- The name of the stanza in which the new scope resides- Returns:
- New scope at the given stanza
-
defineVariable
Define a variable in the current scope.Define a new variable in the current scope or throw an error if a variable of this name already exists in this scope at the current context level.
- Parameters:
name- The name of the variable to define
-
setVariable
Set the value of a variable already defined.Set the value of a variable or throw an error if no variable of the given name is accessible from the current scope.
- Parameters:
name- The name of the variable to setvalue- The new value of the variable
-
getVariable
Get the value of a variable already defined.Get the value of a variable or throw an error if no variable of the given name is accessible from the current scope.
- Parameters:
name- The name of the variable to get- Returns:
- Value of the given variable
-
getKey
Get a unique key for this scope based on application and substance.The key is lazily initialized and cached. It consists of the application and substance names separated by a tab character, with "-" used for null values.
-