Class ObjectCreationNode

All Implemented Interfaces:

public class ObjectCreationNode extends Node
A node for a new object creation.
   new typeToInstantiate(arg1, arg2, ...) typeToInstantiate(arg1, arg2, ...) <Ts>typeToInstantiate(arg1, arg2, ...)

We use the term "typeToInstantiate" to represent what is called the "identifier" in NewClassTree and what is called "ClassOrInterfaceTypeToInstantiate" in the "ClassInstanceCreationExpression" in the JLS. The former term "identifier" is misleading, as this can be a type with type arguments. The latter term "ClassOrInterfaceTypeToInstantiate" is rather long and we shortened it to "typeToInstantiate".

Class type arguments can be accessed through the "typeToInstantiate" node. To access constructor type arguments one needs to use the NewClassTree.

  • Field Details

    • tree

      protected final NewClassTree tree
      The tree for the object creation.
    • enclosingExpression

      protected final @Nullable Node enclosingExpression
      The enclosing expression of the object creation or null.
    • typeToInstantiate

      protected final Node typeToInstantiate
      The type to instantiate node of the object creation. A non-generic typeToInstantiate node will refer to a ClassNameNode, while a generic typeToInstantiate node will refer to a ParameterizedTypeNode.
    • arguments

      protected final List<Node> arguments
      The arguments of the object creation.
    • classbody

      protected final @Nullable ClassDeclarationNode classbody
      Class body for anonymous classes, otherwise null.
  • Constructor Details

    • ObjectCreationNode

      public ObjectCreationNode(NewClassTree tree, @Nullable Node enclosingExpr, Node typeToInstantiate, List<Node> arguments, @Nullable ClassDeclarationNode classbody)
      Constructs a ObjectCreationNode.
      tree - the NewClassTree
      enclosingExpr - the enclosing expression Node if it exists, or null
      typeToInstantiate - the typeToInstantiate node
      arguments - the passed arguments
      classbody - the ClassDeclarationNode
  • Method Details

    • getConstructor

      @Deprecated public Node getConstructor()
      Returns the constructor node.
      the constructor node
    • getTypeToInstantiate

      @Pure public Node getTypeToInstantiate()
      Returns the typeToInstantiate node. A non-generic typeToInstantiate node can refer to a ClassNameNode, while a generic typeToInstantiate node can refer to a ParameterizedTypeNode.
      the typeToInstantiate node
    • getArguments

      @Pure public List<Node> getArguments()
      Returns the explicit arguments to the object creation.
      the arguments
    • getArgument

      @Pure public Node getArgument(int i)
      Returns the i-th explicit argument to the object creation.
      i - the index of the argument
      the argument
    • getEnclosingExpression

      @Pure public @Nullable Node getEnclosingExpression()
      Returns the enclosing expression node, which only exists if it is an inner class instantiation.
      the enclosing type expression node
    • getClassBody

      @Pure public @Nullable Node getClassBody()
      Returns the classbody.
      the classbody
    • getTree

      @Pure public NewClassTree getTree()
      Description copied from class: Node
      Returns the Tree in the abstract syntax tree, or null if no corresponding tree exists. For instance, this is the case for an ImplicitThisNode.
      Specified by:
      getTree in class Node
      the corresponding Tree or null
    • accept

      public <R, P> R accept(NodeVisitor<R,P> visitor, P p)
      Description copied from class: Node
      Accept method of the visitor pattern.
      Specified by:
      accept in class Node
      Type Parameters:
      R - result type of the operation
      P - parameter type
      visitor - the visitor to be applied to this node
      p - the parameter for this operation
    • toString

      @SideEffectFree public String toString()
      toString in class Object
    • equals

      @Pure public boolean equals(@Nullable Object obj)
      equals in class Object
    • hashCode

      @SideEffectFree public int hashCode()
      hashCode in class Object
    • getOperands

      @SideEffectFree public Collection<Node> getOperands()
      Description copied from class: Node
      Returns a collection containing all of the operand Nodes of this Node.
      Specified by:
      getOperands in class Node
      a collection containing all of the operand Nodes of this Node