use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.
the class JavaParserClassDeclaration method getAncestors.
@Override
public List<ResolvedReferenceType> getAncestors() {
List<ResolvedReferenceType> ancestors = new ArrayList<>();
// We want to avoid infinite recursion in case of Object having Object as ancestor
if (!(Object.class.getCanonicalName().equals(getQualifiedName()))) {
ResolvedReferenceType superclass = getSuperClass();
if (superclass != null) {
ancestors.add(superclass);
}
if (wrappedNode.getImplementedTypes() != null) {
for (ClassOrInterfaceType implemented : wrappedNode.getImplementedTypes()) {
ResolvedReferenceType ancestor = toReferenceType(implemented);
ancestors.add(ancestor);
}
}
}
return ancestors;
}
use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.
the class JavaParserEnumDeclaration method getAncestors.
@Override
public List<ResolvedReferenceType> getAncestors() {
List<ResolvedReferenceType> ancestors = new ArrayList<>();
ResolvedReferenceType enumClass = ReflectionFactory.typeUsageFor(Enum.class, typeSolver).asReferenceType();
ResolvedTypeParameterDeclaration eTypeParameter = enumClass.getTypeDeclaration().getTypeParameters().get(0);
enumClass = enumClass.deriveTypeParameters(new ResolvedTypeParametersMap.Builder().setValue(eTypeParameter, new ReferenceTypeImpl(this, typeSolver)).build());
ancestors.add(enumClass);
if (wrappedNode.getImplementedTypes() != null) {
for (ClassOrInterfaceType implementedType : wrappedNode.getImplementedTypes()) {
SymbolReference<ResolvedTypeDeclaration> implementedDeclRef = new SymbolSolver(typeSolver).solveTypeInType(this, implementedType.getName().getId());
if (!implementedDeclRef.isSolved()) {
throw new UnsolvedSymbolException(implementedType.getName().getId());
}
ancestors.add(new ReferenceTypeImpl((ResolvedReferenceTypeDeclaration) implementedDeclRef.getCorrespondingDeclaration(), typeSolver));
}
}
return ancestors;
}
use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.
the class JavaParserTypeAdapter method isAssignableBy.
public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) {
List<ResolvedReferenceType> ancestorsOfOther = other.getAllAncestors();
ancestorsOfOther.add(new ReferenceTypeImpl(other, typeSolver));
for (ResolvedReferenceType ancestorOfOther : ancestorsOfOther) {
if (ancestorOfOther.getQualifiedName().equals(this.getQualifiedName())) {
return true;
}
}
return false;
}
use of com.github.javaparser.resolution.types.ResolvedReferenceType 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.resolution.types.ResolvedReferenceType in project javaparser by javaparser.
the class BoundSet method findPairsOfCommonAncestors.
private List<Pair<ResolvedReferenceType, ResolvedReferenceType>> findPairsOfCommonAncestors(ResolvedReferenceType r1, ResolvedReferenceType r2) {
List<ResolvedReferenceType> set1 = new LinkedList<>();
set1.add(r1);
set1.addAll(r1.getAllAncestors());
List<ResolvedReferenceType> set2 = new LinkedList<>();
set2.add(r2);
set2.addAll(r2.getAllAncestors());
List<Pair<ResolvedReferenceType, ResolvedReferenceType>> pairs = new LinkedList<>();
for (ResolvedReferenceType rtFrom1 : set1) {
for (ResolvedReferenceType rtFrom2 : set2) {
if (rtFrom1.getTypeDeclaration().equals(rtFrom2.getTypeDeclaration())) {
pairs.add(new Pair<>(rtFrom1, rtFrom2));
}
}
}
return pairs;
}
Aggregations