Class RestrictedExpression<T>
java.lang.Object
io.github.syst3ms.skriptparser.lang.base.RestrictedExpression<T>
- Type Parameters:
T- the return type
- All Implemented Interfaces:
Expression<T>, SyntaxElement
An expression that can only be used in select CodeSections. It is possible to make a RestrictedExpression "strict" ;
that is, it would be invalid to use it when not directly enclosed in one of its required sections.
It is possible to specify the error message that should be shown if the restrictions aren't followed.
This class shouldn't be used for expressions that should only work with specific
TriggerContexts.
For this purpose, use ParseContext.getParserState() in conjuction with ParserState.getCurrentContexts().- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract List<Class<? extends CodeSection>> Returns a list of the classes of all the sections inside of which this expression can be usedprotected abstract StringThe error message that should be displayed if this expression is used outside of one of its required sectionsbooleaninit(Expression<?>[] expressions, int matchedPattern, ParseContext parseContext) Initializes this SyntaxElement before being used.protected abstract booleaninitialize(Expression<?>[] expressions, CodeSection requiredSection, int matchedPattern, ParseContext parseContext) protected abstract booleanisStrict()True if the directly enclosing section must be a required one (a member ofgetRequiredSections()), false otherwise.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Expression
acceptsChange, acceptsChange, acceptsChange, change, check, check, convertExpression, getArray, getReturnType, getSingle, getSource, getValues, isAndList, isLoopOf, isSingle, iterator, setAndList, streamMethods inherited from interface SyntaxElement
toString
-
Constructor Details
-
RestrictedExpression
public RestrictedExpression()
-
-
Method Details
-
init
Description copied from interface:SyntaxElementInitializes this SyntaxElement before being used. This method is always called before all the others in an extending class, the only exception beingCodeSection.loadSection(FileSection, ParserState, SkriptLogger).- Specified by:
initin interfaceSyntaxElement- Parameters:
expressions- an array of expressions representing all the expressions that are being passed to this syntax element. As opposed to Skript, elements of this array can't benull.matchedPattern- the index of the pattern that was successfully matched. It corresponds to the order of the syntaxes in registrationparseContext- an object containing additional information about the parsing of this syntax element, like regex matches and parse marks- Returns:
trueif the syntax element was initialized successfully,falseotherwise.- See Also:
-
initialize
protected abstract boolean initialize(Expression<?>[] expressions, CodeSection requiredSection, int matchedPattern, ParseContext parseContext) -
getSpecificErrorMessage
The error message that should be displayed if this expression is used outside of one of its required sections- Returns:
- the error message that should be displayed if this expression is used outside of one of its required sections
-
getRequiredSections
Returns a list of the classes of all the sections inside of which this expression can be used- Returns:
- a list of the classes of all the sections inside of which this expression can be used
-
isStrict
protected abstract boolean isStrict()True if the directly enclosing section must be a required one (a member ofgetRequiredSections()), false otherwise.- Returns:
- whether the directly enclosing section must be a required one or not
-