use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class ReflectionClassDeclaration method solveMethod.
@Deprecated
public SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> argumentsTypes, boolean staticOnly) {
List<ResolvedMethodDeclaration> methods = new ArrayList<>();
Predicate<Method> staticFilter = m -> !staticOnly || (staticOnly && Modifier.isStatic(m.getModifiers()));
for (Method method : Arrays.stream(clazz.getDeclaredMethods()).filter((m) -> m.getName().equals(name)).filter(staticFilter).sorted(new MethodComparator()).collect(Collectors.toList())) {
if (method.isBridge() || method.isSynthetic())
continue;
ResolvedMethodDeclaration methodDeclaration = new ReflectionMethodDeclaration(method, typeSolver);
methods.add(methodDeclaration);
}
if (getSuperClass() != null) {
ResolvedClassDeclaration superClass = (ResolvedClassDeclaration) getSuperClass().getTypeDeclaration();
SymbolReference<ResolvedMethodDeclaration> ref = MethodResolutionLogic.solveMethodInType(superClass, name, argumentsTypes, staticOnly, typeSolver);
if (ref.isSolved()) {
methods.add(ref.getCorrespondingDeclaration());
}
}
for (ResolvedReferenceType interfaceDeclaration : getInterfaces()) {
SymbolReference<ResolvedMethodDeclaration> ref = MethodResolutionLogic.solveMethodInType(interfaceDeclaration.getTypeDeclaration(), name, argumentsTypes, staticOnly, typeSolver);
if (ref.isSolved()) {
methods.add(ref.getCorrespondingDeclaration());
}
}
return MethodResolutionLogic.findMostApplicable(methods, name, argumentsTypes, typeSolver);
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class ReflectionClassDeclaration method solveMethodAsUsage.
public Optional<MethodUsage> solveMethodAsUsage(String name, List<ResolvedType> argumentsTypes, TypeSolver typeSolver, Context invokationContext, List<ResolvedType> typeParameterValues) {
List<MethodUsage> methods = new ArrayList<>();
for (Method method : Arrays.stream(clazz.getDeclaredMethods()).filter((m) -> m.getName().equals(name)).sorted(new MethodComparator()).collect(Collectors.toList())) {
if (method.isBridge() || method.isSynthetic())
continue;
ResolvedMethodDeclaration methodDeclaration = new ReflectionMethodDeclaration(method, typeSolver);
MethodUsage methodUsage = new MethodUsage(methodDeclaration);
for (int i = 0; i < getTypeParameters().size() && i < typeParameterValues.size(); i++) {
ResolvedTypeParameterDeclaration tpToReplace = getTypeParameters().get(i);
ResolvedType newValue = typeParameterValues.get(i);
methodUsage = methodUsage.replaceTypeParameter(tpToReplace, newValue);
}
methods.add(methodUsage);
}
if (getSuperClass() != null) {
ResolvedClassDeclaration superClass = (ResolvedClassDeclaration) getSuperClass().getTypeDeclaration();
Optional<MethodUsage> ref = ContextHelper.solveMethodAsUsage(superClass, name, argumentsTypes, typeSolver, invokationContext, typeParameterValues);
if (ref.isPresent()) {
methods.add(ref.get());
}
}
for (ResolvedReferenceType interfaceDeclaration : getInterfaces()) {
Optional<MethodUsage> ref = ContextHelper.solveMethodAsUsage(interfaceDeclaration.getTypeDeclaration(), name, argumentsTypes, typeSolver, invokationContext, typeParameterValues);
if (ref.isPresent()) {
methods.add(ref.get());
}
}
Optional<MethodUsage> ref = MethodResolutionLogic.findMostApplicableUsage(methods, name, argumentsTypes, typeSolver);
return ref;
}
use of com.github.javaparser.resolution.types.ResolvedType 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.resolution.types.ResolvedType in project javaparser by javaparser.
the class CompilationUnitContext method solveMethod.
@Override
public SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> argumentsTypes, boolean staticOnly, TypeSolver typeSolver) {
for (ImportDeclaration importDecl : wrappedNode.getImports()) {
if (importDecl.isStatic()) {
if (importDecl.isAsterisk()) {
String importString = importDecl.getNameAsString();
if (this.wrappedNode.getPackageDeclaration().isPresent() && this.wrappedNode.getPackageDeclaration().get().getName().getIdentifier().equals(packageName(importString)) && this.wrappedNode.getTypes().stream().anyMatch(it -> it.getName().getIdentifier().equals(toSimpleName(importString)))) {
// a lower level so this will fail
return SymbolReference.unsolved(ResolvedMethodDeclaration.class);
}
ResolvedTypeDeclaration ref = typeSolver.solveType(importString);
SymbolReference<ResolvedMethodDeclaration> method = MethodResolutionLogic.solveMethodInType(ref, name, argumentsTypes, true, typeSolver);
if (method.isSolved()) {
return method;
}
} else {
String qName = importDecl.getNameAsString();
if (qName.equals(name) || qName.endsWith("." + name)) {
String typeName = getType(qName);
ResolvedTypeDeclaration ref = typeSolver.solveType(typeName);
SymbolReference<ResolvedMethodDeclaration> method = MethodResolutionLogic.solveMethodInType(ref, name, argumentsTypes, true, typeSolver);
if (method.isSolved()) {
return method;
}
}
}
}
}
return SymbolReference.unsolved(ResolvedMethodDeclaration.class);
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class ReflectionClassAdapter method getInterfaces.
public List<ResolvedReferenceType> getInterfaces() {
List<ResolvedReferenceType> interfaces = new ArrayList<>();
for (java.lang.reflect.Type superInterface : clazz.getGenericInterfaces()) {
if (superInterface instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) superInterface;
List<ResolvedType> typeParameters = Arrays.stream(parameterizedType.getActualTypeArguments()).map((t) -> ReflectionFactory.typeUsageFor(t, typeSolver)).collect(Collectors.toList());
interfaces.add(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration((Class<?>) ((ParameterizedType) superInterface).getRawType(), typeSolver), typeParameters, typeSolver));
} else {
interfaces.add(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration((Class<?>) superInterface, typeSolver), typeSolver));
}
}
return interfaces;
}
Aggregations