Class AbstractProtelisAST<T>

    • Constructor Detail

      • AbstractProtelisAST

        protected AbstractProtelisAST​(Metadata metadata,
                                      ProtelisAST<?>... branch)
        Parameters:
        metadata - A Metadata object containing information about the code that generated this AST node.
        branch - the branches for this tree
      • AbstractProtelisAST

        protected AbstractProtelisAST​(Metadata metadata,
                                      java.util.List<ProtelisAST<?>> branch)
        Parameters:
        metadata - A Metadata object containing information about the code that generated this AST node.
        branch - the branches for this tree
    • Method Detail

      • branchesToString

        protected final java.lang.String branchesToString()
        Returns:
        a String representing the branches of this tree, in the format (b1, b2, ..., bn).
      • branchesToString

        protected final java.lang.String branchesToString​(java.lang.CharSequence separator,
                                                          java.lang.CharSequence prefix,
                                                          java.lang.CharSequence postfix)
        Returns a String representing the branches of this tree with the specified format.
        Parameters:
        separator - the separator CharSequence
        prefix - the prefix
        postfix - the postfix
        Returns:
        a String representing the branches of this tree with the specified format.
      • evaluate

        protected abstract T evaluate​(ExecutionContext context)
        Evaluates this AST node. This method can throw any exception, AbstractProtelisAST takes care of storing the necessary metadata.
        Parameters:
        context - the execution context
        Returns:
        the result of the evaluation
      • forEach

        protected final void forEach​(java.util.function.Consumer<? super ProtelisAST<?>> action)
        Facility to run lambdas across all the branches.
        Parameters:
        action - the Consumer to execute
      • isNullable

        protected boolean isNullable()
        Returns:
        true if this node can get annotated with null values - namely, if it is an interaction with Java
      • forEachWithIndex

        protected final void forEachWithIndex​(java.util.function.BiConsumer<java.lang.Integer,​? super ProtelisAST<?>> action)
        Facility to run lambdas across all the branches.
        Parameters:
        action - the Consumer to execute
      • getBranch

        public final ProtelisAST<?> getBranch​(int i)
        Specified by:
        getBranch in interface ProtelisAST<T>
        Parameters:
        i - the index
        Returns:
        the i-th branch of the evaluation tree
      • getBranches

        public final java.util.List<ProtelisAST<?>> getBranches()
        Specified by:
        getBranches in interface ProtelisAST<T>
        Returns:
        a view of the branches of the tree
      • getBranchesNumber

        protected final int getBranchesNumber()
        Returns:
        the number of branches
      • getMetadata

        public final Metadata getMetadata()
        Specified by:
        getMetadata in interface ProtelisAST<T>
        Returns:
        A Metadata object containing information about the code that generated this AST node.
      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface ProtelisAST<T>
        Returns:
        The name of the operation
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • stringFor

        protected static final java.lang.String stringFor​(ProtelisAST<?> tree)
        A String representation of an ProtelisAST. I
        Parameters:
        tree - the tree to stringify
        Returns:
        if the tree it is not erased (i.e., contains a value), returns a stringified version of such value. Otherwise, returns the branch name via getName()