Class MethodCall

All Implemented Interfaces:
Operation

public final class MethodCall extends CallableOperation
MethodCall is a Operation that represents a call to a method. It is a wrapper for a reflective Method object, and caches values of computed reflective calls.

An an Operation, a call to a non-static method
T mname (T1,...,Tn)
of class C can be represented formally as an operation
mname: [C, T1,...,Tn] → T.
If this method is static, then we could write the operation as
C.mname: [T1,...,Tn] → T
(a class instance not being needed as an input).

The execution of a MethodCall executes the enclosed Method given values for the inputs.

(Class previously called RMethod.)

  • Field Details

    • method

      private final Method method
    • isStatic

      private final boolean isStatic
  • Constructor Details

    • MethodCall

      public MethodCall(Method method)
      MethodCall creates an object corresponding to the given reflective method.
      Parameters:
      method - the reflective method object
  • Method Details

    • getMethod

      public Method getMethod()
      getMethod returns Method object of this MethodCall.
      Returns:
      Method object called by this MethodCall
    • toString

      public String toString()
      toString outputs a text representation of the method call.
      Overrides:
      toString in class Object
      Returns:
      string representation of the enclosed method
    • appendCode

      public void appendCode(Type declaringType, TypeTuple inputTypes, Type outputType, List<Variable> inputVars, StringBuilder sb)
      Produces a Java source code representation of this statement and appends it to the given StringBuilder.

      Issues the code that corresponds to calling the method with the provided Variable objects as arguments.

      Specified by:
      appendCode in class CallableOperation
      Parameters:
      inputVars - is the list of actual arguments to be printed
      declaringType - the declaring type for this operation
      inputTypes - the input types for this operation
      outputType - the output type for this operation
      sb - the StringBuilder to which code is added
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • execute

      public ExecutionOutcome execute(Object[] input)
      Performs this operation using the array of input values. Returns the results of execution as an ResultOrException object and can output results to specified PrintStream.
      Specified by:
      execute in class CallableOperation
      Parameters:
      input - array containing appropriate inputs to operation
      Returns:
      a NormalExecution with return value if execution was normal, otherwise a ExceptionalExecution if an exception was thrown
    • isStatic

      public boolean isStatic()
      Predicate to indicate whether object represents a static operation on the declaring class.
      Specified by:
      isStatic in interface Operation
      Overrides:
      isStatic in class CallableOperation
      Returns:
      true if this method is static, and false otherwise
    • toParsableString

      public String toParsableString(Type declaringType, TypeTuple inputTypes, Type outputType)
      Returns a string representation of this Operation, which can be read by static parse method for class. For a class C implementing the Operation interface, this method should return a String s such that parsing the string returns an object equivalent to this object, i.e. C.parse(this.s).equals(this).

      The descriptor for a method is a string representing the method signature.

      Examples: java.util.ArrayList.get(int) java.util.ArrayList.add(int,java.lang.Object)

      Specified by:
      toParsableString in class CallableOperation
      Parameters:
      declaringType - the declaring type for this operation
      inputTypes - the input types for this operation
      outputType - the output type for this operation
      Returns:
      a string representation of this operation
    • parse

      public static TypedClassOperation parse(String signature) throws OperationParseException
      Parses a method signature (not a representation of a call; there are no arguments, for example) and returns a MethodCall object. Should satisfy parse(op.toParsableString()).equals(op) for Operation op.
      Parameters:
      signature - a string descriptor
      Returns:
      the method call operation for the given string descriptor
      Throws:
      OperationParseException - if s does not match expected descriptor
      See Also:
    • isMessage

      public boolean isMessage()
      Predicate to indicate whether object represents a method-call-like operation (either static or instance). This includes field getters and setters, which are operations that access fields.
      Specified by:
      isMessage in interface Operation
      Overrides:
      isMessage in class CallableOperation
      Returns:
      true always, since this is a method call
    • isMethodCall

      public boolean isMethodCall()
      Indicates whether this object represents a method-call operation (either static or instance). This excludes getters and setters.
      Specified by:
      isMethodCall in interface Operation
      Overrides:
      isMethodCall in class CallableOperation
      Returns:
      true always, since this is a method call
    • getName

      public String getName()
      Description copied from interface: Operation
      Returns the name for the operation.
      Returns:
      the name for this operation
    • getReflectionObject

      public Method getReflectionObject()
      Overrides:
      getReflectionObject in class CallableOperation
    • satisfies

      public boolean satisfies(ReflectionPredicate reflectionPredicate)
      Checks whether reflective object contained in an Operation satisfies the predicate. Since there is no reflective object in an CallableOperation, returns false.

      Determines whether enclosed Method satisfies the given predicate.

      Specified by:
      satisfies in interface Operation
      Overrides:
      satisfies in class CallableOperation
      Parameters:
      reflectionPredicate - the ReflectionPredicate to be checked
      Returns:
      true only if the method in this object satisfies the canUse(Method) of predicate