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
ConstructorsConstructorDescriptionVariableDeclarator(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> Raccept(GenericVisitor<R,A> v, A arg)Accept method for visitor support.<A> voidaccept(VoidVisitor<A> v, A arg)Accept method for visitor support.clone()protected voidCalled in every constructor for node specific code.getName()getType()Gets the typebooleanbooleanresolve()setInitializer(Expression initializer)Sets the initializer expressionsetInitializer(String init)Will create aNameExprwith 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, walkMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.github.javaparser.HasParentNode
findAncestor, findAncestor, hasParentNode, isDescendantOfMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithRange
containsWithin, containsWithinRange, getBegin, getEnd, hasRangeMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithSimpleName
getNameAsExpression, getNameAsString, setNameMethods 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. AnAssignExpris 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:NodeCalled 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:
customInitializationin classNode
-
accept
Description copied from interface:VisitableAccept method for visitor support.- Specified by:
acceptin 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:VisitableAccept method for visitor support. -
getInitializer
-
getName
- Specified by:
getNamein interfaceNodeWithSimpleName<VariableDeclarator>
-
setName
- Specified by:
setNamein interfaceNodeWithSimpleName<VariableDeclarator>
-
setInitializer
Sets the initializer expression- Parameters:
initializer- the initializer expression, can be null- Returns:
- this, the VariableDeclarator
-
setInitializer
Will create aNameExprwith the initializer param- Parameters:
init- the initializer expression, can be null- Returns:
- this, the VariableDeclarator
-
getType
Description copied from interface:NodeWithTypeGets the type- Specified by:
getTypein interfaceNodeWithType<VariableDeclarator,Type>- Returns:
- the type
-
setType
Description copied from interface:NodeWithTypeSets the type- Specified by:
setTypein interfaceNodeWithType<VariableDeclarator,Type>- Parameters:
type- the type- Returns:
- this
-
remove
-
removeInitializer
-
clone
-
getMetaModel
- Overrides:
getMetaModelin classNode- Returns:
- get JavaParser specific node introspection information.
-
replace
-
resolve
- Specified by:
resolvein interfaceResolvable<ResolvedValueDeclaration>
-