Top Description Fields Constructors Methods
com.github.javaparser.ast.body

public Class VariableDeclarator

extends Node
implements NodeWithType<VariableDeclarator, Type>, NodeWithSimpleName<VariableDeclarator>, Resolvable<ResolvedValueDeclaration>
Class Inheritance
All Implemented Interfaces
com.github.javaparser.resolution.Resolvable, com.github.javaparser.ast.nodeTypes.NodeWithSimpleName, com.github.javaparser.ast.nodeTypes.NodeWithType
Imports
com.github.javaparser.ast.AllFieldsConstructor, .Node, .Generated, com.github.javaparser.ast.expr.Expression, .NameExpr, .SimpleName, com.github.javaparser.ast.nodeTypes.NodeWithSimpleName, .NodeWithType, .NodeWithVariables, com.github.javaparser.ast.observer.AstObserverAdapter, .ObservableProperty, com.github.javaparser.ast.type.ClassOrInterfaceType, .Type, com.github.javaparser.ast.visitor.CloneVisitor, .GenericVisitor, .VoidVisitor, com.github.javaparser.metamodel.JavaParserMetaModel, .NonEmptyProperty, .OptionalProperty, .VariableDeclaratorMetaModel, java.util.LinkedList, .List, .Optional, com.github.javaparser.TokenRange, com.github.javaparser.resolution.Resolvable, com.github.javaparser.resolution.declarations.ResolvedValueDeclaration

The declaration of a variable.
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

Field Summary

Modifier and TypeField and Description
private Expression
private SimpleName
private Type
Inherited from com.github.javaparser.ast.Node:
ABSOLUTE_BEGIN_LINEABSOLUTE_END_LINENODE_BY_BEGIN_POSITIONprettyPrinterNoCommentsConfigurationSYMBOL_RESOLVER_KEY

Constructor Summary

AccessConstructor and Description
public
public
VariableDeclarator(Type type, String variableName)

public
public
VariableDeclarator(Type type, String variableName, Expression initializer)

public
VariableDeclarator(Type type, SimpleName
The identifier for this variable. IE. The variables name.
name
,
Expression
What this variable should be initialized to. An com.github.javaparser.ast.expr.AssignExpr is unnecessary as the = operator is already added.
initializer
)

Defines the declaration of a variable.

public
VariableDeclarator(TokenRange tokenRange, Type type, SimpleName name, Expression initializer)

This constructor is used by the parser and is considered private.

Method Summary

Modifier and TypeMethod and Description
public <R, A> R
accept(final GenericVisitor<R, A>
the visitor implementation
v
,
final A
the argument passed to the visitor (of type A)
arg
)

Implements com.github.javaparser.ast.visitor.Visitable.accept.

Accept method for visitor support.
public <A> void
accept(final VoidVisitor<A>
the visitor implementation
v
,
final A
any value relevant for the visitor (of type A)
arg
)

Implements com.github.javaparser.ast.visitor.Visitable.accept.

Accept method for visitor support.
public VariableDeclarator
clone()

Overrides com.github.javaparser.ast.Node.clone.

Creates and returns a copy of this object.
protected void
customInitialization()

Overrides com.github.javaparser.ast.Node.customInitialization.

Called in every constructor for node specific code.
public Optional<Expression>
public VariableDeclaratorMetaModel
public SimpleName
public Type
public boolean
public VariableDeclarator
public boolean
replace(Node node, Node replacementNode)

Overrides com.github.javaparser.ast.Node.replace.

public ResolvedValueDeclaration
public VariableDeclarator

Returns:

this, the VariableDeclarator
setInitializer
(final Expression
the initializer expression, can be null
initializer
)

Sets the initializer expression

public VariableDeclarator

Returns:

this, the VariableDeclarator
setInitializer
(String
the initializer expression, can be null
init
)

Will create a NameExpr with the initializer param

public VariableDeclarator
public VariableDeclarator
setType(final Type
the type
type
)

Implements com.github.javaparser.ast.nodeTypes.NodeWithType.setType.

Sets the type
Inherited from com.github.javaparser.ast.Node:
addOrphanCommentcontainsDataequalsfindAllfindAllfindCompilationUnitfindFirstfindFirstfindFirstfindRootNodegetAllContainedCommentsgetChildNodesgetChildNodesByTypegetCommentgetDatagetDataKeysgetNodesByTypegetOrphanCommentsgetParentNodegetParentNodeForChildrengetParsedgetRangegetSymbolResolvergetTokenRangegetToStringPrettyPrinterConfigurationhashCodeisAncestorOfisRegisterednotifyPropertyChangeregisterregisterregisterForSubtreeremoveremoveCommentremoveDataremoveForcedremoveOrphanCommentreplacesetAsParentNodeOfsetAsParentNodeOfsetBlockCommentsetCommentsetDatasetLineCommentsetParentNodesetParsedsetRangesetTokenRangesetToStringPrettyPrinterConfigurationstreamstreamtoStringtoStringtryAddImportToParentCompilationUnitunregisterwalkwalkwalk

Field Detail

initializerback to summary
private Expression initializer
Annotations
@OptionalProperty
@NonEmptyProperty
nameback to summary
private SimpleName name
typeback to summary
private Type type

Constructor Detail

VariableDeclaratorback to summary
public VariableDeclarator()
VariableDeclaratorback to summary
public VariableDeclarator(Type type, String variableName)
VariableDeclaratorback to summary
public VariableDeclarator(Type type, SimpleName name)
VariableDeclaratorback to summary
public VariableDeclarator(Type type, String variableName, Expression initializer)
VariableDeclaratorback to summary
public VariableDeclarator(Type type, SimpleName name, Expression initializer)

Defines the declaration of a variable.

Parameters
name:SimpleName

The identifier for this variable. IE. The variables name.

initializer:Expression

What this variable should be initialized to. An com.github.javaparser.ast.expr.AssignExpr is unnecessary as the = operator is already added.

Annotations
@AllFieldsConstructor
VariableDeclaratorback to summary
public VariableDeclarator(TokenRange tokenRange, Type type, SimpleName name, Expression initializer)

This constructor is used by the parser and is considered private.

Annotations
@Generated:com.github.javaparser.generator.core.node.MainConstructorGenerator

Method Detail

acceptback to summary
public <R, A> R accept(final GenericVisitor<R, A> v, final A arg)

Implements com.github.javaparser.ast.visitor.Visitable.accept.

Doc from com.github.javaparser.ast.visitor.Visitable.accept.

Accept method for visitor support.

Parameters
<R>
the type of the return value of the visitor
<A>
the type the user argument passed to the visitor
v:GenericVisitor<R, A>

the visitor implementation

arg:A

the argument passed to the visitor (of type A)

Returns:R

the result of the visit (of type R)

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.AcceptGenerator
acceptback to summary
public <A> void accept(final VoidVisitor<A> v, final A arg)

Implements com.github.javaparser.ast.visitor.Visitable.accept.

Doc from com.github.javaparser.ast.visitor.Visitable.accept.

Accept method for visitor support.

Parameters
<A>
the type the argument passed for the visitor
v:VoidVisitor<A>

the visitor implementation

arg:A

any value relevant for the visitor (of type A)

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.AcceptGenerator
cloneback to summary
public VariableDeclarator clone()

Overrides com.github.javaparser.ast.Node.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:VariableDeclarator

a clone of this instance.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.CloneGenerator
customInitializationback to summary
protected void customInitialization()

Overrides com.github.javaparser.ast.Node.customInitialization.

Doc from com.github.javaparser.ast.Node.customInitialization.

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.

Annotations
@Override
getInitializerback to summary
public Optional<Expression> getInitializer()
Annotations
@Generated:com.github.javaparser.generator.core.node.PropertyGenerator
getMetaModelback to summary
public VariableDeclaratorMetaModel getMetaModel()

Overrides com.github.javaparser.ast.Node.getMetaModel.

Returns:VariableDeclaratorMetaModel

Doc from com.github.javaparser.ast.Node.getMetaModel.

get JavaParser specific node introspection information.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.GetMetaModelGenerator
getNameback to summary
public SimpleName getName()

Implements com.github.javaparser.ast.nodeTypes.NodeWithSimpleName.getName.

Annotations
@Generated:com.github.javaparser.generator.core.node.PropertyGenerator
getTypeback to summary
public Type getType()

Implements com.github.javaparser.ast.nodeTypes.NodeWithType.getType.

Doc from com.github.javaparser.ast.nodeTypes.NodeWithType.getType.

Gets the type

Returns:Type

the type

Annotations
@Generated:com.github.javaparser.generator.core.node.PropertyGenerator
removeback to summary
public boolean remove(Node node)

Overrides com.github.javaparser.ast.Node.remove.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.RemoveMethodGenerator
removeInitializerback to summary
public VariableDeclarator removeInitializer()
Annotations
@Generated:com.github.javaparser.generator.core.node.RemoveMethodGenerator
replaceback to summary
public boolean replace(Node node, Node replacementNode)

Overrides com.github.javaparser.ast.Node.replace.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.ReplaceMethodGenerator
resolveback to summary
public ResolvedValueDeclaration resolve()

Implements com.github.javaparser.resolution.Resolvable.resolve.

Annotations
@Override
setInitializerback to summary
public VariableDeclarator setInitializer(final Expression initializer)

Sets the initializer expression

Parameters
initializer:Expression

the initializer expression, can be null

Returns:VariableDeclarator

this, the VariableDeclarator

Annotations
@Generated:com.github.javaparser.generator.core.node.PropertyGenerator
setInitializerback to summary
public VariableDeclarator setInitializer(String init)

Will create a NameExpr with the initializer param

Parameters
init:String

the initializer expression, can be null

Returns:VariableDeclarator

this, the VariableDeclarator

setNameback to summary
public VariableDeclarator setName(final SimpleName name)

Implements com.github.javaparser.ast.nodeTypes.NodeWithSimpleName.setName.

Annotations
@Generated:com.github.javaparser.generator.core.node.PropertyGenerator
setTypeback to summary
public VariableDeclarator setType(final Type type)

Implements com.github.javaparser.ast.nodeTypes.NodeWithType.setType.

Doc from com.github.javaparser.ast.nodeTypes.NodeWithType.setType.

Sets the type

Parameters
type:Type

the type

Returns:VariableDeclarator

this

Annotations
@Generated:com.github.javaparser.generator.core.node.PropertyGenerator