Class ASTLocalVariableDeclaration
- java.lang.Object
-
- net.sourceforge.pmd.lang.ast.AbstractNode
-
- net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode<JavaNode>
-
- net.sourceforge.pmd.lang.java.ast.AbstractJavaNode
-
- net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessNode
-
- net.sourceforge.pmd.lang.java.ast.ASTLocalVariableDeclaration
-
- All Implemented Interfaces:
Iterable<ASTVariableDeclaratorId>
,Node
,AccessNode
,Annotatable
,CanSuppressWarnings
,Dimensionable
,JavaNode
,ScopedNode
public class ASTLocalVariableDeclaration extends AbstractJavaAccessNode implements Dimensionable, CanSuppressWarnings, Iterable<ASTVariableDeclaratorId>
Represents a local variable declaration. This is a block statement, but the node is also used in for-loop initialisers and foreach statements.This statement may define several variables, possibly of different types (see
ASTVariableDeclaratorId.getType()
). The nodes corresponding to the declared variables are accessible throughiterator()
.LocalVariableDeclaration ::= ( "final" | Annotation )* Type VariableDeclarator ( "," VariableDeclarator )*
-
-
Field Summary
-
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 ASTLocalVariableDeclaration(int id)
Deprecated.ASTLocalVariableDeclaration(JavaParser p, int id)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ASTAnnotation
getAnnotation(String annotQualifiedName)
Get specific annotaion on this node.int
getArrayDepth()
Deprecated.List<ASTAnnotation>
getDeclaredAnnotations()
Get all annotations present on this node.ASTType
getTypeNode()
Gets the type node for this variable declaration statement.String
getVariableName()
Deprecated.LocalVariableDeclaration may declare several variables, so this is not exhaustive Iterate on the VariableDeclaratorIds insteadboolean
hasSuppressWarningsAnnotationFor(Rule rule)
boolean
isAnnotationPresent(String annotQualifiedName)
Checks whether the annotation is present on this node.boolean
isAnyAnnotationPresent(Collection<String> annotQualifiedNames)
Checks whether any annotation is present on this node.boolean
isArray()
Deprecated.boolean
isTypeInferred()
If true, this local variable declaration represents a declaration, which makes use of local variable type inference, e.g.Iterator<ASTVariableDeclaratorId>
iterator()
Returns an iterator over the ids of the variables declared in this statement.Object
jjtAccept(JavaParserVisitor visitor, Object data)
Calls back the visitor's visit method corresponding to the runtime type of this Node.-
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 java.lang.Iterable
forEach, spliterator
-
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
-
ASTLocalVariableDeclaration
@InternalApi @Deprecated public ASTLocalVariableDeclaration(int id)
Deprecated.
-
ASTLocalVariableDeclaration
@InternalApi @Deprecated public ASTLocalVariableDeclaration(JavaParser p, int id)
Deprecated.
-
-
Method Detail
-
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
-
hasSuppressWarningsAnnotationFor
public boolean hasSuppressWarningsAnnotationFor(Rule rule)
- Specified by:
hasSuppressWarningsAnnotationFor
in interfaceCanSuppressWarnings
-
isTypeInferred
public boolean isTypeInferred()
If true, this local variable declaration represents a declaration, which makes use of local variable type inference, e.g. java10 "var". You can receive the inferred type viaAbstractJavaTypeNode.getType()
.- See Also:
ASTVariableDeclaratorId.isTypeInferred()
-
isArray
@Deprecated public boolean isArray()
Deprecated.- Specified by:
isArray
in interfaceDimensionable
-
getArrayDepth
@Deprecated public int getArrayDepth()
Deprecated.- Specified by:
getArrayDepth
in interfaceDimensionable
-
getTypeNode
public ASTType getTypeNode()
Gets the type node for this variable declaration statement. With Java10 and local variable type inference, there might be no type node at all.- Returns:
- The type node or
null
- See Also:
isTypeInferred()
-
getVariableName
@Deprecated @DeprecatedAttribute(replaceWith="VariableDeclaratorId/@Name") public String getVariableName()
Deprecated.LocalVariableDeclaration may declare several variables, so this is not exhaustive Iterate on the VariableDeclaratorIds insteadGets the variable name of this declaration. This method searches the first VariableDeclaratorId node and returns it's image ornull
if the child node is not found.- Returns:
- a String representing the name of the variable
-
iterator
public Iterator<ASTVariableDeclaratorId> iterator()
Returns an iterator over the ids of the variables declared in this statement.- Specified by:
iterator
in interfaceIterable<ASTVariableDeclaratorId>
-
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 annotQualifiedName)
Description copied from interface:Annotatable
Get specific annotaion on this node.- Specified by:
getAnnotation
in interfaceAnnotatable
- Parameters:
annotQualifiedName
- qulified name of the annotation.- Returns:
ASTAnnotaion
node if the annotation is present on this node, elsenull
-
isAnnotationPresent
public boolean isAnnotationPresent(String annotQualifiedName)
Description copied from interface:Annotatable
Checks whether the annotation is present on this node.- Specified by:
isAnnotationPresent
in interfaceAnnotatable
- Parameters:
annotQualifiedName
- qulified name of the annotation.- Returns:
true
if the annotation is present on this node, elsefalse
-
isAnyAnnotationPresent
public boolean isAnyAnnotationPresent(Collection<String> annotQualifiedNames)
Description copied from interface:Annotatable
Checks whether any annotation is present on this node.- Specified by:
isAnyAnnotationPresent
in interfaceAnnotatable
- Parameters:
annotQualifiedNames
- collection that cotains qulified name of annotations.- Returns:
true
if any annotation is present on this node, elsefalse
-
-