Class CodeSection

java.lang.Object
io.github.syst3ms.skriptparser.lang.Statement
io.github.syst3ms.skriptparser.lang.CodeSection
All Implemented Interfaces:
SyntaxElement
Direct Known Subclasses:
ArgumentSection, SecAsync, SecCase, SecChance, SecConditional, SecSwitch, SecWhile, SimpleCodeSection, Trigger

public abstract class CodeSection extends Statement
Represents a section of runnable code.
See Also:
  • Field Details

  • Constructor Details

    • CodeSection

      public CodeSection()
  • Method Details

    • loadSection

      public boolean loadSection(FileSection section, ParserState parserState, SkriptLogger logger)
      This methods determines the logic of what is being done to the elements inside of this section. By default, this simply parses all items inside it, but this can be overridden. In case an extending class just needs to do some additional operations on top of what the default implementation already does, then call super.loadSection(section) before any such operations.
      Parameters:
      section - the FileSection representing this CodeSection
      logger - the logger
      Returns:
      true if the items inside of the section were loaded properly, false if there was a problem
    • run

      @Contract("_ -> fail") public boolean run(TriggerContext ctx)
      Description copied from class: Statement
      Executes this Statement
      Specified by:
      run in class Statement
      Parameters:
      ctx - the event
    • walk

      public abstract Optional<? extends Statement> walk(TriggerContext ctx)
      Description copied from class: Statement
      By default, runs Statement.run(TriggerContext) ; returns Statement.getNext() if it returns true, or null otherwise. Note that if this method is overridden, then the implementation of Statement.run(TriggerContext) doesn't matter.
      Overrides:
      walk in class Statement
      Parameters:
      ctx - the event
      Returns:
      the next item to be ran, or null if this is the last item to be executed
    • setItems

      public final void setItems(List<Statement> items)
      Sets the items inside this lists, and also modifies other fields, reflected through the outputs of getFirst(), getLast() and Statement.getParent().
      Parameters:
      items - the items to set
    • getItems

      public List<Statement> getItems()
      The items returned by this method are not representative of the execution of the code, meaning that all items in the list may not be all executed. The list should rather be considered as a flat view of all the lines inside the section. Prefer Statement.runAll(Statement, TriggerContext) to run the contents of this section
      Returns:
      all items inside this section
    • getFirst

      public final Optional<? extends Statement> getFirst()
      Returns:
      the first item of this section, or the item after the section if it's empty, or null if there is no item after this section, in the latter case
    • getLast

      protected final Optional<? extends Statement> getLast()
      Returns:
      the last item of this section, or the item after the section if it's empty, or null if there is no item after this section, in the latter case
    • getAllowedSyntaxes

      protected Set<Class<? extends SyntaxElement>> getAllowedSyntaxes()
      A list of the classes of every syntax that is allowed to be used inside of this CodeSection. The default behavior is to return an empty list, which equates to no restrictions. If overridden, this allows the creation of specialized, DSL-like sections in which only select statements and other sections (and potentially, but not necessarily, expressions).
      Returns:
      a list of the classes of each syntax allowed inside this CodeSection
      See Also:
    • isRestrictingExpressions

      protected boolean isRestrictingExpressions()
      Whether the syntax restrictions outlined in getAllowedSyntaxes() should also apply to expressions. This is usually undesirable, so it is false by default. This should return true if and only if getAllowedSyntaxes() contains an Expression class.
      Returns:
      whether the use of expressions is also restricted by getAllowedSyntaxes(). False by default.
    • checkFinishing

      public boolean checkFinishing(Predicate<? super Statement> finishingTest, SkriptLogger logger, int currentSectionLine, boolean warnUnreachable, String errorMessage)
    • checkFinishing

      public boolean checkFinishing(Predicate<? super Statement> finishingTest, SkriptLogger logger, int currentSectionLine, boolean warnUnreachable)
    • checkReturns

      public boolean checkReturns(SkriptLogger logger, int currentSectionLine, boolean warnUnreachable)