Package com.github.javaparser.ast.body
Class FieldDeclaration
java.lang.Object
com.github.javaparser.ast.Node
com.github.javaparser.ast.body.BodyDeclaration<FieldDeclaration>
com.github.javaparser.ast.body.FieldDeclaration
- All Implemented Interfaces:
NodeWithAccessModifiers<FieldDeclaration>,NodeWithFinalModifier<FieldDeclaration>,NodeWithPrivateModifier<FieldDeclaration>,NodeWithProtectedModifier<FieldDeclaration>,NodeWithPublicModifier<FieldDeclaration>,NodeWithStaticModifier<FieldDeclaration>,NodeWithAnnotations<FieldDeclaration>,NodeWithJavadoc<FieldDeclaration>,NodeWithModifiers<FieldDeclaration>,NodeWithRange<Node>,NodeWithTokenRange<Node>,NodeWithVariables<FieldDeclaration>,Observable,Visitable,HasParentNode<Node>,Resolvable<ResolvedFieldDeclaration>,Cloneable
public class FieldDeclaration
extends BodyDeclaration<FieldDeclaration>
implements NodeWithJavadoc<FieldDeclaration>, NodeWithVariables<FieldDeclaration>, NodeWithAccessModifiers<FieldDeclaration>, NodeWithStaticModifier<FieldDeclaration>, NodeWithFinalModifier<FieldDeclaration>, Resolvable<ResolvedFieldDeclaration>
The declaration of a field in a class. "private static int a=15*15;" in this example:
All annotations preceding the type will be set on this object, not on the type. JavaParser doesn't know if it they are applicable to the method or the type.
class X { private static
int a=15*15; }
All annotations preceding the type will be set on this object, not on the type. JavaParser doesn't know if it they are applicable to the method or the 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
ConstructorsConstructorDescriptionFieldDeclaration(NodeList<Modifier> modifiers, VariableDeclarator variable)FieldDeclaration(NodeList<Modifier> modifiers, NodeList<VariableDeclarator> variables)FieldDeclaration(NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<VariableDeclarator> variables)FieldDeclaration(NodeList<Modifier> modifiers, Type type, String name)Creates aFieldDeclaration.FieldDeclaration(TokenRange tokenRange, NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<VariableDeclarator> variables)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()Create a getter for this field, will only work if this field declares only 1 identifier and if this field is already added to a ClassOrInterfaceDeclarationCreate a setter for this field, will only work if this field declares only 1 identifier and if this field is already added to a ClassOrInterfaceDeclarationReturn the modifiers of this member declaration.voidifFieldDeclaration(Consumer<FieldDeclaration> action)booleanbooleanbooleanbooleanbooleanresolve()setModifiers(NodeList<Modifier> modifiers)setTransient(boolean set)setVariables(NodeList<VariableDeclarator> variables)setVolatile(boolean set)Methods inherited from class com.github.javaparser.ast.body.BodyDeclaration
asAnnotationDeclaration, asAnnotationMemberDeclaration, asCallableDeclaration, asClassOrInterfaceDeclaration, asCompactConstructorDeclaration, asConstructorDeclaration, asEnumConstantDeclaration, asEnumDeclaration, asInitializerDeclaration, asMethodDeclaration, asRecordDeclaration, asTypeDeclaration, getAnnotations, ifAnnotationDeclaration, ifAnnotationMemberDeclaration, ifCallableDeclaration, ifClassOrInterfaceDeclaration, ifCompactConstructorDeclaration, ifConstructorDeclaration, ifEnumConstantDeclaration, ifEnumDeclaration, ifInitializerDeclaration, ifMethodDeclaration, ifRecordDeclaration, ifTypeDeclaration, isAnnotationDeclaration, isAnnotationMemberDeclaration, isCallableDeclaration, isClassOrInterfaceDeclaration, isCompactConstructorDeclaration, isConstructorDeclaration, isEnumConstantDeclaration, isEnumDeclaration, isInitializerDeclaration, isMethodDeclaration, isRecordDeclaration, isTypeDeclaration, setAnnotations, toAnnotationDeclaration, toAnnotationMemberDeclaration, toCallableDeclaration, toClassOrInterfaceDeclaration, toCompactConstructorDeclaration, toConstructorDeclaration, toEnumConstantDeclaration, toEnumDeclaration, toInitializerDeclaration, toMethodDeclaration, toRecordDeclaration, toTypeDeclarationMethods inherited from class com.github.javaparser.ast.Node
addOrphanComment, containsData, createDefaultPrinter, createDefaultPrinter, customInitialization, 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.NodeWithAnnotations
addAndGetAnnotation, addAndGetAnnotation, addAnnotation, addAnnotation, addAnnotation, addMarkerAnnotation, addMarkerAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, getAnnotation, getAnnotationByClass, getAnnotationByName, isAnnotationPresent, isAnnotationPresent, setAnnotation, tryAddImportToParentCompilationUnitMethods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier
isFinal, setFinalMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithJavadoc
getComment, getJavadoc, getJavadocComment, hasJavaDocComment, removeJavaDocComment, setComment, setJavadocComment, setJavadocComment, setJavadocComment, setJavadocCommentMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithModifiers
addModifier, getAccessSpecifier, hasModifier, removeModifier, setModifier, setModifiersMethods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithPrivateModifier
isPrivate, setPrivateMethods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithProtectedModifier
isProtected, setProtectedMethods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithPublicModifier
isPublic, setPublicMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithRange
containsWithin, containsWithinRange, getBegin, getEnd, hasRangeMethods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStaticModifier
isStatic, setStaticMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithVariables
addVariable, getCommonType, getElementType, getMaximumCommonType, getVariable, setAllTypes, setVariable
-
Constructor Details
-
FieldDeclaration
public FieldDeclaration() -
FieldDeclaration
-
FieldDeclaration
-
FieldDeclaration
public FieldDeclaration(NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<VariableDeclarator> variables) -
FieldDeclaration
public FieldDeclaration(TokenRange tokenRange, NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<VariableDeclarator> variables)This constructor is used by the parser and is considered private. -
FieldDeclaration
Creates aFieldDeclaration.- Parameters:
modifiers- modifierstype- typename- field name
-
-
Method Details
-
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. -
getModifiers
Return the modifiers of this member declaration.- Specified by:
getModifiersin interfaceNodeWithModifiers<FieldDeclaration>- Returns:
- modifiers
- See Also:
Modifier
-
getVariables
- Specified by:
getVariablesin interfaceNodeWithVariables<FieldDeclaration>
-
setModifiers
- Specified by:
setModifiersin interfaceNodeWithModifiers<FieldDeclaration>
-
setVariables
- Specified by:
setVariablesin interfaceNodeWithVariables<FieldDeclaration>
-
createGetter
Create a getter for this field, will only work if this field declares only 1 identifier and if this field is already added to a ClassOrInterfaceDeclaration- Returns:
- the
MethodDeclarationcreated - Throws:
IllegalStateException- if there is more than 1 variable identifier or if this field isn't attached to a class or enum
-
createSetter
Create a setter for this field, will only work if this field declares only 1 identifier and if this field is already added to a ClassOrInterfaceDeclaration- Returns:
- the
MethodDeclarationcreated - Throws:
IllegalStateException- if there is more than 1 variable identifier or if this field isn't attached to a class or enum
-
isTransient
public boolean isTransient() -
isVolatile
public boolean isVolatile() -
setTransient
-
setVolatile
-
remove
- Overrides:
removein classBodyDeclaration<FieldDeclaration>
-
clone
- Overrides:
clonein classBodyDeclaration<FieldDeclaration>
-
getMetaModel
- Overrides:
getMetaModelin classBodyDeclaration<FieldDeclaration>- Returns:
- get JavaParser specific node introspection information.
-
replace
- Overrides:
replacein classBodyDeclaration<FieldDeclaration>
-
isFieldDeclaration
public boolean isFieldDeclaration()- Overrides:
isFieldDeclarationin classBodyDeclaration<FieldDeclaration>
-
asFieldDeclaration
- Overrides:
asFieldDeclarationin classBodyDeclaration<FieldDeclaration>
-
ifFieldDeclaration
- Overrides:
ifFieldDeclarationin classBodyDeclaration<FieldDeclaration>
-
resolve
- Specified by:
resolvein interfaceResolvable<ResolvedFieldDeclaration>
-
toFieldDeclaration
- Overrides:
toFieldDeclarationin classBodyDeclaration<FieldDeclaration>
-