Class ExpressionNode

java.lang.Object
jadex.javaparser.javaccimpl.SimpleNode
jadex.javaparser.javaccimpl.ExpressionNode
All Implemented Interfaces:
IParsedExpression, Node, Serializable
Direct Known Subclasses:
ArgumentsNode, ArrayNode, BooleanNode, CastNode, CollectionNode, CompareNode, ConditionalNode, ConstantNode, MathNode, ParameterNode, ReflectNode, SelectionNode, SelectNode, TypeNode

public abstract class ExpressionNode extends SimpleNode implements IParsedExpression
Base class of expression node hierarchy.
See Also:
  • Field Details

    • text

      protected String text
      The token text (if any).
    • expressiontext

      protected String expressiontext
      The expression text (if any).
    • imports

      protected String[] imports
      The imports (if any).
    • static_type

      protected Class static_type
      The static type (if any).
    • constant

      protected boolean constant
      Is the node value constant (independent of evaluation context and parameters)?
    • constant_value

      protected Object constant_value
      The constant value (if any).
  • Constructor Details

    • ExpressionNode

      public ExpressionNode(jadex.javaparser.javaccimpl.ParserImpl p, int id)
      Create an expression node.
      Parameters:
      p - The parser.
      id - The id.
  • Method Details

    • setExpressionText

      public void setExpressionText(String expressiontext)
      Get the full expression text.
      Parameters:
      text - The expression text.
    • getExpressionText

      public String getExpressionText()
      Get the full expression text.
      Specified by:
      getExpressionText in interface IParsedExpression
      Returns:
      The expression text.
    • setText

      public void setText(String text)
      Set the token text.
      Parameters:
      text - The token text.
    • appendText

      public void appendText(String text)
      Append to the token text.
      Parameters:
      text - The text to append.
    • setStaticType

      public void setStaticType(Class static_type)
      Set the static type.
      Parameters:
      static_type - The static type.
    • setConstantValue

      public void setConstantValue(Object constant_value)
      Set the constant value.
      Parameters:
      constant_value - The constant value.
    • getConstantValue

      public Object getConstantValue()
      Get the constant value. The constant value of a node may be known, when it is independent of the evaluation context, and the child nodes are constant, too.
      Returns:
      The constant value.
    • setConstant

      public void setConstant(boolean constant)
      Set if the node is constant.
      Parameters:
      constant - The constant.
    • isConstant

      public boolean isConstant()
      Get if the node is constant. The node is constant, when it is independent of the evaluation context, and the child nodes are constant, too.
      Returns:
      The constant flag.
    • toString

      public String toString(String prefix)
      Create a string representation of this node for dumping in a tree.
      Overrides:
      toString in class SimpleNode
      Returns:
      A string representation of this node.
    • toPlainString

      public String toPlainString()
      Create a string representation of this node for dumping in a tree.
      Specified by:
      toPlainString in interface Node
      Returns:
      A string representation of this node.
    • toString

      public String toString()
      Create a string representation of this node for dumping in a tree.
      Overrides:
      toString in class SimpleNode
      Returns:
      A string representation of this node.
    • subnodeToString

      protected String subnodeToString(int subnode)
      Create a string for a subnode. Automatically adds braces if necessary.
      Parameters:
      subnode - The index of the subnode.
      Returns:
      The string for the subnode.
    • getText

      public String getText()
      Get the expression text.
      Returns:
      The text.
    • getValue

      public abstract Object getValue(jadex.common.IValueFetcher fetcher)
      Evaluate the expression in the given state with respect to given parameters.
      Specified by:
      getValue in interface IParsedExpression
      Parameters:
      params - The parameters (string, value pairs), if any.
      Returns:
      The value of the term.
    • getStaticType

      public Class<?> getStaticType()
      Get the static type. If no information about the return type of an expression is available (e.g. because it depends on the evaluation context), the static type is null.
      Specified by:
      getStaticType in interface IParsedExpression
      Returns:
      The static type.
    • getParameters

      public Set<String> getParameters()
      Get the parameters used in the expression.
      Specified by:
      getParameters in interface IParsedExpression
    • getUnboundParameterNodes

      public ParameterNode[] getUnboundParameterNodes()
      Get unbound parameter nodes.
      Returns:
      The unbound parameter nodes.
    • precompile

      public void precompile()
      This method should be overridden to perform all possible checks and precompute all values (e.g. the static_type), which are independent of the evaluation context and parameters.
    • precompileTree

      public void precompileTree()
      Precompile this node and all subnodes.
    • throwParseException

      protected void throwParseException(Throwable ex) throws ParseException
      (Re)throw an exception that occured during parsing and add a useful error message.
      Parameters:
      ex - The exception to be rethrown (if any).
      Throws:
      ParseException
    • throwEvaluationException

      protected void throwEvaluationException(Throwable ex) throws RuntimeException
      (Re)throw an exception that occured during evaluation and add a useful error message.
      Parameters:
      ex - The exception to be rethrown (if any).
      Throws:
      RuntimeException
    • equals

      public boolean equals(Object o)
      Test if two nodes are equal.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Get the hash code for the node.
      Overrides:
      hashCode in class Object