Class JInvocation

All Implemented Interfaces:
JExpression, JGenerable, JStatement

public final class JInvocation extends JExpressionImpl implements JStatement
JMethod invocation
  • Field Details

    • object

      private JGenerable object
      Object expression upon which this method will be invoked, or null if this is a constructor invocation
    • name

      private String name
      Name of the method to be invoked. Either this field is set, or method, or type (in which case it's a constructor invocation.) This allows the name of the method to be changed later.
    • method

      private JMethod method
    • isConstructor

      private boolean isConstructor
    • args

      private List<JExpression> args
      List of argument expressions for this method invocation
    • type

      private JType type
      If isConstructor==true, this field keeps the type to be created.
  • Constructor Details

    • JInvocation

      JInvocation(JExpression object, String name)
      Invokes a method on an object.
      Parameters:
      object - JExpression for the object upon which the named method will be invoked, or null if none
      name - Name of method to invoke
    • JInvocation

      JInvocation(JExpression object, JMethod method)
    • JInvocation

      JInvocation(JClass type, String name)
      Invokes a static method on a class.
    • JInvocation

      JInvocation(JClass type, JMethod method)
    • JInvocation

      private JInvocation(JGenerable object, String name)
    • JInvocation

      private JInvocation(JGenerable object, JMethod method)
    • JInvocation

      JInvocation(JType c)
      Invokes a constructor of an object (i.e., creates a new object.)
      Parameters:
      c - Type of the object to be created. If this type is an array type, added arguments are treated as array initializer. Thus you can create an expression like new int[]{1,2,3,4,5}.
  • Method Details

    • arg

      public JInvocation arg(JExpression arg)
      Add an expression to this invocation's argument list
      Parameters:
      arg - Argument to add to argument list
    • arg

      public JInvocation arg(String v)
      Adds a literal argument. Short for arg(JExpr.lit(v))
    • listArgs

      public JExpression[] listArgs()
      Returns all arguments of the invocation.
      Returns:
      If there's no arguments, an empty array will be returned.
    • generate

      public void generate(JFormatter f)
      Specified by:
      generate in interface JGenerable
    • state

      public void state(JFormatter f)
      Specified by:
      state in interface JStatement