Class ASTReceiverParameter

  • All Implemented Interfaces:
    GenericNode<JavaNode>, JjtreeNode<JavaNode>, Node, TextAvailableNode, JavaNode, Reportable

    public final class ASTReceiverParameter
    extends AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,​JavaNode>
    Receiver parameter. A receiver parameter is syntactically part of a formal parameter list, though it does not declare a variable or affect the arity of the method in any way. Its only purpose is to annotate the type of the object on which the method call is issued. It was introduced with Java 8.

    For example:

     class Foo {
       abstract void foo(@Bar Foo this);
     }
     

    Receiver parameters are only allowed on two types of declarations:

    • Instance method declarations of a class or interface (not annotation) type
    • Constructor declaration of a non-static inner class. It then has the type of the enclosing instance.
    In both cases it must be the first parameter of the formal parameter list, and is entirely optional.
    
     ReceiverParameter ::= ClassType (<IDENTIFIER> ".")? "this"
    
     
    • Method Detail

      • acceptVisitor

        protected <P,​R> R acceptVisitor​(JavaVisitor<? super P,​? extends R> visitor,
                                              P data)
      • getReceiverType

        public @NonNull ASTClassType getReceiverType()
        Returns the type of the receiver parameter (eg Foo in Foo this. In an instance method, that type must be the class or interface in which the method is declared, and the name of the receiver parameter must be this.

        In an inner class's constructor, the type of the receiver parameter must be the class or interface which is the immediately enclosing type declaration of the inner class, call it C, and the name of the parameter must be Identifier.this where Identifier is the simple name of C.

      • acceptVisitor

        public final <P,​R> R acceptVisitor​(AstVisitor<? super P,​? extends R> visitor,
                                                 P data)
        Specified by:
        acceptVisitor in interface Node
      • addChild

        protected void addChild​(net.sourceforge.pmd.lang.java.ast.AbstractJavaNode child,
                                int index)
        Overrides:
        addChild in class AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,​JavaNode>
      • insertChild

        protected void insertChild​(net.sourceforge.pmd.lang.java.ast.AbstractJavaNode child,
                                   int index)
        Overrides:
        insertChild in class AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,​JavaNode>
      • removeChildAtIndex

        protected void removeChildAtIndex​(int childIndex)
        Overrides:
        removeChildAtIndex in class AbstractNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,​JavaNode>
      • setChild

        protected void setChild​(net.sourceforge.pmd.lang.java.ast.AbstractJavaNode child,
                                int index)
        Overrides:
        setChild in class AbstractNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,​JavaNode>
      • getSymbolTable

        public @NonNull JSymbolTable getSymbolTable()
        Description copied from interface: JavaNode
        Returns the symbol table for the program point represented by this node.
        Specified by:
        getSymbolTable in interface JavaNode
      • getTypeSystem

        public TypeSystem getTypeSystem()
        Description copied from interface: JavaNode
        Returns the type system with which this node was created. This is the object responsible for representing types in the compilation unit.
        Specified by:
        getTypeSystem in interface JavaNode