Class AbstractTypeDeclaration
java.lang.Object
com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration
- All Implemented Interfaces:
AssociableToAST
,ResolvedDeclaration
,ResolvedReferenceTypeDeclaration
,ResolvedTypeDeclaration
,ResolvedTypeParametrizable
- Direct Known Subclasses:
AbstractClassDeclaration
,JavaParserAnnotationDeclaration
,JavaParserEnumDeclaration
,JavaParserInterfaceDeclaration
,JavaParserRecordDeclaration
,JavaParserTypeParameter
,JavaParserTypeVariableDeclaration
,JavassistAnnotationDeclaration
,JavassistEnumDeclaration
,JavassistInterfaceDeclaration
,JavassistRecordDeclaration
,ReflectionAnnotationDeclaration
,ReflectionEnumDeclaration
,ReflectionInterfaceDeclaration
,ReflectionRecordDeclaration
public abstract class AbstractTypeDeclaration
extends Object
implements ResolvedReferenceTypeDeclaration
Common ancestor for most types.
-
Field Summary
Fields inherited from interface com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration
breadthFirstFunc, depthFirstFunc, JAVA_IO_SERIALIZABLE, JAVA_LANG_COMPARABLE, JAVA_LANG_ENUM, JAVA_LANG_OBJECT, JAVA_LANG_RECORD
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Set
<MethodUsage> Return a list of all the methods declared of this type declaration, either declared or inherited.final boolean
This means that the type has a functional method.static boolean
isRecordType
(Class<?> clazz) With the introduction of records in Java 14 (Preview), theClass.isRecord
method was added to check whether a class is a record or not (similar toisEnum
etc.).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.github.javaparser.resolution.declarations.AssociableToAST
toAst, toAst
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedDeclaration
asEnumConstant, asField, asMethod, asParameter, asTypePattern, getName, hasName, isEnumConstant, isField, isMethod, isParameter, isTypePattern, isVariable
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration
asReferenceType, canBeAssignedTo, findTypeParameter, getAllAncestors, getAllAncestors, getAllFields, getAllNonStaticFields, getAllStaticFields, getAncestors, getAncestors, getConstructors, getDeclaredAnnotation, getDeclaredAnnotations, getDeclaredFields, getDeclaredMethods, getField, getVisibleField, getVisibleFields, hasAnnotation, hasDirectlyAnnotation, hasField, hasVisibleField, isAssignableBy, isAssignableBy, isInheritedAnnotation, isJavaLangEnum, isJavaLangObject, isJavaLangRecord, isReferenceType
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration
asAnnotation, asClass, asEnum, asInterface, asRecord, asType, asTypeParameter, containerType, getClassName, getId, getInternalType, getPackageName, getQualifiedName, hasInternalType, internalTypes, isAnnotation, isAnonymousClass, isClass, isEnum, isInterface, isRecord, isType, isTypeParameter
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable
getTypeParameters, isGeneric
-
Constructor Details
-
AbstractTypeDeclaration
public AbstractTypeDeclaration()
-
-
Method Details
-
getAllMethods
Description copied from interface:ResolvedReferenceTypeDeclaration
Return a list of all the methods declared of this type declaration, either declared or inherited. Note that it should not include overridden methods.- Specified by:
getAllMethods
in interfaceResolvedReferenceTypeDeclaration
-
isFunctionalInterface
public final boolean isFunctionalInterface()Description copied from interface:ResolvedReferenceTypeDeclaration
This means that the type has a functional method. Conceptually, a functional interface has exactly one abstract method. Typically these classes has the FunctionInterface annotation but this is not mandatory.- Specified by:
isFunctionalInterface
in interfaceResolvedReferenceTypeDeclaration
-
isRecordType
With the introduction of records in Java 14 (Preview), theClass.isRecord
method was added to check whether a class is a record or not (similar toisEnum
etc.). This method cannot be used directly in JavaParser, however, since it will not compile on Java versions 8-13 (or 15 if preview features aren't enabled) which are supported by the project. This workaround calls theisRecord
method via reflection which compiles while still giving the expected answer. There are 2 cases to consider when this method is called: 1) JavaParser is invoked using a Java runtime which supports records In this case, theisRecord
method exists, so invoking it will give the answer as usual. 2) JavaParser is invoked using an older Java runtime without record support In this case, theisRecord
method does not exist, so attempting to invoke it will throw aNoSuchMethodException
. This is not a problem since the classloader cannot load classes compiled by Java versions greater than that used to invoke JavaParser. This means that if JavaParser is invoked with a Java 8 runtime, for example, then no classes compiled with Java versions greater than 8 are supported, so no class loaded by the classloader could possibly be a record class since it could not be compiled in the first place. There may be an edge case here for classes compiled with Java 14/15 preview, but most likely these won't load either. In the case of anNoSuchMethodException
, simply return false as the type could not be a record for the reason explained above.
-