Class ReflectionInterfaceDeclaration

    • Constructor Detail

      • ReflectionInterfaceDeclaration

        public ReflectionInterfaceDeclaration​(java.lang.Class<?> clazz,
                                              TypeSolver typeSolver)
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • solveMethodAsUsage

        public java.util.Optional<MethodUsage> solveMethodAsUsage​(java.lang.String name,
                                                                  java.util.List<ResolvedType> parameterTypes,
                                                                  Context invokationContext,
                                                                  java.util.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 java.util.Optional<MethodUsage> performTypeInference​(MethodUsage methodUsage,
                                                                     java.util.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 java.util.List<ResolvedType> collectTypeConstraints​(MethodUsage methodUsage,
                                                                    java.util.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:
        java.lang.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:
        java.lang.IllegalArgumentException - if parameter counts are incompatible
      • collectRegularConstraints

        private java.util.List<ResolvedType> collectRegularConstraints​(MethodUsage methodUsage,
                                                                       java.util.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 java.util.List<ResolvedType> collectVarArgsConstraints​(MethodUsage methodUsage,
                                                                       java.util.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,
                                             java.util.List<ResolvedType> parameterTypes,
                                             int regularParamCount,
                                             InferenceContext inferenceContext,
                                             java.util.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:
        java.lang.IllegalStateException - if the varargs parameter is not an array type
      • isDirectArrayPassing

        private boolean isDirectArrayPassing​(java.util.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 java.util.Optional<MethodUsage> resolveInferredTypes​(MethodUsage methodUsage,
                                                                     java.util.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
      • getField

        public ResolvedFieldDeclaration getField​(java.lang.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
      • getAncestors

        public java.util.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.
      • getName

        public java.lang.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