Adds a preinit() method to SyntaxElement #7778
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I first ran into this issue with runtime errors, where I wanted code to run in init for all expressions. This was not possible for any class but SimplePropertyExpression, as it was the only one that used a separate init method for children and therefore could run code for all children.
This adds a preinit() method to SyntaxElement that is called just before init() and is intended to allow any syntax element the chance to do checks or work that should be consistent across children, without needing to change the signature of init() for the children or force all implementations to call super.init().
I also took the opportunity to separate ERS and ExprimentalSyntax's logic in SkriptParser into helper methods for clarity.
This PR includes changes to runtime errors to showcase the utility of preinit. It's not ideal, as I'd like to get the node in Expression, but state isn't allowed in interfaces so SimpleExpression it is.
I welcome feedback about whether this is necessary or if there are better ways to implement this kind of feature.
Target Minecraft Versions: any
Requirements: none
Related Issues: none