@Override public ResolvedType getType() { return ReflectionFactory.typeUsageFor(genericType, typeSolver); } }
@Override public ResolvedType getType() { return ReflectionFactory.typeUsageFor(genericType, typeSolver); } }
@Override public ResolvedType getType() { return ReflectionFactory.typeUsageFor(genericType, typeSolver); }
@Override public ResolvedType getReturnType() { return ReflectionFactory.typeUsageFor(method.getGenericReturnType(), typeSolver); }
private ResolvedType calcType() { // TODO consider interfaces, enums, primitive types, arrays return ReflectionFactory.typeUsageFor(field.getGenericType(), typeSolver); }
@Override public ResolvedType getReturnType() { return ReflectionFactory.typeUsageFor(method.getGenericReturnType(), typeSolver); }
private ResolvedType calcType() { // TODO consider interfaces, enums, primitive types, arrays return ReflectionFactory.typeUsageFor(field.getGenericType(), typeSolver); }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(); } return ReflectionFactory.typeUsageFor(this.method.getExceptionTypes()[index], typeSolver); } }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(); } return ReflectionFactory.typeUsageFor(this.method.getExceptionTypes()[index], typeSolver); }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(); } return ReflectionFactory.typeUsageFor(this.method.getExceptionTypes()[index], typeSolver); } }
@Override public List<Bound> getBounds() { return Arrays.stream(typeVariable.getBounds()).map((refB) -> Bound.extendsBound(ReflectionFactory.typeUsageFor(refB, typeSolver))).collect(Collectors.toList()); }
@Override public List<Bound> getBounds() { return Arrays.stream(typeVariable.getBounds()).map((refB) -> Bound.extendsBound(ReflectionFactory.typeUsageFor(refB, typeSolver))).collect(Collectors.toList()); }
@Override public List<Bound> getBounds() { return Arrays.stream(typeVariable.getBounds()).map((refB) -> Bound.extendsBound(ReflectionFactory.typeUsageFor(refB, typeSolver))).collect(Collectors.toList()); }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(); } return ReflectionFactory.typeUsageFor(this.constructor.getExceptionTypes()[index], typeSolver); }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(); } return ReflectionFactory.typeUsageFor(this.constructor.getExceptionTypes()[index], typeSolver); } }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(); } return ReflectionFactory.typeUsageFor(this.constructor.getExceptionTypes()[index], typeSolver); } }
@Test public void compatibilityShouldConsiderAlsoTypeVariablesRaw() { JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); ResolvedReferenceType rawClassType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(Class.class, typeSolver); MethodUsage mu = constructorDeclaration.getAllMethods().stream().filter(m -> m.getDeclaration().getSignature().equals("isThrows(java.lang.Class<? extends java.lang.Throwable>)")).findFirst().get(); assertEquals(true, MethodResolutionLogic.isApplicable(mu, "isThrows", ImmutableList.of(rawClassType), typeSolver)); }
@Test public void compatibilityShouldConsiderAlsoTypeVariablesPositive() { JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); ResolvedReferenceType runtimeException = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(RuntimeException.class, typeSolver); ResolvedReferenceType rawClassType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(Class.class, typeSolver); ResolvedReferenceType classOfRuntimeType = (ResolvedReferenceType) rawClassType.replaceTypeVariables(rawClassType.getTypeDeclaration().getTypeParameters().get(0), runtimeException); MethodUsage mu = constructorDeclaration.getAllMethods().stream().filter(m -> m.getDeclaration().getSignature().equals("isThrows(java.lang.Class<? extends java.lang.Throwable>)")).findFirst().get(); assertEquals(true, MethodResolutionLogic.isApplicable(mu, "isThrows", ImmutableList.of(classOfRuntimeType), typeSolver)); } }
@Test public void compatibilityShouldConsiderAlsoTypeVariablesNegative() { JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); ResolvedReferenceType stringType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(String.class, typeSolver); ResolvedReferenceType rawClassType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(Class.class, typeSolver); assertEquals(true, rawClassType.isRawType()); ResolvedReferenceType classOfStringType = (ResolvedReferenceType) rawClassType.replaceTypeVariables(rawClassType.getTypeDeclaration().getTypeParameters().get(0), stringType); MethodUsage mu = constructorDeclaration.getAllMethods().stream().filter(m -> m.getDeclaration().getSignature().equals("isThrows(java.lang.Class<? extends java.lang.Throwable>)")).findFirst().get(); assertEquals(false, MethodResolutionLogic.isApplicable(mu, "isThrows", ImmutableList.of(classOfStringType), typeSolver)); }
@Test public void testSolveMethodNotExistingBecauseOfTypeParameters() { JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolverNewCode.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); SymbolReference<ResolvedMethodDeclaration> res = null; ResolvedReferenceType stringType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(String.class, typeSolverNewCode); ResolvedReferenceType rawClassType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(Class.class, typeSolverNewCode); ResolvedReferenceType classOfStringType = (ResolvedReferenceType) rawClassType.replaceTypeVariables(rawClassType.getTypeDeclaration().getTypeParameters().get(0), stringType); res = constructorDeclaration.solveMethod("isThrows", ImmutableList.of(classOfStringType)); assertEquals(false, res.isSolved()); }