@Override public Set<ResolvedFieldDeclaration> getDeclaredFields() { return new HashSet<>(getTypeDeclaration().getDeclaredFields()); } }
@Override public Set<MethodUsage> getDeclaredMethods() { // TODO replace variables Set<MethodUsage> methods = new HashSet<>(); for (ResolvedMethodDeclaration methodDeclaration : getTypeDeclaration().getDeclaredMethods()) { MethodUsage methodUsage = new MethodUsage(methodDeclaration); methods.add(methodUsage); } return methods; }
public boolean hasField(String name) { for (Field field : clazz.getDeclaredFields()) { if (field.getName().equals(name)) { return true; } } ReferenceTypeImpl superclass = getSuperClass(); if (superclass == null) { return false; } else { return superclass.getTypeDeclaration().hasField(name); } }
@Override public Set<MethodUsage> getDeclaredMethods() { // TODO replace variables Set<MethodUsage> methods = new HashSet<>(); for (ResolvedMethodDeclaration methodDeclaration : getTypeDeclaration().getDeclaredMethods()) { MethodUsage methodUsage = new MethodUsage(methodDeclaration); methods.add(methodUsage); } return methods; }
@Override public Set<MethodUsage> getDeclaredMethods() { // TODO replace variables Set<MethodUsage> methods = new HashSet<>(); for (ResolvedMethodDeclaration methodDeclaration : getTypeDeclaration().getDeclaredMethods()) { MethodUsage methodUsage = new MethodUsage(methodDeclaration); methods.add(methodUsage); } return methods; }
public boolean hasField(String name) { for (Field field : clazz.getDeclaredFields()) { if (field.getName().equals(name)) { return true; } } ReferenceTypeImpl superclass = getSuperClass(); if (superclass == null) { return false; } else { return superclass.getTypeDeclaration().hasField(name); } }
public List<ResolvedReferenceType> getDirectAncestors() { // We need to go through the inheritance line and propagate the type parametes List<ResolvedReferenceType> ancestors = typeDeclaration.getAncestors(); ancestors = ancestors.stream() .map(a -> typeParametersMap().replaceAll(a).asReferenceType()) .collect(Collectors.toList()); // Avoid repetitions of Object ancestors.removeIf(a -> a.getQualifiedName().equals(Object.class.getCanonicalName())); boolean isClassWithSuperClassOrObject = this.getTypeDeclaration().isClass() && (this.getTypeDeclaration().asClass().getSuperClass() == null || !this.getTypeDeclaration().asClass().getSuperClass().getQualifiedName().equals(Object.class.getCanonicalName())); if (!isClassWithSuperClassOrObject) { ResolvedReferenceTypeDeclaration objectType = typeSolver.solveType(Object.class.getCanonicalName()); ResolvedReferenceType objectRef = create(objectType); ancestors.add(objectRef); } return ancestors; }
public Optional<MethodUsage> solveMethodAsUsage(String name, List<ResolvedType> argumentsTypes, 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, invokationContext, typeParameterValues); if (ref.isPresent()) { methods.add(ref.get()); } } for (ResolvedReferenceType interfaceDeclaration : getInterfaces()) { Optional<MethodUsage> ref = ContextHelper.solveMethodAsUsage(interfaceDeclaration.getTypeDeclaration(), name, argumentsTypes, invokationContext, typeParameterValues); if (ref.isPresent()) { methods.add(ref.get()); } } Optional<MethodUsage> ref = MethodResolutionLogic.findMostApplicableUsage(methods, name, argumentsTypes, typeSolver); return ref; }
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; }
@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); }
@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); }
static SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> parameterTypes, boolean staticOnly, TypeSolver typeSolver, ResolvedReferenceTypeDeclaration scopeType, Class clazz){ List<ResolvedMethodDeclaration> methods = new ArrayList<>(); Predicate<Method> staticOnlyCheck = m -> !staticOnly || (staticOnly && Modifier.isStatic(m.getModifiers())); for (Method method : clazz.getMethods()) { if (method.isBridge() || method.isSynthetic() || !method.getName().equals(name)|| !staticOnlyCheck.test(method)) continue; ResolvedMethodDeclaration methodDeclaration = new ReflectionMethodDeclaration(method, typeSolver); methods.add(methodDeclaration); } for (ResolvedReferenceType ancestor : scopeType.getAncestors()) { SymbolReference<ResolvedMethodDeclaration> ref = MethodResolutionLogic.solveMethodInType(ancestor.getTypeDeclaration(), name, parameterTypes, staticOnly, typeSolver); if (ref.isSolved()) { methods.add(ref.getCorrespondingDeclaration()); } } if (scopeType.getAncestors().isEmpty()){ ReferenceTypeImpl objectClass = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); SymbolReference<ResolvedMethodDeclaration> ref = MethodResolutionLogic.solveMethodInType(objectClass.getTypeDeclaration(), name, parameterTypes, staticOnly, typeSolver); if (ref.isSolved()) { methods.add(ref.getCorrespondingDeclaration()); } } return MethodResolutionLogic.findMostApplicable(methods, name, parameterTypes, typeSolver); }
static SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> parameterTypes, boolean staticOnly, TypeSolver typeSolver, ResolvedReferenceTypeDeclaration scopeType, Class clazz){ List<ResolvedMethodDeclaration> methods = new ArrayList<>(); Predicate<Method> staticOnlyCheck = m -> !staticOnly || (staticOnly && Modifier.isStatic(m.getModifiers())); for (Method method : clazz.getMethods()) { if (method.isBridge() || method.isSynthetic() || !method.getName().equals(name)|| !staticOnlyCheck.test(method)) continue; ResolvedMethodDeclaration methodDeclaration = new ReflectionMethodDeclaration(method, typeSolver); methods.add(methodDeclaration); } for (ResolvedReferenceType ancestor : scopeType.getAncestors()) { SymbolReference<ResolvedMethodDeclaration> ref = MethodResolutionLogic.solveMethodInType(ancestor.getTypeDeclaration(), name, parameterTypes, staticOnly); if (ref.isSolved()) { methods.add(ref.getCorrespondingDeclaration()); } } if (scopeType.getAncestors().isEmpty()){ ReferenceTypeImpl objectClass = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); SymbolReference<ResolvedMethodDeclaration> ref = MethodResolutionLogic.solveMethodInType(objectClass.getTypeDeclaration(), name, parameterTypes, staticOnly); if (ref.isSolved()) { methods.add(ref.getCorrespondingDeclaration()); } } return MethodResolutionLogic.findMostApplicable(methods, name, parameterTypes, typeSolver); }
static SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> parameterTypes, boolean staticOnly, TypeSolver typeSolver, ResolvedReferenceTypeDeclaration scopeType, Class clazz){ List<ResolvedMethodDeclaration> methods = new ArrayList<>(); Predicate<Method> staticOnlyCheck = m -> !staticOnly || (staticOnly && Modifier.isStatic(m.getModifiers())); for (Method method : clazz.getMethods()) { if (method.isBridge() || method.isSynthetic() || !method.getName().equals(name)|| !staticOnlyCheck.test(method)) continue; ResolvedMethodDeclaration methodDeclaration = new ReflectionMethodDeclaration(method, typeSolver); methods.add(methodDeclaration); } for (ResolvedReferenceType ancestor : scopeType.getAncestors()) { SymbolReference<ResolvedMethodDeclaration> ref = MethodResolutionLogic.solveMethodInType(ancestor.getTypeDeclaration(), name, parameterTypes, staticOnly, typeSolver); if (ref.isSolved()) { methods.add(ref.getCorrespondingDeclaration()); } } if (scopeType.getAncestors().isEmpty()){ ReferenceTypeImpl objectClass = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver); SymbolReference<ResolvedMethodDeclaration> ref = MethodResolutionLogic.solveMethodInType(objectClass.getTypeDeclaration(), name, parameterTypes, staticOnly, typeSolver); if (ref.isSolved()) { methods.add(ref.getCorrespondingDeclaration()); } } return MethodResolutionLogic.findMostApplicable(methods, name, parameterTypes, typeSolver); }
@Override public boolean isAssignableBy(ResolvedType type) { if (type instanceof NullType) { return true; } if (type instanceof LambdaArgumentTypePlaceholder) { return isFunctionalInterface(); } if (type.isArray()) { return false; } if (type.isPrimitive()) { return false; } if (type.describe().equals(getQualifiedName())) { return true; } if (type instanceof ReferenceTypeImpl) { ReferenceTypeImpl otherTypeDeclaration = (ReferenceTypeImpl) type; return otherTypeDeclaration.getTypeDeclaration().canBeAssignedTo(this); } return false; }
public boolean isAssignableBy(ResolvedType type) { if (type instanceof NullType) { return true; } if (type instanceof LambdaArgumentTypePlaceholder) { return isFunctionalInterface(); } if (type.isArray()) { return false; } if (type.isPrimitive()) { return false; } if (type.describe().equals(typeDeclaration.getQualifiedName())) { return true; } if (type instanceof ReferenceTypeImpl) { ReferenceTypeImpl otherTypeDeclaration = (ReferenceTypeImpl) type; return otherTypeDeclaration.getTypeDeclaration().canBeAssignedTo(typeDeclaration); } return false; }
@Override public boolean isAssignableBy(ResolvedType type) { if (type instanceof NullType) { return true; } if (type instanceof LambdaArgumentTypePlaceholder) { return isFunctionalInterface(); } if (type.isArray()) { return false; } if (type.isPrimitive()) { return false; } if (type.describe().equals(getQualifiedName())) { return true; } if (type instanceof ReferenceTypeImpl) { ReferenceTypeImpl otherTypeDeclaration = (ReferenceTypeImpl) type; return otherTypeDeclaration.getTypeDeclaration().canBeAssignedTo(this); } return false; }
public boolean isAssignableBy(ResolvedType type) { if (type instanceof NullType) { return true; } if (type instanceof LambdaArgumentTypePlaceholder) { return isFunctionalInterface(); } if (type.isArray()) { return false; } if (type.isPrimitive()) { return false; } if (type.describe().equals(typeDeclaration.getQualifiedName())) { return true; } if (type instanceof ReferenceTypeImpl) { ReferenceTypeImpl otherTypeDeclaration = (ReferenceTypeImpl) type; return otherTypeDeclaration.getTypeDeclaration().canBeAssignedTo(typeDeclaration); } return false; }
public boolean isAssignableBy(ResolvedType type) { if (type instanceof NullType) { return true; } if (type instanceof LambdaArgumentTypePlaceholder) { return isFunctionalInterface(); } if (type.isArray()) { return false; } if (type.isPrimitive()) { return false; } if (type.describe().equals(typeDeclaration.getQualifiedName())) { return true; } if (type instanceof ReferenceTypeImpl) { ReferenceTypeImpl otherTypeDeclaration = (ReferenceTypeImpl) type; return otherTypeDeclaration.getTypeDeclaration().canBeAssignedTo(typeDeclaration); } return false; }
@Override public boolean isAssignableBy(ResolvedType type) { if (type instanceof NullType) { return true; } if (type instanceof LambdaArgumentTypePlaceholder) { return isFunctionalInterface(); } if (type.isArray()) { return false; } if (type.isPrimitive()) { return false; } if (type.describe().equals(getQualifiedName())) { return true; } if (type instanceof ReferenceTypeImpl) { ReferenceTypeImpl otherTypeDeclaration = (ReferenceTypeImpl) type; return otherTypeDeclaration.getTypeDeclaration().canBeAssignedTo(this); } return false; }