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 final class VariableDeclarator extends Node implements NodeWithType<VariableDeclarator,Type>, NodeWithSimpleName<VariableDeclarator>, Resolvable<ResolvedValueDeclaration>
The declaration of a variable.
Inint 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, NODE_BY_BEGIN_POSITION, prettyPrinterNoCommentsConfiguration, SYMBOL_RESOLVER_KEY
-
-
Constructor Summary
Constructors Constructor Description VariableDeclarator()
VariableDeclarator(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <R,A>
Raccept(GenericVisitor<R,A> v, A arg)
Accept method for visitor support.<A> void
accept(VoidVisitor<A> v, A arg)
Accept method for visitor support.VariableDeclarator
clone()
protected void
customInitialization()
Called in every constructor for node specific code.Optional<Expression>
getInitializer()
VariableDeclaratorMetaModel
getMetaModel()
SimpleName
getName()
Type
getType()
Gets the typeboolean
remove(Node node)
VariableDeclarator
removeInitializer()
boolean
replace(Node node, Node replacementNode)
ResolvedValueDeclaration
resolve()
VariableDeclarator
setInitializer(Expression initializer)
Sets the initializer expressionVariableDeclarator
setInitializer(String init)
Will create aNameExpr
with the initializer paramVariableDeclarator
setName(SimpleName name)
VariableDeclarator
setType(Type type)
Sets the type-
Methods inherited from class com.github.javaparser.ast.Node
addOrphanComment, containsData, equals, findAll, findAll, findCompilationUnit, findFirst, findFirst, findFirst, findRootNode, getAllContainedComments, getChildNodes, getChildNodesByType, getComment, getData, getNodesByType, getOrphanComments, getParentNode, getParentNodeForChildren, getParsed, getRange, getSymbolResolver, getTokenRange, hasComment, hashCode, 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, findParent, getAncestorOfType
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithRange
containsWithin, getBegin, getEnd, isPositionedAfter, isPositionedBefore
-
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 Detail
-
VariableDeclarator
public VariableDeclarator()
-
VariableDeclarator
public VariableDeclarator(Type type, SimpleName name)
-
VariableDeclarator
public VariableDeclarator(Type type, String variableName, Expression initializer)
-
VariableDeclarator
public VariableDeclarator(Type type, SimpleName name, Expression initializer)
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 Detail
-
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
public <R,A> R accept(GenericVisitor<R,A> v, A arg)
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
public <A> void accept(VoidVisitor<A> v, A arg)
Description copied from interface:Visitable
Accept method for visitor support.
-
getInitializer
public Optional<Expression> getInitializer()
-
getName
public SimpleName getName()
- Specified by:
getName
in interfaceNodeWithSimpleName<VariableDeclarator>
-
setName
public VariableDeclarator setName(SimpleName name)
- Specified by:
setName
in interfaceNodeWithSimpleName<VariableDeclarator>
-
setInitializer
public VariableDeclarator setInitializer(Expression initializer)
Sets the initializer expression- Parameters:
initializer
- the initializer expression, can be null- Returns:
- this, the VariableDeclarator
-
setInitializer
public VariableDeclarator setInitializer(String init)
Will create aNameExpr
with the initializer param- Parameters:
init
- the initializer expression, can be null- Returns:
- this, the VariableDeclarator
-
getType
public Type getType()
Description copied from interface:NodeWithType
Gets the type- Specified by:
getType
in interfaceNodeWithType<VariableDeclarator,Type>
- Returns:
- the type
-
setType
public VariableDeclarator setType(Type type)
Description copied from interface:NodeWithType
Sets the type- Specified by:
setType
in interfaceNodeWithType<VariableDeclarator,Type>
- Parameters:
type
- the type- Returns:
- this
-
removeInitializer
public VariableDeclarator removeInitializer()
-
clone
public VariableDeclarator clone()
-
getMetaModel
public VariableDeclaratorMetaModel getMetaModel()
- Overrides:
getMetaModel
in classNode
- Returns:
- get JavaParser specific node introspection information.
-
resolve
public ResolvedValueDeclaration resolve()
- Specified by:
resolve
in interfaceResolvable<ResolvedValueDeclaration>
-
-