Class JavaParserFieldDeclaration
- java.lang.Object
-
- com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration
-
- All Implemented Interfaces:
AssociableToAST,HasAccessSpecifier,ResolvedDeclaration,ResolvedFieldDeclaration,ResolvedValueDeclaration
public class JavaParserFieldDeclaration extends java.lang.Object implements ResolvedFieldDeclaration
-
-
Field Summary
Fields Modifier and Type Field Description private TypeSolvertypeSolverprivate VariableDeclaratorvariableDeclaratorprivate FieldDeclarationwrappedNode
-
Constructor Summary
Constructors Constructor Description JavaParserFieldDeclaration(VariableDeclarator variableDeclarator, TypeSolver typeSolver)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AccessSpecifieraccessSpecifier()The access specifier of this element.ResolvedTypeDeclarationdeclaringType()The type on which this field has been declaredjava.lang.StringgetName()Should return the name or return null if the name is not available.ResolvedTypegetType()Type of the declaration.VariableDeclaratorgetVariableDeclarator()FieldDeclarationgetWrappedNode()Returns the JavaParser node associated with this JavaParserFieldDeclaration.booleanisField()Does this declaration represents a class field?booleanisStatic()Is the field static?booleanisVolatile()Is the field volatile?java.util.Optional<Node>toAst()If the declaration is associated to an AST node return it, otherwise it return empty.java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.javaparser.resolution.declarations.AssociableToAST
toAst
-
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedDeclaration
asEnumConstant, asMethod, asParameter, asType, asTypePattern, hasName, isEnumConstant, isMethod, isParameter, isType, isTypePattern, isVariable
-
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration
asField
-
-
-
-
Field Detail
-
variableDeclarator
private VariableDeclarator variableDeclarator
-
wrappedNode
private FieldDeclaration wrappedNode
-
typeSolver
private TypeSolver typeSolver
-
-
Constructor Detail
-
JavaParserFieldDeclaration
public JavaParserFieldDeclaration(VariableDeclarator variableDeclarator, TypeSolver typeSolver)
-
-
Method Detail
-
getType
public ResolvedType getType()
Description copied from interface:ResolvedValueDeclarationType of the declaration.- Specified by:
getTypein interfaceResolvedValueDeclaration
-
getName
public java.lang.String getName()
Description copied from interface:ResolvedDeclarationShould return the name or return null if the name is not available.- Specified by:
getNamein interfaceResolvedDeclaration
-
isStatic
public boolean isStatic()
Description copied from interface:ResolvedFieldDeclarationIs the field static?- Specified by:
isStaticin interfaceResolvedFieldDeclaration
-
isVolatile
public boolean isVolatile()
Description copied from interface:ResolvedFieldDeclarationIs the field volatile?- Specified by:
isVolatilein interfaceResolvedFieldDeclaration
-
isField
public boolean isField()
Description copied from interface:ResolvedDeclarationDoes this declaration represents a class field?- Specified by:
isFieldin interfaceResolvedDeclaration- Specified by:
isFieldin interfaceResolvedFieldDeclaration
-
getWrappedNode
public FieldDeclaration getWrappedNode()
Returns the JavaParser node associated with this JavaParserFieldDeclaration.- Returns:
- A visitable JavaParser node wrapped by this object.
-
getVariableDeclarator
public VariableDeclarator getVariableDeclarator()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
accessSpecifier
public AccessSpecifier accessSpecifier()
Description copied from interface:HasAccessSpecifierThe access specifier of this element.- Specified by:
accessSpecifierin interfaceHasAccessSpecifier
-
declaringType
public ResolvedTypeDeclaration declaringType()
Description copied from interface:ResolvedFieldDeclarationThe type on which this field has been declared- Specified by:
declaringTypein interfaceResolvedFieldDeclaration
-
toAst
public java.util.Optional<Node> toAst()
Description copied from interface:AssociableToASTIf the declaration is associated to an AST node return it, otherwise it return empty. Declaration based on source code have an AST node associated while others don't. Example of other declarations are declarations coming from reflection or JARs. You may wonder how this method is different from the various getWrappedNode. The difference is that toAst is present in all Resolved* declarations (such as ResolvedAnnotationDeclaration), while getWrappedNode is present only on the subclasses of the Resolved* declarations that derive from JP AST nodes (such as JavaParserClassDeclaration). Therefore one which has a Resolved* declaration need to do a downcast before being able to use getWrappedNode. Now, this means that toAst could potentially replace getWrappedNode (but not the other way around!). However toAst return an Optional, which is less convenient than getting the direct node. Also, toAst sometimes have to return a more generic node. This is the case for subclasses of ResolvedClassDeclaration. In those cases toAst return a Node. Why? Because both anonymous class declarations and standard class declarations are subclasses of that. In one case the underlying AST node is an ObjectCreationExpr, while in the other case it is ClassOrInterfaceDeclaration. In these cases getWrappedNode is particularly nice because it returns the right type of AST node, not just a Node.- Specified by:
toAstin interfaceAssociableToAST
-
-