use of com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl in project javaparser by javaparser.
the class ReflectionMethodResolutionLogic method solveMethodAsUsage.
static Optional<MethodUsage> solveMethodAsUsage(String name, List<ResolvedType> argumentsTypes, TypeSolver typeSolver, Context invokationContext, List<ResolvedType> typeParameterValues, ResolvedReferenceTypeDeclaration scopeType, Class clazz) {
if (typeParameterValues.size() != scopeType.getTypeParameters().size()) {
// if it is zero we are going to ignore them
if (!scopeType.getTypeParameters().isEmpty()) {
// Parameters not specified, so default to Object
typeParameterValues = new ArrayList<>();
for (int i = 0; i < scopeType.getTypeParameters().size(); i++) {
typeParameterValues.add(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver));
}
}
}
List<MethodUsage> methods = new ArrayList<>();
for (Method method : clazz.getMethods()) {
if (method.getName().equals(name) && !method.isBridge() && !method.isSynthetic()) {
ResolvedMethodDeclaration methodDeclaration = new ReflectionMethodDeclaration(method, typeSolver);
MethodUsage methodUsage = replaceParams(typeParameterValues, scopeType, methodDeclaration);
methods.add(methodUsage);
}
}
for (ResolvedReferenceType ancestor : scopeType.getAncestors()) {
SymbolReference<ResolvedMethodDeclaration> ref = MethodResolutionLogic.solveMethodInType(ancestor.getTypeDeclaration(), name, argumentsTypes, typeSolver);
if (ref.isSolved()) {
ResolvedMethodDeclaration correspondingDeclaration = ref.getCorrespondingDeclaration();
MethodUsage methodUsage = replaceParams(typeParameterValues, ancestor.getTypeDeclaration(), correspondingDeclaration);
methods.add(methodUsage);
}
}
if (scopeType.getAncestors().isEmpty()) {
ReferenceTypeImpl objectClass = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver);
SymbolReference<ResolvedMethodDeclaration> ref = MethodResolutionLogic.solveMethodInType(objectClass.getTypeDeclaration(), name, argumentsTypes, typeSolver);
if (ref.isSolved()) {
MethodUsage usage = replaceParams(typeParameterValues, objectClass.getTypeDeclaration(), ref.getCorrespondingDeclaration());
methods.add(usage);
}
}
final List<ResolvedType> finalTypeParameterValues = typeParameterValues;
argumentsTypes = argumentsTypes.stream().map((pt) -> {
int i = 0;
for (ResolvedTypeParameterDeclaration tp : scopeType.getTypeParameters()) {
pt = pt.replaceTypeVariables(tp, finalTypeParameterValues.get(i));
i++;
}
return pt;
}).collect(Collectors.toList());
return MethodResolutionLogic.findMostApplicableUsage(methods, name, argumentsTypes, typeSolver);
}
use of com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl in project javaparser by javaparser.
the class JavassistInterfaceDeclaration method getAncestors.
@Override
public List<ResolvedReferenceType> getAncestors() {
List<ResolvedReferenceType> ancestors = new ArrayList<>();
try {
for (CtClass interfaze : ctClass.getInterfaces()) {
ResolvedReferenceType superInterfaze = JavassistFactory.typeUsageFor(interfaze, typeSolver).asReferenceType();
ancestors.add(superInterfaze);
}
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
ancestors = ancestors.stream().filter(a -> a.getQualifiedName() != Object.class.getCanonicalName()).collect(Collectors.toList());
ancestors.add(new ReferenceTypeImpl(typeSolver.solveType(Object.class.getCanonicalName()), typeSolver));
return ancestors;
}
use of com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl in project javaparser by javaparser.
the class ReflectionClassAdapter method getAncestors.
public List<ResolvedReferenceType> getAncestors() {
List<ResolvedReferenceType> ancestors = new LinkedList<>();
if (getSuperClass() != null) {
ReferenceTypeImpl superClass = getSuperClass();
ancestors.add(superClass);
} else {
ReferenceTypeImpl object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver);
ancestors.add(object);
}
ancestors.addAll(getInterfaces());
for (int i = 0; i < ancestors.size(); i++) {
ResolvedReferenceType ancestor = ancestors.get(i);
if (ancestor.hasName() && ancestor.getQualifiedName().equals(Object.class.getCanonicalName())) {
ancestors.remove(i);
i--;
}
}
return ancestors;
}
use of com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl in project javaparser by javaparser.
the class ReflectionClassAdapter method getSuperClass.
public ReferenceTypeImpl getSuperClass() {
if (clazz.getGenericSuperclass() == null) {
return null;
}
java.lang.reflect.Type superType = clazz.getGenericSuperclass();
if (superType instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) superType;
List<ResolvedType> typeParameters = Arrays.stream(parameterizedType.getActualTypeArguments()).map((t) -> ReflectionFactory.typeUsageFor(t, typeSolver)).collect(Collectors.toList());
return new ReferenceTypeImpl(new ReflectionClassDeclaration(clazz.getSuperclass(), typeSolver), typeParameters, typeSolver);
}
return new ReferenceTypeImpl(new ReflectionClassDeclaration(clazz.getSuperclass(), typeSolver), typeSolver);
}
use of com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl in project javaparser by javaparser.
the class MyObjectProvider method byName.
@Override
public ResolvedReferenceType byName(String qualifiedName) {
TypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedReferenceTypeDeclaration typeDeclaration = typeSolver.solveType(qualifiedName);
if (!typeDeclaration.getTypeParameters().isEmpty()) {
throw new UnsupportedOperationException();
}
return new ReferenceTypeImpl(typeDeclaration, typeSolver);
}
Aggregations