Interface ModifierOwner

All Superinterfaces:
Annotatable, net.sourceforge.pmd.lang.ast.impl.GenericNode<JavaNode>, JavaNode, net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeNode<JavaNode>, net.sourceforge.pmd.lang.ast.Node, net.sourceforge.pmd.reporting.Reportable, net.sourceforge.pmd.lang.ast.TextAvailableNode
All Known Subinterfaces:
ASTExecutableDeclaration, ASTTypeDeclaration
All Known Implementing Classes:
ASTAnnotationTypeDeclaration, ASTAnonymousClassDeclaration, ASTCatchParameter, ASTClassDeclaration, ASTCompactConstructorDeclaration, ASTConstructorDeclaration, ASTEnumConstant, ASTEnumDeclaration, ASTFieldDeclaration, ASTFormalParameter, ASTImplicitClassDeclaration, ASTLambdaParameter, ASTLocalVariableDeclaration, ASTMethodDeclaration, ASTRecordComponent, ASTRecordDeclaration, ASTTypePattern, ASTVariableId

public interface ModifierOwner extends Annotatable
A node that owns a modifier list.

ModifierOwner methods take into account the syntactic context of the declaration, e.g. hasModifiers(JModifier.PUBLIC) will always return true for a field declared inside an interface, regardless of whether the public modifier was specified explicitly or not. If you want to know whether the modifier was explicitly stated, use hasExplicitModifiers(JModifier, JModifier...).

Modifiers are accessible from XPath through the functions pmd:modifiers() and pmd:explicitModifiers(). They return a sequence, e.g. ("public", "static", "final").

Note: This interface was called AccessNode in PMD 6.

See Also:
  • GetModifiersFun
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    Represents the visibility of a declaration.
  • Field Summary

    Fields inherited from interface net.sourceforge.pmd.lang.ast.Node

    COORDS_COMPARATOR
  • Method Summary

    Modifier and Type
    Method
    Description
    default net.sourceforge.pmd.lang.ast.NodeStream<ASTAnnotation>
    Returns all annotations present on this node.
    Returns the "effective" visibility of a member.
    default @NonNull ASTModifierList
    Returns the node representing the modifier list of this node.
    Returns the visibility corresponding to the effective modifiers.
    default boolean
    Returns true if this node has all the given modifiers explicitly written in the source.
    default boolean
    Returns true if this node has all the given modifiers either explicitly written or inferred through context.
    default boolean
    Returns true if this node has the given visibility either explicitly written or inferred through context.

    Methods inherited from interface net.sourceforge.pmd.lang.java.ast.Annotatable

    getAnnotation, isAnnotationPresent, isAnnotationPresent, isAnyAnnotationPresent

    Methods inherited from interface net.sourceforge.pmd.lang.ast.impl.GenericNode

    ancestors, ancestorsOrSelf, asStream, children, descendants, descendantsOrSelf, getChild, getFirstChild, getLastChild, getNextSibling, getParent, getPreviousSibling

    Methods inherited from interface net.sourceforge.pmd.lang.java.ast.JavaNode

    getEnclosingType, getRoot, getSymbolTable, getTypeSystem

    Methods inherited from interface net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeNode

    getFirstToken, getLastToken, tokens

    Methods inherited from interface net.sourceforge.pmd.lang.ast.Node

    acceptVisitor, ancestors, children, compareLocation, descendants, firstChild, getAstInfo, getBeginColumn, getBeginLine, getEndColumn, getEndLine, getImage, getIndexInParent, getLanguageVersion, getNumChildren, getReportLocation, getTextDocument, getUserMap, getXPathAttributesIterator, getXPathNodeName, hasImageEqualTo, isFindBoundary

    Methods inherited from interface net.sourceforge.pmd.lang.ast.TextAvailableNode

    getOriginalText, getText, getTextRegion
  • Method Details

    • getDeclaredAnnotations

      default net.sourceforge.pmd.lang.ast.NodeStream<ASTAnnotation> getDeclaredAnnotations()
      Description copied from interface: Annotatable
      Returns all annotations present on this node.
      Specified by:
      getDeclaredAnnotations in interface Annotatable
    • getModifiers

      default @NonNull ASTModifierList getModifiers()
      Returns the node representing the modifier list of this node.
    • getVisibility

      default ModifierOwner.Visibility getVisibility()
      Returns the visibility corresponding to the effective modifiers. Eg a public method will have visibility public, a local class will have visibility local. There cannot be any conflict with hasModifiers(JModifier, JModifier...)} on well-formed code (e.g. for any n, (n.getVisibility() == V_PROTECTED) == n.hasModifiers(PROTECTED))

      TODO a public method of a private class can be considered to be private we could probably add another method later on that takes this into account

    • getEffectiveVisibility

      default ModifierOwner.Visibility getEffectiveVisibility()
      Returns the "effective" visibility of a member. This is the minimum visibility of its enclosing type declarations. For example, a public method of a private class is "effectively private".

      Local declarations keep local visibility, eg a local variable somewhere in an anonymous class doesn't get anonymous visibility.

    • hasModifiers

      default boolean hasModifiers(JModifier mod1, JModifier... mod)
      Returns true if this node has all the given modifiers either explicitly written or inferred through context.
    • hasExplicitModifiers

      default boolean hasExplicitModifiers(JModifier mod1, JModifier... mod)
      Returns true if this node has all the given modifiers explicitly written in the source.
    • hasVisibility

      default boolean hasVisibility(ModifierOwner.Visibility visibility)
      Returns true if this node has the given visibility either explicitly written or inferred through context.
      See Also: