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

  • Field Details

  • Constructor Details

    • ReflectionInterfaceDeclaration

      public ReflectionInterfaceDeclaration(Class<?> clazz, TypeSolver typeSolver)
      Constructor
  • Method Details

    • isAssignableBy

      public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other)
      Public methods
      Specified by:
      isAssignableBy in interface ResolvedReferenceTypeDeclaration
    • getPackageName

      public String getPackageName()
      Description copied from interface: ResolvedTypeDeclaration
      The package name of the type.
      Specified by:
      getPackageName in interface ResolvedTypeDeclaration
    • getClassName

      public String getClassName()
      Description copied from interface: ResolvedTypeDeclaration
      The class(es) wrapping this type.
      Specified by:
      getClassName in interface ResolvedTypeDeclaration
    • getQualifiedName

      public String getQualifiedName()
      Description copied from interface: ResolvedTypeDeclaration
      The fully qualified name of the type declared.
      Specified by:
      getQualifiedName in interface ResolvedTypeDeclaration
    • solveMethod

      @Deprecated public SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> parameterTypes, boolean staticOnly)
      Deprecated.
      Specified by:
      solveMethod in interface MethodResolutionCapability
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getUsage

      public ResolvedType getUsage(Node node)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • 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:
      solveMethodAsUsage in interface MethodUsageResolutionCapability
      Parameters:
      name - the method name to resolve
      parameterTypes - the actual parameter types at the call site
      invokationContext - the context where the method is invoked
      typeParameterValues - 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 usage
      parameterTypes - 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 analyze
      parameterTypes - the actual parameter types from the call site
      inferenceContext - 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 method
      formalParamCount - the number of formal parameters in the method signature
      actualParamCount - 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 analyze
      parameterTypes - the actual parameter types from the call site
      inferenceContext - 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 analyze
      parameterTypes - the actual parameter types from the call site
      inferenceContext - the inference context for collecting constraints
      formalParamCount - 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 site
      regularParamCount - the number of regular (non-varargs) parameters
      inferenceContext - the inference context for collecting constraints
      constraints - 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 site
      regularParamCount - the number of regular (non-varargs) parameters
      actualParamCount - 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 types
      constraints - the collected type constraints from parameter analysis
      inferenceContext - the inference context containing all type relationships
      Returns:
      an Optional containing the fully resolved MethodUsage
      Throws:
      ConflictingGenericTypesException - if type constraints are contradictory
    • canBeAssignedTo

      public boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other)
      Description copied from interface: ResolvedReferenceTypeDeclaration
      Can we assign instances of the type defined by this declaration to variables having the type defined by the given type?
      Specified by:
      canBeAssignedTo in interface ResolvedReferenceTypeDeclaration
    • isAssignableBy

      public boolean isAssignableBy(ResolvedType type)
      Description copied from interface: ResolvedReferenceTypeDeclaration
      Can we assign instances of the given type to variables having the type defined by this declaration?
      Specified by:
      isAssignableBy in interface ResolvedReferenceTypeDeclaration
    • isTypeParameter

      public boolean isTypeParameter()
      Description copied from interface: ResolvedTypeDeclaration
      Is this the declaration of a type parameter?
      Specified by:
      isTypeParameter in interface ResolvedTypeDeclaration
    • getField

      public ResolvedFieldDeclaration getField(String name)
      Description copied from interface: ResolvedReferenceTypeDeclaration
      Note 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:
      getField in interface ResolvedReferenceTypeDeclaration
    • getAllFields

      public List<ResolvedFieldDeclaration> getAllFields()
      Description copied from interface: ResolvedReferenceTypeDeclaration
      Return a list of all fields, either declared in this declaration or inherited.
      Specified by:
      getAllFields in interface ResolvedReferenceTypeDeclaration
    • solveSymbol

      public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver)
      Specified by:
      solveSymbol in interface SymbolResolutionCapability
      Parameters:
      name - Field / symbol name.
      typeSolver - Symbol solver to resolve type usage.
      Returns:
      Symbol reference of the resolved value.
    • getAncestors

      public List<ResolvedReferenceType> getAncestors(boolean acceptIncompleteList)
      Description copied from interface: ResolvedReferenceTypeDeclaration
      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.

      If acceptIncompleteList is false, then an UnsolvedSymbolException is thrown if any ancestor cannot be resolved. Otherwise, a list of only the resolvable direct ancestors is returned.

      Specified by:
      getAncestors in interface ResolvedReferenceTypeDeclaration
      Parameters:
      acceptIncompleteList - When set to false, this method throws an UnsolvedSymbolException if one or more ancestor could not be resolved. When set to true, this method does not throw an UnsolvedSymbolException, 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

      public Set<ResolvedMethodDeclaration> getDeclaredMethods()
      Description copied from interface: ResolvedReferenceTypeDeclaration
      Return a list of all the methods declared in this type declaration.
      Specified by:
      getDeclaredMethods in interface ResolvedReferenceTypeDeclaration
    • hasField

      public boolean hasField(String name)
      Description copied from interface: ResolvedReferenceTypeDeclaration
      Has this type a field with the given name?
      Specified by:
      hasField in interface ResolvedReferenceTypeDeclaration
    • getName

      public String getName()
      Description copied from interface: ResolvedDeclaration
      Should return the name or return null if the name is not available.
      Specified by:
      getName in interface ResolvedDeclaration
    • isInterface

      public boolean isInterface()
      Description copied from interface: ResolvedTypeDeclaration
      Is this the declaration of an interface?
      Specified by:
      isInterface in interface ResolvedInterfaceDeclaration
      Specified by:
      isInterface in interface ResolvedTypeDeclaration
    • getInterfacesExtended

      public List<ResolvedReferenceType> getInterfacesExtended()
      Description copied from interface: ResolvedInterfaceDeclaration
      Return the list of interfaces extended directly by this one.
      Specified by:
      getInterfacesExtended in interface ResolvedInterfaceDeclaration
    • containerType

      public Optional<ResolvedReferenceTypeDeclaration> containerType()
      Description copied from interface: ResolvedTypeDeclaration
      Get the ReferenceTypeDeclaration enclosing this declaration.
      Specified by:
      containerType in interface ResolvedTypeDeclaration
    • internalTypes

      public Set<ResolvedReferenceTypeDeclaration> internalTypes()
      Description copied from interface: ResolvedTypeDeclaration
      Get the list of types defined inside the current type.
      Specified by:
      internalTypes in interface ResolvedTypeDeclaration
    • asInterface

      public ResolvedInterfaceDeclaration asInterface()
      Description copied from interface: ResolvedTypeDeclaration
      Return this as a InterfaceDeclaration or throw UnsupportedOperationException.
      Specified by:
      asInterface in interface ResolvedTypeDeclaration
    • hasDirectlyAnnotation

      public boolean hasDirectlyAnnotation(String canonicalName)
      Description copied from interface: ResolvedReferenceTypeDeclaration
      Has the type at least one annotation declared having the specified qualified name?
      Specified by:
      hasDirectlyAnnotation in interface ResolvedReferenceTypeDeclaration
    • getTypeParameters

      public List<ResolvedTypeParameterDeclaration> getTypeParameters()
      Description copied from interface: ResolvedTypeParametrizable
      The list of type parameters defined on this element.
      Specified by:
      getTypeParameters in interface ResolvedTypeParametrizable
    • accessSpecifier

      public AccessSpecifier accessSpecifier()
      Description copied from interface: HasAccessSpecifier
      The access specifier of this element.
      Specified by:
      accessSpecifier in interface HasAccessSpecifier
    • getConstructors

      public List<ResolvedConstructorDeclaration> getConstructors()
      Specified by:
      getConstructors in interface ResolvedReferenceTypeDeclaration