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;
}
}
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;
}
}
Aggregations