Class ReflectionInterfaceDeclaration
java.lang.Object
com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration
com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration
- All Implemented Interfaces:
AssociableToAST, HasAccessSpecifier, ResolvedDeclaration, ResolvedInterfaceDeclaration, ResolvedReferenceTypeDeclaration, ResolvedTypeDeclaration, ResolvedTypeParametrizable, MethodResolutionCapability, MethodUsageResolutionCapability, SymbolResolutionCapability
public class ReflectionInterfaceDeclaration
extends AbstractTypeDeclaration
implements ResolvedInterfaceDeclaration, MethodResolutionCapability, MethodUsageResolutionCapability, SymbolResolutionCapability
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Class<?> Fieldsprivate ReflectionClassAdapterprivate TypeSolverFields inherited from interface ResolvedReferenceTypeDeclaration
breadthFirstFunc, depthFirstFunc, JAVA_IO_SERIALIZABLE, JAVA_LANG_COMPARABLE, JAVA_LANG_ENUM, JAVA_LANG_OBJECT, JAVA_LANG_RECORD -
Constructor Summary
ConstructorsConstructorDescriptionReflectionInterfaceDeclaration(Class<?> clazz, TypeSolver typeSolver) Constructor -
Method Summary
Modifier and TypeMethodDescriptionThe access specifier of this element.Return this as a InterfaceDeclaration or throw UnsupportedOperationException.booleanCan we assign instances of the type defined by this declaration to variables having the type defined by the given type?private List<ResolvedType> collectRegularConstraints(MethodUsage methodUsage, List<ResolvedType> parameterTypes, InferenceContext inferenceContext) Collects type constraints for regular (non-varargs) methods by creating pairs between each formal parameter type and its corresponding actual parameter type.private List<ResolvedType> collectTypeConstraints(MethodUsage methodUsage, List<ResolvedType> parameterTypes, InferenceContext inferenceContext) Collects type constraints by comparing formal parameter types with actual parameter types.private List<ResolvedType> collectVarArgsConstraints(MethodUsage methodUsage, List<ResolvedType> parameterTypes, InferenceContext inferenceContext, int formalParamCount) Collects type constraints for varargs methods.Get the ReferenceTypeDeclaration enclosing this declaration.booleanReturn a list of all fields, either declared in this declaration or inherited.getAncestors(boolean acceptIncompleteList) Resolves the types of all direct ancestors (i.e., the directly extended class and the directly implemented interfaces) and returns the list of ancestors as a list of resolved reference types.The class(es) wrapping this type.Return a list of all the methods declared in this type declaration.Note that the type of the field should be expressed using the type variables of this particular type.Return the list of interfaces extended directly by this one.getName()Should return the name or return null if the name is not available.The package name of the type.The fully qualified name of the type declared.The list of type parameters defined on this element.booleanhasDirectlyAnnotation(String canonicalName) Has the type at least one annotation declared having the specified qualified name?booleanHas this type a field with the given name?inthashCode()Get the list of types defined inside the current type.booleanPublic methodsbooleanisAssignableBy(ResolvedType type) Can we assign instances of the given type to variables having the type defined by this declaration?private booleanisDirectArrayPassing(List<ResolvedType> parameterTypes, int regularParamCount, int actualParamCount) Determines whether arguments are being passed directly as an array to the varargs parameter.booleanIs this the declaration of an interface?booleanIs this the declaration of a type parameter?private Optional<MethodUsage> performTypeInference(MethodUsage methodUsage, List<ResolvedType> parameterTypes) Performs generic type inference on a resolved method usage by analyzing the relationship between formal parameter types and actual parameter types provided at the call site.private voidprocessVarArgsParameter(ResolvedType varargsParamType, List<ResolvedType> parameterTypes, int regularParamCount, InferenceContext inferenceContext, List<ResolvedType> constraints) Processes the varargs parameter by determining how arguments are passed and creating appropriate type constraints.private Optional<MethodUsage> resolveInferredTypes(MethodUsage methodUsage, List<ResolvedType> constraints, InferenceContext inferenceContext) Applies the inferred generic types to the method usage by resolving all collected constraints and updating both parameter types and return type with their concrete resolved types.solveMethod(String name, List<ResolvedType> parameterTypes, boolean staticOnly) Deprecated.solveMethodAsUsage(String name, List<ResolvedType> parameterTypes, Context invokationContext, List<ResolvedType> typeParameterValues) Solves method usage with proper generic type inference, including support for varargs methods.SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) toString()private voidvalidateParameterCount(boolean isVarArgs, int formalParamCount, int actualParamCount) Validates that the number of actual parameters is compatible with the method signature.Methods inherited from class AbstractTypeDeclaration
getAllMethods, isFunctionalInterface, isRecordTypeMethods inherited from interface AssociableToAST
toAst, toAstMethods inherited from interface ResolvedDeclaration
asEnumConstant, asField, asMethod, asParameter, asTypePattern, hasName, isEnumConstant, isField, isMethod, isParameter, isTypePattern, isVariableMethods inherited from interface ResolvedInterfaceDeclaration
getAllInterfacesExtendedMethods inherited from interface ResolvedReferenceTypeDeclaration
asReferenceType, findTypeParameter, getAllAncestors, getAllAncestors, getAllMethods, getAllNonStaticFields, getAllStaticFields, getAncestors, getDeclaredAnnotation, getDeclaredAnnotations, getDeclaredFields, getVisibleField, getVisibleFields, hasAnnotation, hasVisibleField, isFunctionalInterface, isInheritedAnnotation, isJavaLangEnum, isJavaLangObject, isJavaLangRecord, isReferenceTypeMethods inherited from interface ResolvedTypeDeclaration
asAnnotation, asClass, asEnum, asRecord, asType, asTypeParameter, getId, getInternalType, hasInternalType, isAnnotation, isAnonymousClass, isClass, isEnum, isRecord, isTypeMethods inherited from interface ResolvedTypeParametrizable
isGeneric
-
Field Details
-
clazz
Fields -
typeSolver
-
reflectionClassAdapter
-
-
Constructor Details
-
ReflectionInterfaceDeclaration
Constructor
-
-
Method Details
-
isAssignableBy
Public methods- Specified by:
isAssignableByin interfaceResolvedReferenceTypeDeclaration
-
getPackageName
Description copied from interface:ResolvedTypeDeclarationThe package name of the type.- Specified by:
getPackageNamein interfaceResolvedTypeDeclaration
-
getClassName
Description copied from interface:ResolvedTypeDeclarationThe class(es) wrapping this type.- Specified by:
getClassNamein interfaceResolvedTypeDeclaration
-
getQualifiedName
Description copied from interface:ResolvedTypeDeclarationThe fully qualified name of the type declared.- Specified by:
getQualifiedNamein interfaceResolvedTypeDeclaration
-
solveMethod
@Deprecated public SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> parameterTypes, boolean staticOnly) Deprecated.- Specified by:
solveMethodin interfaceMethodResolutionCapability
-
toString
-
getUsage
-
equals
-
hashCode
-
solveMethodAsUsage
public Optional<MethodUsage> solveMethodAsUsage(String name, List<ResolvedType> parameterTypes, Context invokationContext, List<ResolvedType> typeParameterValues) Solves method usage with proper generic type inference, including support for varargs methods. This method first resolves the basic method signature, then performs generic type inference based on the actual parameter types provided at the call site.- Specified by:
solveMethodAsUsagein interfaceMethodUsageResolutionCapability- Parameters:
name- the method name to resolveparameterTypes- the actual parameter types at the call siteinvokationContext- the context where the method is invokedtypeParameterValues- explicit type parameter values (if any)- Returns:
- an Optional containing the resolved MethodUsage with inferred types, or empty if resolution fails
-
performTypeInference
private Optional<MethodUsage> performTypeInference(MethodUsage methodUsage, List<ResolvedType> parameterTypes) Performs generic type inference on a resolved method usage by analyzing the relationship between formal parameter types and actual parameter types provided at the call site. Handles both regular methods and varargs methods with appropriate constraint collection.- Parameters:
methodUsage- the initially resolved method usageparameterTypes- the actual parameter types from the call site- Returns:
- an Optional containing the method usage with inferred generic types, or empty if inference fails
-
collectTypeConstraints
private List<ResolvedType> collectTypeConstraints(MethodUsage methodUsage, List<ResolvedType> parameterTypes, InferenceContext inferenceContext) Collects type constraints by comparing formal parameter types with actual parameter types. Automatically detects whether the method is varargs and delegates to the appropriate constraint collection strategy. Also validates that parameter counts are compatible.- Parameters:
methodUsage- the method usage to analyzeparameterTypes- the actual parameter types from the call siteinferenceContext- the inference context for collecting type constraints- Returns:
- a list of type constraints that will be used for generic type resolution
- Throws:
IllegalArgumentException- if parameter counts are incompatible
-
validateParameterCount
private void validateParameterCount(boolean isVarArgs, int formalParamCount, int actualParamCount) Validates that the number of actual parameters is compatible with the method signature. For regular methods, counts must match exactly. For varargs methods, actual parameter count must be at least the number of required parameters (formal count - 1).- Parameters:
isVarArgs- whether the method is a varargs methodformalParamCount- the number of formal parameters in the method signatureactualParamCount- the number of actual parameters provided at the call site- Throws:
IllegalArgumentException- if parameter counts are incompatible
-
collectRegularConstraints
private List<ResolvedType> collectRegularConstraints(MethodUsage methodUsage, List<ResolvedType> parameterTypes, InferenceContext inferenceContext) Collects type constraints for regular (non-varargs) methods by creating pairs between each formal parameter type and its corresponding actual parameter type. This is a straightforward one-to-one mapping since parameter counts must match exactly.- Parameters:
methodUsage- the method usage to analyzeparameterTypes- the actual parameter types from the call siteinferenceContext- the inference context for collecting constraints- Returns:
- a list of type constraints, one for each parameter position
-
collectVarArgsConstraints
private List<ResolvedType> collectVarArgsConstraints(MethodUsage methodUsage, List<ResolvedType> parameterTypes, InferenceContext inferenceContext, int formalParamCount) Collects type constraints for varargs methods. This involves two phases: 1. Regular parameters: handled like non-varargs methods (one-to-one mapping) 2. Varargs parameter: handled specially based on how arguments are passed The varargs parameter can receive arguments in two ways: - Direct array passing: method(array) - constraint between array types - Individual elements: method(elem1, elem2, ...) - constraints between component type and each element- Parameters:
methodUsage- the varargs method usage to analyzeparameterTypes- the actual parameter types from the call siteinferenceContext- the inference context for collecting constraintsformalParamCount- the total number of formal parameters (including varargs)- Returns:
- a list of type constraints covering both regular and varargs parameters
-
processVarArgsParameter
private void processVarArgsParameter(ResolvedType varargsParamType, List<ResolvedType> parameterTypes, int regularParamCount, InferenceContext inferenceContext, List<ResolvedType> constraints) Processes the varargs parameter by determining how arguments are passed and creating appropriate type constraints. Handles two scenarios: 1. Direct array passing: When exactly one argument is passed to varargs and it's an array, creates a constraint between the formal array type and the actual array type. Example: method(String[] args) called as method(stringArray) 2. Individual element passing: When multiple arguments are passed to varargs, creates constraints between the array's component type and each individual argument. Example: method(String... args) called as method("a", "b", "c")- Parameters:
varargsParamType- the formal type of the varargs parameter (must be an array type)parameterTypes- all actual parameter types from the call siteregularParamCount- the number of regular (non-varargs) parametersinferenceContext- the inference context for collecting constraintsconstraints- the constraint list to add new constraints to- Throws:
IllegalStateException- if the varargs parameter is not an array type
-
isDirectArrayPassing
private boolean isDirectArrayPassing(List<ResolvedType> parameterTypes, int regularParamCount, int actualParamCount) Determines whether arguments are being passed directly as an array to the varargs parameter. This happens when there is exactly one argument for the varargs parameter and that argument is an array type. This is a special case that requires different constraint handling.- Parameters:
parameterTypes- all actual parameter types from the call siteregularParamCount- the number of regular (non-varargs) parametersactualParamCount- the total number of actual parameters- Returns:
- true if a single array is being passed directly to varargs, false otherwise
-
resolveInferredTypes
private Optional<MethodUsage> resolveInferredTypes(MethodUsage methodUsage, List<ResolvedType> constraints, InferenceContext inferenceContext) Applies the inferred generic types to the method usage by resolving all collected constraints and updating both parameter types and return type with their concrete resolved types. This is the final step that produces a fully resolved MethodUsage with no remaining generic placeholders.- Parameters:
methodUsage- the method usage to update with resolved typesconstraints- the collected type constraints from parameter analysisinferenceContext- the inference context containing all type relationships- Returns:
- an Optional containing the fully resolved MethodUsage
- Throws:
ConflictingGenericTypesException- if type constraints are contradictory
-
canBeAssignedTo
Description copied from interface:ResolvedReferenceTypeDeclarationCan we assign instances of the type defined by this declaration to variables having the type defined by the given type?- Specified by:
canBeAssignedToin interfaceResolvedReferenceTypeDeclaration
-
isAssignableBy
Description copied from interface:ResolvedReferenceTypeDeclarationCan we assign instances of the given type to variables having the type defined by this declaration?- Specified by:
isAssignableByin interfaceResolvedReferenceTypeDeclaration
-
isTypeParameter
public boolean isTypeParameter()Description copied from interface:ResolvedTypeDeclarationIs this the declaration of a type parameter?- Specified by:
isTypeParameterin interfaceResolvedTypeDeclaration
-
getField
Description copied from interface:ResolvedReferenceTypeDeclarationNote that the type of the field should be expressed using the type variables of this particular type. Consider for example:class Foo
{ E field; } class Bar extends Foo
{ } When calling getField("field") on Foo I should get a FieldDeclaration with type E, while calling it on Bar I should get a FieldDeclaration with type String.
- Specified by:
getFieldin interfaceResolvedReferenceTypeDeclaration
-
getAllFields
Description copied from interface:ResolvedReferenceTypeDeclarationReturn a list of all fields, either declared in this declaration or inherited.- Specified by:
getAllFieldsin interfaceResolvedReferenceTypeDeclaration
-
solveSymbol
public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) - Specified by:
solveSymbolin interfaceSymbolResolutionCapability- Parameters:
name- Field / symbol name.typeSolver- Symbol solver to resolve type usage.- Returns:
- Symbol reference of the resolved value.
-
getAncestors
Description copied from interface:ResolvedReferenceTypeDeclarationResolves the types of all direct ancestors (i.e., the directly extended class and the directly implemented interfaces) and returns the list of ancestors as a list of resolved reference types.If
acceptIncompleteListisfalse, then anUnsolvedSymbolExceptionis thrown if any ancestor cannot be resolved. Otherwise, a list of only the resolvable direct ancestors is returned.- Specified by:
getAncestorsin interfaceResolvedReferenceTypeDeclaration- Parameters:
acceptIncompleteList- When set tofalse, this method throws anUnsolvedSymbolExceptionif one or more ancestor could not be resolved. When set totrue, this method does not throw anUnsolvedSymbolException, but the list of returned ancestors may be incomplete in case one or more ancestor could not be resolved.- Returns:
- The list of resolved ancestors.
-
getDeclaredMethods
Description copied from interface:ResolvedReferenceTypeDeclarationReturn a list of all the methods declared in this type declaration.- Specified by:
getDeclaredMethodsin interfaceResolvedReferenceTypeDeclaration
-
hasField
Description copied from interface:ResolvedReferenceTypeDeclarationHas this type a field with the given name?- Specified by:
hasFieldin interfaceResolvedReferenceTypeDeclaration
-
getName
Description copied from interface:ResolvedDeclarationShould return the name or return null if the name is not available.- Specified by:
getNamein interfaceResolvedDeclaration
-
isInterface
public boolean isInterface()Description copied from interface:ResolvedTypeDeclarationIs this the declaration of an interface?- Specified by:
isInterfacein interfaceResolvedInterfaceDeclaration- Specified by:
isInterfacein interfaceResolvedTypeDeclaration
-
getInterfacesExtended
Description copied from interface:ResolvedInterfaceDeclarationReturn the list of interfaces extended directly by this one.- Specified by:
getInterfacesExtendedin interfaceResolvedInterfaceDeclaration
-
containerType
Description copied from interface:ResolvedTypeDeclarationGet the ReferenceTypeDeclaration enclosing this declaration.- Specified by:
containerTypein interfaceResolvedTypeDeclaration
-
internalTypes
Description copied from interface:ResolvedTypeDeclarationGet the list of types defined inside the current type.- Specified by:
internalTypesin interfaceResolvedTypeDeclaration
-
asInterface
Description copied from interface:ResolvedTypeDeclarationReturn this as a InterfaceDeclaration or throw UnsupportedOperationException.- Specified by:
asInterfacein interfaceResolvedTypeDeclaration
-
hasDirectlyAnnotation
Description copied from interface:ResolvedReferenceTypeDeclarationHas the type at least one annotation declared having the specified qualified name?- Specified by:
hasDirectlyAnnotationin interfaceResolvedReferenceTypeDeclaration
-
getTypeParameters
Description copied from interface:ResolvedTypeParametrizableThe list of type parameters defined on this element.- Specified by:
getTypeParametersin interfaceResolvedTypeParametrizable
-
accessSpecifier
Description copied from interface:HasAccessSpecifierThe access specifier of this element.- Specified by:
accessSpecifierin interfaceHasAccessSpecifier
-
getConstructors
- Specified by:
getConstructorsin interfaceResolvedReferenceTypeDeclaration
-