Class HintManager
Hint Tracking
Type hints are tracked in scopes which are generally equivalent to sections. However, there may be additional scopes that are not associated with sections. These scopes may be used for a variety of reasons. For example, a non-section scope could be used for capturing the hints of a section. These hints could be filtered before being passed back up.
When entering a scope (enterScope(boolean)
), it is initialized with the hints of the previous top-level scope.
When exiting a scope (exitScope()
), remaining hints from that scope are added to the existing hints of the new top-level scope.
This merging of scopes is provided and described by mergeScope(int, int, boolean)
.
Thus, it is only necessary to obtain hints for the current scope.
get(Variable)
is provided for obtaining the hints of a variable in the current scope.
It is possible to disable the collection and usage of hints through the activity state of a manager.
See setActive(boolean)
and isActive
for detailed information.
Hint Modification
The standard syntax where hints are modified is the Change Effect (EffChange
).
Consider the following basic SET example:
set {_x} to 5
# hint for {_x} is Integer.class
A SET operation overrides all existing type hints for a variable in the current scope (see set(Variable, Class[])
).
In a more advanced example, we can see how hints are shared between scopes:
set {_x} to 5
# hint for {_x} is Integer.class
if <some condition>:
set {_x} to true
# hint for {_x} is Boolean.class
# here, it is not known if the section above would have executed
# we consider all possible values
# thus, hints for {_x} are Integer.class and Boolean.class
ADD is another considered operation (see add(Variable, Class[])
).
Consider the following example:
add 5 to {_x::*}
# hint for {_x::*} is Integer.class
Essentially, an ADD operation is handled similarly to a SET operation, but hints are combined rather than overridden,
as the list may contain other types.
Note that REMOVE is not a handled operation, as a list variable might contain multiple values of some type.
However, for use cases where applicable, remove(Variable, Class[])
is provided.
Finally, a DELETE operation (see delete(Variable)
) allows us to trim down context where applicable.
Consider the following examples:
set {_x} to 5
# hint for {_x} is Integer.class
delete {_x}
# now, there are no hints for {_x}
set {_x} to 5
# hint for {_x} is Integer.class
if <some condition>:
delete {_x}
# now, there are no hints for {_x}
# the previous section no longer had hints for {_x}, so there is nothing to copy over
# thus, hint for {_x} is Integer.class
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Represents a snapshot of a scope. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds hints forvariable
in the current scope.void
Adds hints forvariableName
in the current scope.backup()
static boolean
canUseHints
(Variable<?> variable) void
clearScope
(int level, boolean sectionOnly) Resets (clears) all type hints for the current (top-level) scope.void
Deletes hints forvariable
in the current scope.void
Deletes hints forvariableName
in the current scope.void
enterScope
(boolean isSection) Enters a new scope for storing hints.void
Exits the current (top-level) scope.Obtains the type hints forvariable
in the current scope.Obtains the type hints forvariableName
in the current scope.boolean
isActive()
void
mergeScope
(int from, int to, boolean sectionOnly) Copies hints from one scope to another.void
Removes hints forvariable
in the current scope.void
Removes hints forvariableName
in the current scope.void
restore
(HintManager.Backup backup) Overwrites the current scope with the scope represented inbackup
.void
Overrides hints forvariable
in the current scope.void
Overrides hints forvariableName
in the current scope.void
setActive
(boolean active) Marks this hint manager as active or inactive.
-
Constructor Details
-
HintManager
public HintManager(boolean active)
-
-
Method Details
-
setActive
public void setActive(boolean active) Marks this hint manager as active or inactive. An inactive hint manager does not collect hints. That is, actions such as setting, adding, etc. have no effect on the currently stored hints. Additionally, any calls to obtain hints will always result in an empty collection. As a result, type hints are effectively not used.- Parameters:
active
- Whether this hint manager should be active.- See Also:
-
isActive
public boolean isActive()- Returns:
- Whether this manager is active.
- See Also:
-
enterScope
public void enterScope(boolean isSection) Enters a new scope for storing hints. Hints from the previous (current top-level) scope are copied over.- Parameters:
isSection
- Whether this scope represents a section in a trigger.- See Also:
-
exitScope
public void exitScope()Exits the current (top-level) scope. Hints from the exited scope will be copied over to the new top-level scope.- See Also:
-
clearScope
public void clearScope(int level, boolean sectionOnly) Resets (clears) all type hints for the current (top-level) scope. Scopes are represented as integers, where0
represents the most recently entered scope. For example, after callingenterScope(boolean)
,0
would represent the scope just entered by calling the method, and1
would represent the most recently entered scope before calling the method.- Parameters:
sectionOnly
- Whether only scopes representing sections should be considered.
-
mergeScope
public void mergeScope(int from, int to, boolean sectionOnly) Copies hints from one scope to another. Scopes are represented as integers, where0
represents the most recently entered scope. For example, after callingenterScope(boolean)
,0
would represent the scope just entered by calling the method, and1
would represent the most recently entered scope before calling the method.Note: This does not overwrite the existing hints of
to
. Instead, the hints are merged together.- Parameters:
from
- The scope to copy hints from.to
- The scope to copy hints to.sectionOnly
- Whether only scopes representing sections should be considered.
-
set
Overrides hints forvariable
in the current scope.- Parameters:
variable
- The variable to sethints
for.hints
- The hint(s) to set forvariable
.- See Also:
-
set
Overrides hints forvariableName
in the current scope.- Parameters:
variableName
- The name of the variable to sethints
for.hints
- The hint(s) to set forvariableName
.- See Also:
-
delete
Deletes hints forvariable
in the current scope.- Parameters:
variable
- The variable to clear hints for.- See Also:
-
delete
Deletes hints forvariableName
in the current scope.- Parameters:
variableName
- The name of the variable to clear hints for.- See Also:
-
add
Adds hints forvariable
in the current scope.- Parameters:
variable
- The variable to addhints
to.hints
- The hint(s) to add forvariable
.- See Also:
-
add
Adds hints forvariableName
in the current scope.- Parameters:
variableName
- The name of the variable to addhints
to.hints
- The hint(s) to add forvariableName
.- See Also:
-
remove
Removes hints forvariable
in the current scope.- Parameters:
variable
- The variable to removehints
from.hints
- The hint(s) to remove forvariable
.- See Also:
-
remove
Removes hints forvariableName
in the current scope.- Parameters:
variableName
- The name of the variable to addhints
to.hints
- The hint(s) to remove forvariableName
.- See Also:
-
get
Obtains the type hints forvariable
in the current scope.- Parameters:
variable
- The variable to get hints from.- Returns:
- An unmodifiable set of hints.
- See Also:
-
get
Obtains the type hints forvariableName
in the current scope.- Parameters:
variableName
- The name of the variable to get hints from.- Returns:
- An unmodifiable set of hints.
- See Also:
-
backup
- Returns:
- A backup of this manager's current scope.
-
restore
Overwrites the current scope with the scope represented inbackup
.- Parameters:
backup
- The backup to apply.
-
canUseHints
- Parameters:
variable
- The variable to check.- Returns:
- Whether hints can be used for
variable
.
-