Class ASTFormalParameter
-
- All Implemented Interfaces:
Node
,AccessNode
,Annotatable
,CanSuppressWarnings
,Dimensionable
,JavaNode
,TypeNode
,ScopedNode
- Direct Known Subclasses:
ASTResource
public class ASTFormalParameter extends AbstractJavaAccessTypeNode implements Dimensionable, CanSuppressWarnings
Formal parameter node. Used in theASTFormalParameters
production ofASTMethodDeclarator
to represent a method's formal parameter. Also used in theASTCatchStatement
production to represent the declared exception variable. Also used in LambdaExpressions for the LambdaParameters.( "final" | Annotation )* Type ( "|" Type )* [ "..." ] VariableDeclaratorId
-
-
Field Summary
-
Fields inherited from class net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessTypeNode
typeDefinition
-
Fields inherited from class net.sourceforge.pmd.lang.java.ast.AbstractJavaNode
parser
-
Fields inherited from class net.sourceforge.pmd.lang.ast.AbstractNode
beginColumn, beginLine, childIndex, children, endColumn, endLine, firstToken, id, lastToken, parent
-
Fields inherited from interface net.sourceforge.pmd.lang.java.ast.AccessNode
ABSTRACT, DEFAULT, FINAL, NATIVE, NON_SEALED, PRIVATE, PROTECTED, PUBLIC, SEALED, STATIC, STRICTFP, SYNCHRONIZED, TRANSIENT, VOLATILE
-
-
Constructor Summary
Constructors Constructor Description ASTFormalParameter(int id)
Deprecated.ASTFormalParameter(JavaParser p, int id)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ASTAnnotation
getAnnotation(String binaryName)
Returns a specific annotation on this node, or null if absent.int
getArrayDepth()
Deprecated.protected ASTVariableDeclaratorId
getDecl()
Deprecated.List<ASTAnnotation>
getDeclaredAnnotations()
Get all annotations present on this node.Class<?>
getType()
Returns the type of this formal parameter.JavaTypeDefinition
getTypeDefinition()
Get the TypeDefinition associated with this node.ASTType
getTypeNode()
Returns the type node of this formal parameter.ASTVariableDeclaratorId
getVariableDeclaratorId()
Returns the declarator ID of this formal parameter.boolean
hasSuppressWarningsAnnotationFor(Rule rule)
boolean
isAnnotationPresent(String binaryName)
Checks whether the annotation is present on this node.boolean
isAnyAnnotationPresent(Collection<String> binaryNames)
Checks whether any annotation is present on this node.boolean
isArray()
Deprecated.boolean
isExplicitReceiverParameter()
Returns true if this node is the explicit receiver parameter, e.g.boolean
isTypeInferred()
If true, this formal parameter represents one without explicit types.boolean
isVarargs()
Returns true if this node is a varargs parameter.Object
jjtAccept(JavaParserVisitor visitor, Object data)
Calls back the visitor's visit method corresponding to the runtime type of this Node.void
setType(Class<?> type)
Deprecated.void
setTypeDefinition(JavaTypeDefinition type)
Deprecated.void
setVarargs()
Deprecated.Will be made private in 7.0.0-
Methods inherited from class net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessNode
getModifiers, isAbstract, isDefault, isFinal, isNative, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic, isStrictfp, isSynchronized, isTransient, isVolatile, setAbstract, setDefault, setFinal, setModifiers, setNative, setPrivate, setProtected, setPublic, setStatic, setStrictfp, setSynchronized, setTransient, setVolatile
-
Methods inherited from class net.sourceforge.pmd.lang.java.ast.AbstractJavaNode
childrenAccept, comment, comment, getRoot, getScope, getXPathNodeName, jjtClose, jjtOpen, setScope
-
Methods inherited from class net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode
children, getChild, getParent
-
Methods inherited from class net.sourceforge.pmd.lang.ast.AbstractNode
appendElement, findChildNodesWithXPath, findChildrenOfType, findDescendantsOfType, findDescendantsOfType, findDescendantsOfType, getAsDocument, getBeginColumn, getBeginLine, getDataFlowNode, getEndColumn, getEndLine, getFirstChildOfType, getFirstDescendantOfType, getFirstParentOfAnyType, getFirstParentOfType, getImage, getIndexInParent, getNthParent, getNumChildren, getParentsOfType, getUserData, getUserMap, getXPathAttributesIterator, hasDecendantOfAnyType, hasDescendantMatchingXPath, hasDescendantOfAnyType, hasDescendantOfType, hasImageEqualTo, isFindBoundary, isSingleLine, jjtAddChild, jjtGetChild, jjtGetChildIndex, jjtGetFirstToken, jjtGetId, jjtGetLastToken, jjtGetNumChildren, jjtGetParent, jjtSetChildIndex, jjtSetFirstToken, jjtSetLastToken, jjtSetParent, remove, removeChildAtIndex, setDataFlowNode, setImage, setUserData, testingOnlySetBeginColumn, testingOnlySetBeginLine, testingOnlySetEndColumn, testingOnlySetEndLine, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sourceforge.pmd.lang.java.ast.JavaNode
children, childrenAccept, getChild, getParent, getRoot, setScope
-
Methods inherited from interface net.sourceforge.pmd.lang.ast.Node
findChildNodesWithXPath, findChildrenOfType, findDescendantsOfType, findDescendantsOfType, findDescendantsOfType, getAsDocument, getBeginColumn, getBeginLine, getDataFlowNode, getEndColumn, getEndLine, getFirstChildOfType, getFirstDescendantOfType, getFirstParentOfAnyType, getFirstParentOfType, getImage, getIndexInParent, getNthParent, getNumChildren, getParentsOfType, getUserData, getUserMap, getXPathAttributesIterator, getXPathNodeName, hasDescendantMatchingXPath, hasDescendantOfType, hasImageEqualTo, isFindBoundary, jjtAddChild, jjtClose, jjtGetChild, jjtGetChildIndex, jjtGetId, jjtGetNumChildren, jjtGetParent, jjtOpen, jjtSetChildIndex, jjtSetParent, remove, removeChildAtIndex, setDataFlowNode, setImage, setUserData
-
Methods inherited from interface net.sourceforge.pmd.lang.symboltable.ScopedNode
getScope
-
-
-
-
Constructor Detail
-
ASTFormalParameter
@InternalApi @Deprecated public ASTFormalParameter(int id)
Deprecated.
-
ASTFormalParameter
@InternalApi @Deprecated public ASTFormalParameter(JavaParser p, int id)
Deprecated.
-
-
Method Detail
-
setVarargs
@InternalApi @Deprecated public void setVarargs()
Deprecated.Will be made private in 7.0.0
-
isVarargs
public boolean isVarargs()
Returns true if this node is a varargs parameter.
-
isExplicitReceiverParameter
public boolean isExplicitReceiverParameter()
Returns true if this node is the explicit receiver parameter, e.g. inclass Foo { abstract void foo(@Bar Foo this); }
-
isTypeInferred
public boolean isTypeInferred()
If true, this formal parameter represents one without explicit types. This can appear as part of a lambda expression with java11 using "var".- See Also:
ASTVariableDeclaratorId.isTypeInferred()
-
jjtAccept
public Object jjtAccept(JavaParserVisitor visitor, Object data)
Description copied from interface:JavaNode
Calls back the visitor's visit method corresponding to the runtime type of this Node.- Specified by:
jjtAccept
in interfaceJavaNode
- Overrides:
jjtAccept
in classAbstractJavaNode
- Parameters:
visitor
- Visitor to dispatchdata
- Visit data
-
getVariableDeclaratorId
public ASTVariableDeclaratorId getVariableDeclaratorId()
Returns the declarator ID of this formal parameter.
-
hasSuppressWarningsAnnotationFor
public boolean hasSuppressWarningsAnnotationFor(Rule rule)
- Specified by:
hasSuppressWarningsAnnotationFor
in interfaceCanSuppressWarnings
-
isArray
@Deprecated public boolean isArray()
Deprecated.Returns true if this formal parameter is of an array type. This includes varargs parameters.- Specified by:
isArray
in interfaceDimensionable
-
getArrayDepth
@Deprecated public int getArrayDepth()
Deprecated.- Specified by:
getArrayDepth
in interfaceDimensionable
-
getTypeNode
public ASTType getTypeNode()
Returns the type node of this formal parameter. The type of that node is not necessarily the type of the parameter itself, seeASTVariableDeclaratorId.getType()
.In particular, the type of the returned node doesn't take into account whether this formal parameter is varargs or not.
-
getDecl
@Deprecated protected ASTVariableDeclaratorId getDecl()
Deprecated.
-
getType
public Class<?> getType()
Returns the type of this formal parameter. That type is exactly that of the variable declarator id, which means that the declarator id's type takes into account whether this parameter is varargs or not.- Specified by:
getType
in interfaceTypeNode
- Overrides:
getType
in classAbstractJavaAccessTypeNode
- Returns:
- The Java Class, may return
null
.
-
getTypeDefinition
public JavaTypeDefinition getTypeDefinition()
Description copied from interface:TypeNode
Get the TypeDefinition associated with this node. The Class object contained in the TypeDefinition will always be equal to that which is returned bygetType()
.- Specified by:
getTypeDefinition
in interfaceTypeNode
- Overrides:
getTypeDefinition
in classAbstractJavaAccessTypeNode
- Returns:
- The TypeDefinition, may return
null
-
setTypeDefinition
@InternalApi @Deprecated public void setTypeDefinition(JavaTypeDefinition type)
Deprecated.Noop, the type of this node is defined by the type of the declarator id.- Specified by:
setTypeDefinition
in interfaceTypeNode
- Overrides:
setTypeDefinition
in classAbstractJavaAccessTypeNode
- Parameters:
type
- A TypeDefinition object
-
setType
@InternalApi @Deprecated public void setType(Class<?> type)
Deprecated.Noop, the type of this node is defined by the type of the declarator id.- Specified by:
setType
in interfaceTypeNode
- Overrides:
setType
in classAbstractJavaAccessTypeNode
- Parameters:
type
- A Java Class
-
getDeclaredAnnotations
public List<ASTAnnotation> getDeclaredAnnotations()
Description copied from interface:Annotatable
Get all annotations present on this node.- Specified by:
getDeclaredAnnotations
in interfaceAnnotatable
- Returns:
- all annotations present on this node.
-
getAnnotation
public ASTAnnotation getAnnotation(String binaryName)
Description copied from interface:Annotatable
Returns a specific annotation on this node, or null if absent.- Specified by:
getAnnotation
in interfaceAnnotatable
- Parameters:
binaryName
- Binary name of the annotation type. Note: for now, canonical names are tolerated, this may be changed in PMD 7.
-
isAnnotationPresent
public boolean isAnnotationPresent(String binaryName)
Description copied from interface:Annotatable
Checks whether the annotation is present on this node.- Specified by:
isAnnotationPresent
in interfaceAnnotatable
- Parameters:
binaryName
- Binary name of the annotation type. Note: for now, canonical names are tolerated, this may be changed in PMD 7.- Returns:
true
if the annotation is present on this node, elsefalse
-
isAnyAnnotationPresent
public boolean isAnyAnnotationPresent(Collection<String> binaryNames)
Description copied from interface:Annotatable
Checks whether any annotation is present on this node.- Specified by:
isAnyAnnotationPresent
in interfaceAnnotatable
- Parameters:
binaryNames
- Collection that contains binary names of annotations. Note: for now, canonical names are tolerated, this may be changed in PMD 7.- Returns:
true
if any annotation is present on this node, elsefalse
-
-