public Set<ResolvedMethodDeclaration> getDeclaredMethods() { return Arrays.stream(clazz.getDeclaredMethods()) .filter(m -> !m.isSynthetic() && !m.isBridge()) .map(m -> new ReflectionMethodDeclaration(m, typeSolver)) .collect(Collectors.toSet()); }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(); } return ReflectionFactory.typeUsageFor(this.method.getExceptionTypes()[index], typeSolver); } }
static MethodUsage resolveTypeVariables(Context context, ResolvedMethodDeclaration methodDeclaration, List<ResolvedType> parameterTypes) { if (methodDeclaration instanceof JavaParserMethodDeclaration) { return ((JavaParserMethodDeclaration) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else if (methodDeclaration instanceof JavassistMethodDeclaration) { return ((JavassistMethodDeclaration) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else if (methodDeclaration instanceof JavaParserEnumDeclaration.ValuesMethod) { return ((JavaParserEnumDeclaration.ValuesMethod) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else if (methodDeclaration instanceof ReflectionMethodDeclaration) { return ((ReflectionMethodDeclaration) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else { throw new UnsupportedOperationException(); } } }
static MethodUsage resolveTypeVariables(Context context, ResolvedMethodDeclaration methodDeclaration, List<ResolvedType> parameterTypes) { if (methodDeclaration instanceof JavaParserMethodDeclaration) { return ((JavaParserMethodDeclaration) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else if (methodDeclaration instanceof JavassistMethodDeclaration) { return ((JavassistMethodDeclaration) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else if (methodDeclaration instanceof JavaParserEnumDeclaration.ValuesMethod) { return ((JavaParserEnumDeclaration.ValuesMethod) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else if (methodDeclaration instanceof ReflectionMethodDeclaration) { return ((ReflectionMethodDeclaration) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else { throw new UnsupportedOperationException(); } } }
public Set<ResolvedMethodDeclaration> getDeclaredMethods() { return Arrays.stream(clazz.getDeclaredMethods()) .filter(m -> !m.isSynthetic() && !m.isBridge()) .map(m -> new ReflectionMethodDeclaration(m, typeSolver)) .collect(Collectors.toSet()); }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(); } return ReflectionFactory.typeUsageFor(this.method.getExceptionTypes()[index], typeSolver); }
public Set<ResolvedMethodDeclaration> getDeclaredMethods() { return Arrays.stream(clazz.getDeclaredMethods()) .filter(m -> !m.isSynthetic() && !m.isBridge()) .map(m -> new ReflectionMethodDeclaration(m, typeSolver)) .collect(Collectors.toSet()); }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(); } return ReflectionFactory.typeUsageFor(this.method.getExceptionTypes()[index], typeSolver); } }
public ReflectionTypeParameter(TypeVariable typeVariable, boolean declaredOnClass, TypeSolver typeSolver) { GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration(); if (genericDeclaration instanceof Class) { container = ReflectionFactory.typeDeclarationFor((Class) genericDeclaration, typeSolver); } else if (genericDeclaration instanceof Method) { container = new ReflectionMethodDeclaration((Method) genericDeclaration, typeSolver); } else if (genericDeclaration instanceof Constructor) { container = new ReflectionConstructorDeclaration((Constructor) genericDeclaration, typeSolver); } this.typeVariable = typeVariable; this.typeSolver = typeSolver; }
public ReflectionTypeParameter(TypeVariable typeVariable, boolean declaredOnClass, TypeSolver typeSolver) { GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration(); if (genericDeclaration instanceof Class) { container = ReflectionFactory.typeDeclarationFor((Class) genericDeclaration, typeSolver); } else if (genericDeclaration instanceof Method) { container = new ReflectionMethodDeclaration((Method) genericDeclaration, typeSolver); } else if (genericDeclaration instanceof Constructor) { container = new ReflectionConstructorDeclaration((Constructor) genericDeclaration, typeSolver); } this.typeVariable = typeVariable; this.typeSolver = typeSolver; }
public ReflectionTypeParameter(TypeVariable typeVariable, boolean declaredOnClass, TypeSolver typeSolver) { GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration(); if (genericDeclaration instanceof Class) { container = ReflectionFactory.typeDeclarationFor((Class) genericDeclaration, typeSolver); } else if (genericDeclaration instanceof Method) { container = new ReflectionMethodDeclaration((Method) genericDeclaration, typeSolver); } else if (genericDeclaration instanceof Constructor) { container = new ReflectionConstructorDeclaration((Constructor) genericDeclaration, typeSolver); } this.typeVariable = typeVariable; this.typeSolver = 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); }
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; }
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); }
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); }
.sorted(new MethodComparator()).collect(Collectors.toList())) { if (method.isBridge() || method.isSynthetic()) continue; ResolvedMethodDeclaration methodDeclaration = new ReflectionMethodDeclaration(method, typeSolver); methods.add(methodDeclaration);
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); }