Search in sources :

Example 1 with ConfilictingGenericTypesException

use of com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException in project javaparser by javaparser.

the class ReflectionInterfaceDeclaration method solveMethodAsUsage.

public Optional<MethodUsage> solveMethodAsUsage(String name, List<ResolvedType> parameterTypes, TypeSolver typeSolver, Context invokationContext, List<ResolvedType> typeParameterValues) {
    Optional<MethodUsage> res = ReflectionMethodResolutionLogic.solveMethodAsUsage(name, parameterTypes, typeSolver, invokationContext, typeParameterValues, this, clazz);
    if (res.isPresent()) {
        // We have to replace method type typeParametersValues here
        InferenceContext inferenceContext = new InferenceContext(MyObjectProvider.INSTANCE);
        MethodUsage methodUsage = res.get();
        int i = 0;
        List<ResolvedType> parameters = new LinkedList<>();
        for (ResolvedType actualType : parameterTypes) {
            ResolvedType formalType = methodUsage.getParamType(i);
            // We need to replace the class type typeParametersValues (while we derive the method ones)
            parameters.add(inferenceContext.addPair(formalType, actualType));
            i++;
        }
        try {
            ResolvedType returnType = inferenceContext.addSingle(methodUsage.returnType());
            for (int j = 0; j < parameters.size(); j++) {
                methodUsage = methodUsage.replaceParamType(j, inferenceContext.resolve(parameters.get(j)));
            }
            methodUsage = methodUsage.replaceReturnType(inferenceContext.resolve(returnType));
            return Optional.of(methodUsage);
        } catch (ConfilictingGenericTypesException e) {
            return Optional.empty();
        }
    } else {
        return res;
    }
}
Also used : InferenceContext(com.github.javaparser.symbolsolver.logic.InferenceContext) ConfilictingGenericTypesException(com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException) MethodUsage(com.github.javaparser.resolution.MethodUsage) ResolvedType(com.github.javaparser.resolution.types.ResolvedType)

Example 2 with ConfilictingGenericTypesException

use of com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException in project javaparser by javaparser.

the class ReflectionEnumDeclaration method solveMethodAsUsage.

public Optional<MethodUsage> solveMethodAsUsage(String name, List<ResolvedType> parameterTypes, TypeSolver typeSolver, Context invokationContext, List<ResolvedType> typeParameterValues) {
    Optional<MethodUsage> res = ReflectionMethodResolutionLogic.solveMethodAsUsage(name, parameterTypes, typeSolver, invokationContext, typeParameterValues, this, clazz);
    if (res.isPresent()) {
        // We have to replace method type typeParametersValues here
        InferenceContext inferenceContext = new InferenceContext(MyObjectProvider.INSTANCE);
        MethodUsage methodUsage = res.get();
        int i = 0;
        List<ResolvedType> parameters = new LinkedList<>();
        for (ResolvedType actualType : parameterTypes) {
            ResolvedType formalType = methodUsage.getParamType(i);
            // We need to replace the class type typeParametersValues (while we derive the method ones)
            parameters.add(inferenceContext.addPair(formalType, actualType));
            i++;
        }
        try {
            ResolvedType returnType = inferenceContext.addSingle(methodUsage.returnType());
            for (int j = 0; j < parameters.size(); j++) {
                methodUsage = methodUsage.replaceParamType(j, inferenceContext.resolve(parameters.get(j)));
            }
            methodUsage = methodUsage.replaceReturnType(inferenceContext.resolve(returnType));
            return Optional.of(methodUsage);
        } catch (ConfilictingGenericTypesException e) {
            return Optional.empty();
        }
    } else {
        return res;
    }
}
Also used : InferenceContext(com.github.javaparser.symbolsolver.logic.InferenceContext) ConfilictingGenericTypesException(com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException) MethodUsage(com.github.javaparser.resolution.MethodUsage) ResolvedType(com.github.javaparser.resolution.types.ResolvedType)

Aggregations

MethodUsage (com.github.javaparser.resolution.MethodUsage)2 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)2 ConfilictingGenericTypesException (com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException)2 InferenceContext (com.github.javaparser.symbolsolver.logic.InferenceContext)2