Package com.github.javaparser.ast.body
Class VariableDeclarator
java.lang.Object
com.github.javaparser.ast.Node
com.github.javaparser.ast.body.VariableDeclarator
- All Implemented Interfaces:
NodeWithRange<Node>
,NodeWithSimpleName<VariableDeclarator>
,NodeWithTokenRange<Node>
,NodeWithType<VariableDeclarator,Type>
,Observable
,Visitable
,HasParentNode<Node>
,Resolvable<ResolvedValueDeclaration>
,Cloneable
public class VariableDeclarator
extends Node
implements NodeWithType<VariableDeclarator,Type>, NodeWithSimpleName<VariableDeclarator>, Resolvable<ResolvedValueDeclaration>
The declaration of a variable.
In
In
int x = 14, y = 3;
"int x = 14" and "int y = 3" are
VariableDeclarators.
The type is on all of the variable declarators because, thanks to array brackets, each variable can have a different type.
- Author:
- Julio Vilmar Gesser
-
Nested Class Summary
Nested classes/interfaces inherited from class com.github.javaparser.ast.Node
Node.BreadthFirstIterator, Node.DirectChildrenIterator, Node.ObserverRegistrationMode, Node.ParentsVisitor, Node.Parsedness, Node.PostOrderIterator, Node.PreOrderIterator, Node.TreeTraversal
-
Field Summary
Fields inherited from class com.github.javaparser.ast.Node
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE, LINE_SEPARATOR_KEY, NODE_BY_BEGIN_POSITION, PHANTOM_KEY, prettyPrinterNoCommentsConfiguration, PRINTER_KEY, SYMBOL_RESOLVER_KEY
-
Constructor Summary
ConstructorDescriptionVariableDeclarator(Type type, SimpleName name)
VariableDeclarator(Type type, SimpleName name, Expression initializer)
Defines the declaration of a variable.VariableDeclarator(Type type, String variableName)
VariableDeclarator(Type type, String variableName, Expression initializer)
VariableDeclarator(TokenRange tokenRange, Type type, SimpleName name, Expression initializer)
This constructor is used by the parser and is considered private. -
Method Summary
Modifier and TypeMethodDescription<R, A> R
accept(GenericVisitor<R,A> v, A arg)
Accept method for visitor support.<A> void
accept(VoidVisitor<A> v, A arg)
Accept method for visitor support.clone()
protected void
Called in every constructor for node specific code.getName()
getType()
Gets the typeboolean
boolean
resolve()
setInitializer(Expression initializer)
Sets the initializer expressionsetInitializer(String init)
Will create aNameExpr
with the initializer paramsetName(SimpleName name)
Sets the typeMethods inherited from class com.github.javaparser.ast.Node
addOrphanComment, containsData, createDefaultPrinter, createDefaultPrinter, equals, findAll, findAll, findAll, findCompilationUnit, findFirst, findFirst, findFirst, findRootNode, getAllContainedComments, getChildNodes, getChildNodesByType, getComment, getData, getDataKeys, getDefaultPrinterConfiguration, getLineEndingStyle, getLineEndingStyleOrDefault, getNodesByType, getOrphanComments, getParentNode, getParentNodeForChildren, getParsed, getPrinter, getPrinter, getRange, getSymbolResolver, getTokenRange, hashCode, hasScope, isAncestorOf, isPhantom, isRegistered, notifyPropertyChange, register, register, registerForSubtree, remove, removeComment, removeData, removeForced, removeOrphanComment, replace, setAsParentNodeOf, setAsParentNodeOf, setBlockComment, setComment, setData, setLineComment, setParentNode, setParsed, setRange, setTokenRange, stream, stream, toString, toString, tryAddImportToParentCompilationUnit, unregister, walk, walk, walk
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.github.javaparser.HasParentNode
findAncestor, findAncestor, findAncestor, hasParentNode, isDescendantOf
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithRange
containsWithin, containsWithinRange, getBegin, getEnd, hasRange
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithSimpleName
getNameAsExpression, getNameAsString, setName
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithType
getTypeAsString, setType, setType, tryAddImportToParentCompilationUnit
-
Constructor Details
-
VariableDeclarator
public VariableDeclarator() -
VariableDeclarator
-
VariableDeclarator
-
VariableDeclarator
-
VariableDeclarator
Defines the declaration of a variable.- Parameters:
name
- The identifier for this variable. IE. The variables name.initializer
- What this variable should be initialized to. AnAssignExpr
is unnecessary as the=
operator is already added.
-
VariableDeclarator
public VariableDeclarator(TokenRange tokenRange, Type type, SimpleName name, Expression initializer)This constructor is used by the parser and is considered private.
-
-
Method Details
-
customInitialization
protected void customInitialization()Description copied from class:Node
Called in every constructor for node specific code. It can't be written in the constructor itself because it will be overwritten during code generation.- Overrides:
customInitialization
in classNode
-
accept
Description copied from interface:Visitable
Accept method for visitor support.- Specified by:
accept
in interfaceVisitable
- Type Parameters:
R
- the type of the return value of the visitorA
- the type the user argument passed to the visitor- Parameters:
v
- the visitor implementationarg
- the argument passed to the visitor (of type A)- Returns:
- the result of the visit (of type R)
-
accept
Description copied from interface:Visitable
Accept method for visitor support. -
getInitializer
-
getName
- Specified by:
getName
in interfaceNodeWithSimpleName<VariableDeclarator>
-
setName
- Specified by:
setName
in interfaceNodeWithSimpleName<VariableDeclarator>
-
setInitializer
Sets the initializer expression- Parameters:
initializer
- the initializer expression, can be null- Returns:
- this, the VariableDeclarator
-
setInitializer
Will create aNameExpr
with the initializer param- Parameters:
init
- the initializer expression, can be null- Returns:
- this, the VariableDeclarator
-
getType
Description copied from interface:NodeWithType
Gets the type- Specified by:
getType
in interfaceNodeWithType<VariableDeclarator,Type>
- Returns:
- the type
-
setType
Description copied from interface:NodeWithType
Sets the type- Specified by:
setType
in interfaceNodeWithType<VariableDeclarator,Type>
- Parameters:
type
- the type- Returns:
- this
-
remove
-
removeInitializer
-
clone
-
getMetaModel
- Overrides:
getMetaModel
in classNode
- Returns:
- get JavaParser specific node introspection information.
-
replace
-
resolve
- Specified by:
resolve
in interfaceResolvable<ResolvedValueDeclaration>
-