Class ASTMethodDeclaration

java.lang.Object
net.sourceforge.pmd.lang.ast.impl.AbstractNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration
All Implemented Interfaces:
net.sourceforge.pmd.lang.ast.impl.GenericNode<JavaNode>, net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeNode<JavaNode>, net.sourceforge.pmd.lang.ast.Node, net.sourceforge.pmd.lang.ast.TextAvailableNode, Annotatable, ASTBodyDeclaration, ASTExecutableDeclaration, JavadocCommentOwner, JavaNode, ModifierOwner, ReturnScopeNode, SymbolDeclaratorNode, TypeParamOwnerNode, net.sourceforge.pmd.reporting.Reportable

public final class ASTMethodDeclaration extends net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
A method declaration, in a class or interface declaration. Since 7.0, this also represents annotation methods. Annotation methods have a much more restricted grammar though, in particular: They can however declare a default value.

 MethodDeclaration ::= ModifierList
                       TypeParameters?
                       Type
                       <IDENTIFIER>
                       FormalParameters
                       ArrayDimensions?
                       ThrowsList?
                       (Block | ";" )

 
  • Field Details

  • Method Details

    • acceptVisitor

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

      public boolean isOverridden()
      Returns true if this method is overridden.
    • getOverriddenMethod

      public JMethodSig getOverriddenMethod()
      Returns the signature of the method this method overrides in a supertype. Note that this method may be implementing several methods of super-interfaces at once, in that case, an arbitrary one is returned.

      If the method has an Override annotation, but we couldn't resolve any method that is actually implemented, this will return TypeSystem.UNRESOLVED_METHOD.

    • getAccessedRecordComponent

      public @Nullable ASTRecordComponent getAccessedRecordComponent()
      If this method declaration is an explicit record component accessor, returns the corresponding record component. Otherwise returns null.
    • isVoid

      public boolean isVoid()
      Returns true if the result type of this method is void.
    • getDefaultClause

      public @Nullable ASTDefaultValue getDefaultClause()
      Returns the default clause, if this is an annotation method declaration that features one. Otherwise returns null.
    • getResultTypeNode

      public @NonNull ASTType getResultTypeNode()
      Returns the result type node of the method. This may be a ASTVoidType.
    • getExtraDimensions

      public @Nullable ASTArrayDimensions getExtraDimensions()
      Returns the extra array dimensions that may be after the formal parameters.
    • isMainMethod

      public boolean isMainMethod()
      Returns whether this is a main method declaration.
    • getImage

      public String getImage()
      Specified by:
      getImage in interface net.sourceforge.pmd.lang.ast.Node
      Overrides:
      getImage in class net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • getSymbol

      public JMethodSymbol getSymbol()
      Description copied from interface: SymbolDeclaratorNode
      Returns the symbol this node declares.
      Specified by:
      getSymbol in interface ASTExecutableDeclaration
      Specified by:
      getSymbol in interface SymbolDeclaratorNode
      Specified by:
      getSymbol in interface TypeParamOwnerNode
    • getGenericSignature

      public JMethodSig getGenericSignature()
      Description copied from interface: ASTExecutableDeclaration
      Returns the generic signature for the method. This is a JMethodSig declared in the generic type declaration of the enclosing type. The signature may mention type parameters of the enclosing types, and its own type parameters.
      Specified by:
      getGenericSignature in interface ASTExecutableDeclaration
    • getReportLocation

      public net.sourceforge.pmd.lang.document.FileLocation getReportLocation()
      Specified by:
      getReportLocation in interface net.sourceforge.pmd.lang.ast.Node
      Specified by:
      getReportLocation in interface net.sourceforge.pmd.reporting.Reportable
    • getName

      public String getName()
      Description copied from interface: ASTExecutableDeclaration
      Returns the name of the method, or the simple name of the declaring class for a constructor declaration.
      Specified by:
      getName in interface ASTExecutableDeclaration
    • jjtClose

      public void jjtClose()
      Overrides:
      jjtClose in class net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • acceptVisitor

      public final <P, R> R acceptVisitor(net.sourceforge.pmd.lang.ast.AstVisitor<? super P,? extends R> visitor, P data)
      Specified by:
      acceptVisitor in interface net.sourceforge.pmd.lang.ast.Node
    • addChild

      protected void addChild(net.sourceforge.pmd.lang.java.ast.AbstractJavaNode child, int index)
      Overrides:
      addChild in class net.sourceforge.pmd.lang.ast.impl.javacc.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 net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • removeChildAtIndex

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

      protected void setImage(String image)
      Overrides:
      setImage in class net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • setFirstToken

      protected void setFirstToken(net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken token)
      Overrides:
      setFirstToken in class net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • setLastToken

      protected void setLastToken(net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken token)
      Overrides:
      setLastToken in class net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • enlargeLeft

      protected void enlargeLeft(net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken child)
      Overrides:
      enlargeLeft in class net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode<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 net.sourceforge.pmd.lang.ast.impl.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
    • getRoot

      public final @NonNull ASTCompilationUnit getRoot()
      Specified by:
      getRoot in interface JavaNode
      Specified by:
      getRoot in interface net.sourceforge.pmd.lang.ast.Node
    • getXPathNodeName

      public final String getXPathNodeName()
      Specified by:
      getXPathNodeName in interface net.sourceforge.pmd.lang.ast.Node