Class ReflectNode

All Implemented Interfaces:
IParsedExpression, Node, Serializable

public class ReflectNode extends ExpressionNode
A node for a constructor or method invocation or field access.
See Also:
  • Field Details

    • CONSTRUCTOR

      public static final int CONSTRUCTOR
      The constructor type.
      See Also:
    • STATIC_METHOD

      public static final int STATIC_METHOD
      The static method type.
      See Also:
    • STATIC_FIELD

      public static final int STATIC_FIELD
      The static field type.
      See Also:
    • METHOD

      public static final int METHOD
      The method type.
      See Also:
    • FIELD

      public static final int FIELD
      The field type.
      See Also:
    • type

      protected int type
      The reflect node type.
    • clazz

      protected Class clazz
      The clazz.
    • argtypes

      protected transient Class[] argtypes
      The argument types (for constructors and methods).
    • args

      protected transient Object[] args
      The argument values (for constructors and methods).
    • constructors

      protected transient Constructor[] constructors
      The possible constructors (for constructor nodes).
    • reloadedclass

      protected transient Class reloadedclass
      The dynamically reloaded class (currently only for constructor nodes).
    • methods

      protected transient Method[] methods
      The possible methods (for static and nonstatic methods).
    • accessor

      protected transient Method accessor
      The field accessor method (for static and nonstatic fields).
    • field

      protected transient Field field
      The field (for static and nonstatic fields).
    • reloadable

      protected boolean reloadable
      Flag indicating that this node is a candidate dynamic class reloading (currently only supported for plan constructors).
  • Constructor Details

    • ReflectNode

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

    • setType

      public void setType(int type)
      Set the constructor type.
      Parameters:
      type - The constrcutor type.
    • getType

      public int getType()
      Get the constructor type.
      Returns:
      The constructor type.
    • precompile

      public void precompile()
      Precompute the set of matching constructors if possible.
      Overrides:
      precompile in class ExpressionNode
    • getValue

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

      public String toPlainString()
      Create a string representation of this node and its subnodes.
      Specified by:
      toPlainString in interface Node
      Overrides:
      toPlainString in class ExpressionNode
      Returns:
      A string representation of this node.
    • findConstructors

      protected Constructor[] findConstructors(Class clazz, Class[] argtypes)
      Find all matching constructors of a given class.
      Parameters:
      clazz - The class.
      argtypes - The argument types.
      Returns:
      The matched constructors.
    • findMethods

      protected Method[] findMethods(Class clazz, Class[] argtypes)
      Find all matching methods of a given class.
      Parameters:
      clazz - The class.
      argtypes - The argument types.
      Returns:
      The matched methods.
    • invokeConstructor

      protected Object invokeConstructor(Class clazz, Class[] argtypes, Object[] args) throws Exception
      Find and invoke a constructor.
      Parameters:
      clazz - The class to instantiate.
      argtypes - The actual argument types.
      args - The actual argument values.
      Returns:
      The instantiated object.
      Throws:
      Exception
    • invokeMethod

      protected Object invokeMethod(Object ref, Class clazz, Class[] argtypes, Object[] args) throws Exception
      Find and invoke a method.
      Parameters:
      ref - The object on which to invoke (may be null for static methods).
      clazz - The class to instantiate.
      argtypes - The actual argument types.
      args - The actual argument values.
      Returns:
      The return value.
      Throws:
      Exception
    • accessField

      protected Object accessField(Object ref, Class clazz, jadex.common.IValueFetcher fetcher) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException
      Access a field.
      Throws:
      IllegalAccessException
      IllegalArgumentException
      NoSuchFieldException
    • getMethodForMethod

      protected Method getMethodForMethod(Method method)
      Find method declared in public class for a given method.
    • equals

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

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