net.sourceforge.pmd.lang.ast.Node
, Dimensionable
, JavaNode
, TypeNode
, net.sourceforge.pmd.lang.symboltable.ScopedNode
public class ASTVariableDeclaratorId extends AbstractJavaTypeNode implements Dimensionable
Since this node conventionally represents the declared variable in PMD, our symbol table
populates it with a VariableNameDeclaration
, and its usages can be accessed through
the method getUsages()
.
Type resolution assigns the type of the variable to this node. See getType()
's
documentation for the contract of this method.
parser
Constructor | Description |
---|---|
ASTVariableDeclaratorId(int id) |
|
ASTVariableDeclaratorId(JavaParser p,
int id) |
Modifier and Type | Method | Description |
---|---|---|
void |
bumpArrayDepth() |
|
int |
getArrayDepth() |
|
VariableNameDeclaration |
getNameDeclaration() |
|
java.lang.Class<?> |
getType() |
Returns the type of the declared variable.
|
net.sourceforge.pmd.lang.ast.Node |
getTypeNameNode() |
Returns the first child of the node returned by
getTypeNode() . |
ASTType |
getTypeNode() |
Determines the type node of this variable id, that is, the type node
belonging to the variable declaration of this node (either a
FormalParameter, LocalVariableDeclaration or FieldDeclaration).
|
java.util.List<net.sourceforge.pmd.lang.symboltable.NameOccurrence> |
getUsages() |
|
boolean |
isArray() |
|
boolean |
isExceptionBlockParameter() |
Returns true if this nodes declares an exception parameter in
a
catch statement. |
boolean |
isExplicitReceiverParameter() |
Returns true if this node is a receiver parameter for a method or constructor
declaration.
|
boolean |
isFormalParameter() |
Returns true if this node declares a formal parameter for a method
declaration or a lambda expression.
|
boolean |
isResourceDeclaration() |
Returns true if this declarator id declares a resource in a try-with-resources statement.
|
boolean |
isTypeInferred() |
Returns true if the declared variable's type is inferred by
the compiler.
|
java.lang.Object |
jjtAccept(JavaParserVisitor visitor,
java.lang.Object data) |
Accept the visitor.
|
void |
setExplicitReceiverParameter() |
|
void |
setNameDeclaration(VariableNameDeclaration decl) |
childrenAccept, comment, comment, getScope, getXPathNodeName, jjtClose, jjtOpen, setScope
getTypeDefinition, setType, setTypeDefinition
appendElement, findChildNodesWithXPath, findChildrenOfType, findDescendantsOfType, findDescendantsOfType, findDescendantsOfType, getAsDocument, getBeginColumn, getBeginLine, getDataFlowNode, getEndColumn, getEndLine, getFirstChildOfType, getFirstDescendantOfType, getFirstParentOfAnyType, getFirstParentOfType, getImage, getNthParent, getParentsOfType, getUserData, 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
findChildNodesWithXPath, findChildrenOfType, findDescendantsOfType, findDescendantsOfType, getAsDocument, getBeginColumn, getBeginLine, getDataFlowNode, getEndColumn, getEndLine, getFirstChildOfType, getFirstDescendantOfType, getFirstParentOfAnyType, getFirstParentOfType, getImage, getNthParent, getParentsOfType, getUserData, getXPathNodeName, hasDescendantMatchingXPath, hasDescendantOfType, hasImageEqualTo, isFindBoundary, jjtAddChild, jjtClose, jjtGetChild, jjtGetChildIndex, jjtGetId, jjtGetNumChildren, jjtGetParent, jjtOpen, jjtSetChildIndex, jjtSetParent, remove, removeChildAtIndex, setDataFlowNode, setImage, setUserData
public ASTVariableDeclaratorId(int id)
public ASTVariableDeclaratorId(JavaParser p, int id)
public java.lang.Object jjtAccept(JavaParserVisitor visitor, java.lang.Object data)
jjtAccept
in interface JavaNode
jjtAccept
in class AbstractJavaNode
public VariableNameDeclaration getNameDeclaration()
public void setNameDeclaration(VariableNameDeclaration decl)
public java.util.List<net.sourceforge.pmd.lang.symboltable.NameOccurrence> getUsages()
public void bumpArrayDepth()
public int getArrayDepth()
getArrayDepth
in interface Dimensionable
public boolean isArray()
isArray
in interface Dimensionable
public boolean isExceptionBlockParameter()
catch
statement.public boolean isFormalParameter()
isExplicitReceiverParameter()
).public void setExplicitReceiverParameter()
public boolean isExplicitReceiverParameter()
this
, and must be declared
at the beginning of the parameter list. Its only purpose is to annotate
the type of the object on which the method call is issued. It was introduced
in Java 8.public boolean isResourceDeclaration()
public boolean isTypeInferred()
(a, b) -> a + b
).
Since Java 10, the type of local variables can be inferred
too, e.g. var i = 2;
.
This method returns true for declarator IDs in those contexts,
in which case getTypeNode()
returns null
,
since the type node is absent.
public net.sourceforge.pmd.lang.ast.Node getTypeNameNode()
getTypeNode()
.
The image of that node can usually be interpreted as the image of the
type.public ASTType getTypeNode()
The type of the returned node is not necessarily the type of this
node. See getType()
for an explanation.
null
if there is no explicit type,
e.g. if isTypeInferred()
returns true.public java.lang.Class<?> getType()
int a[];
int a[], b;
.
These are consequences of Java's allowing programmers to
declare additional pairs of brackets on declarator ids. The type
of the node returned by getTypeNode()
doesn't take into
account those additional array dimensions, whereas this node's
type takes into account the total number of dimensions, i.e.
those declared on this node plus those declared on the type node.
The returned type also takes into account whether this variable is a varargs formal parameter.
The type of the declarator ID is thus always the real type of the variable.
getType
in interface TypeNode
getType
in class AbstractJavaTypeNode
null
.Copyright © 2002–2018 PMD. All rights reserved.