@Override public String getName() { return this.declaringType.getName(); }
@Override public boolean hasInternalType(String name) { /* The name of the ReferenceTypeDeclaration could be composed of the internal class and the outer class, e.g. A$B. That's why we search the internal type in the ending part. In case the name is composed of the internal type only, i.e. f.getName() returns B, it will also works. */ return this.internalTypes().stream().anyMatch(f -> f.getName().endsWith(name)); } }
@Override public boolean hasInternalType(String name) { /* The name of the ReferenceTypeDeclaration could be composed on the internal class and the outer class, e.g. A$B. That's why we search the internal type in the ending part. In case the name is composed of the internal type only, i.e. f.getName() returns B, it will also works. */ return this.internalTypes().stream().anyMatch(f -> f.getName().endsWith(name)); }
@Override public boolean hasInternalType(String name) { /* The name of the ReferenceTypeDeclaration could be composed on the internal class and the outer class, e.g. A$B. That's why we search the internal type in the ending part. In case the name is composed of the internal type only, i.e. f.getName() returns B, it will also works. */ return this.internalTypes().stream().anyMatch(f -> f.getName().endsWith(name)); } }
@Override public boolean hasInternalType(String name) { /* The name of the ReferenceTypeDeclaration could be composed on the internal class and the outer class, e.g. A$B. That's why we search the internal type in the ending part. In case the name is composed of the internal type only, i.e. f.getName() returns B, it will also works. */ return this.internalTypes().stream().anyMatch(f -> f.getName().endsWith(name)); }
@Override public ResolvedReferenceTypeDeclaration getInternalType(String name) { /* The name of the ReferenceTypeDeclaration could be composed on the internal class and the outer class, e.g. A$B. That's why we search the internal type in the ending part. In case the name is composed of the internal type only, i.e. f.getName() returns B, it will also works. */ Optional<ResolvedReferenceTypeDeclaration> type = this.internalTypes().stream().filter(f -> f.getName().endsWith(name)).findFirst(); return type.orElseThrow(() -> new UnsolvedSymbolException("Internal type not found: " + name)); }
@Override public ResolvedReferenceTypeDeclaration getInternalType(String name) { /* The name of the ReferenceTypeDeclaration could be composed of the internal class and the outer class, e.g. A$B. That's why we search the internal type in the ending part. In case the name is composed of the internal type only, i.e. f.getName() returns B, it will also works. */ Optional<ResolvedReferenceTypeDeclaration> type = this.internalTypes().stream().filter(f -> f.getName().endsWith(name)).findFirst(); return type.orElseThrow(() -> new UnsolvedSymbolException("Internal type not found: " + name)); }
@Override public ResolvedReferenceTypeDeclaration getInternalType(String name) { /* The name of the ReferenceTypeDeclaration could be composed on the internal class and the outer class, e.g. A$B. That's why we search the internal type in the ending part. In case the name is composed of the internal type only, i.e. f.getName() returns B, it will also works. */ Optional<ResolvedReferenceTypeDeclaration> type = this.internalTypes().stream().filter(f -> f.getName().endsWith(name)).findFirst(); return type.orElseThrow(() -> new UnsolvedSymbolException("Internal type not found: " + name)); }
@Override public ResolvedReferenceTypeDeclaration getInternalType(String name) { /* The name of the ReferenceTypeDeclaration could be composed of the internal class and the outer class, e.g. A$B. That's why we search the internal type in the ending part. In case the name is composed of the internal type only, i.e. f.getName() returns B, it will also works. */ Optional<ResolvedReferenceTypeDeclaration> type = this.internalTypes().stream().filter(f -> f.getName().endsWith(name)).findFirst(); return type.orElseThrow(() -> new UnsolvedSymbolException("Internal type not found: " + name)); }
@Override public ResolvedReferenceTypeDeclaration getInternalType(String name) { /* The name of the ReferenceTypeDeclaration could be composed on the internal class and the outer class, e.g. A$B. That's why we search the internal type in the ending part. In case the name is composed of the internal type only, i.e. f.getName() returns B, it will also works. */ Optional<ResolvedReferenceTypeDeclaration> type = this.internalTypes().stream().filter(f -> f.getName().endsWith(name)).findFirst(); return type.orElseThrow(() -> new UnsolvedSymbolException("Internal type not found: " + name)); }
@Override public ResolvedReferenceTypeDeclaration getInternalType(String name) { /* The name of the ReferenceTypeDeclaration could be composed on the internal class and the outer class, e.g. A$B. That's why we search the internal type in the ending part. In case the name is composed of the internal type only, i.e. f.getName() returns B, it will also works. */ Optional<ResolvedReferenceTypeDeclaration> type = this.internalTypes().stream().filter(f -> f.getName().endsWith(name)).findFirst(); return type.orElseThrow(() -> new UnsolvedSymbolException("Internal type not found: " + name)); }
@Override public ResolvedReferenceTypeDeclaration getInternalType(String name) { /* The name of the ReferenceTypeDeclaration could be composed on the internal class and the outer class, e.g. A$B. That's why we search the internal type in the ending part. In case the name is composed of the internal type only, i.e. f.getName() returns B, it will also works. */ Optional<ResolvedReferenceTypeDeclaration> type = this.internalTypes().stream().filter(f -> f.getName().endsWith(name)).findFirst(); return type.orElseThrow(() -> new UnsolvedSymbolException("Internal type not found: " + name)); }
@Override public ResolvedReferenceTypeDeclaration getInternalType(String name) { /* The name of the ReferenceTypeDeclaration could be composed of the internal class and the outer class, e.g. A$B. That's why we search the internal type in the ending part. In case the name is composed of the internal type only, i.e. f.getName() returns B, it will also works. */ Optional<ResolvedReferenceTypeDeclaration> type = this.internalTypes().stream().filter(f -> f.getName().endsWith(name)).findFirst(); return type.orElseThrow(() -> new UnsolvedSymbolException("Internal type not found: " + name)); }
@Test public void solveMethodAsUsageOverrideCase() throws ParseException { CompilationUnit cu = parseSample("ClassWithMethods"); ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A"); Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver); Optional<MethodUsage> ref = context.solveMethodAsUsage("foo1", ImmutableList.of(), new ReflectionTypeSolver()); assertEquals(true, ref.isPresent()); assertEquals("A", ref.get().declaringType().getName()); assertEquals(0, ref.get().getNoParams()); }
@Test public void solveMethodAsUsageWithPrimitiveParameters() throws ParseException { CompilationUnit cu = parseSample("ClassWithMethods"); ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A"); Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver); ResolvedType intType = ResolvedPrimitiveType.INT; Optional<MethodUsage> ref = context.solveMethodAsUsage("foo3", ImmutableList.of(intType), new ReflectionTypeSolver()); assertEquals(true, ref.isPresent()); assertEquals("A", ref.get().declaringType().getName()); assertEquals(1, ref.get().getNoParams()); }
@Test public void solveMethodAsUsageInheritedCase() throws ParseException { CompilationUnit cu = parseSample("ClassWithMethods"); ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A"); Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver); Optional<MethodUsage> ref = context.solveMethodAsUsage("foo2", ImmutableList.of(), new ReflectionTypeSolver()); assertEquals(true, ref.isPresent()); assertEquals("Super", ref.get().declaringType().getName()); assertEquals(0, ref.get().getNoParams()); }
@Test public void solveMethodAsUsageWithMoreSpecializedParameter() throws ParseException { CompilationUnit cu = parseSample("ClassWithMethods"); ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A"); Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver); ResolvedType stringType = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver); Optional<MethodUsage> ref = context.solveMethodAsUsage("foo4", ImmutableList.of(stringType), new ReflectionTypeSolver()); assertEquals(true, ref.isPresent()); assertEquals("A", ref.get().declaringType().getName()); assertEquals(1, ref.get().getNoParams()); }
@Test public void solveMethodInheritedCase() throws ParseException { CompilationUnit cu = parseSample("ClassWithMethods"); ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A"); Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver); SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("foo2", ImmutableList.of(), false, new ReflectionTypeSolver()); assertEquals(true, ref.isSolved()); assertEquals("Super", ref.getCorrespondingDeclaration().declaringType().getName()); assertEquals(0, ref.getCorrespondingDeclaration().getNumberOfParams()); }
@Test public void solveMethodWithPrimitiveParameters() throws ParseException { CompilationUnit cu = parseSample("ClassWithMethods"); ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A"); Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver); ResolvedType intType = ResolvedPrimitiveType.INT; SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("foo3", ImmutableList.of(intType), false, new ReflectionTypeSolver()); assertEquals(true, ref.isSolved()); assertEquals("A", ref.getCorrespondingDeclaration().declaringType().getName()); assertEquals(1, ref.getCorrespondingDeclaration().getNumberOfParams()); }
@Test public void solveMethodOverrideCase() throws ParseException { CompilationUnit cu = parseSample("ClassWithMethods"); ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A"); Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver); SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("foo1", ImmutableList.of(), false, new ReflectionTypeSolver()); assertEquals(true, ref.isSolved()); assertEquals("A", ref.getCorrespondingDeclaration().declaringType().getName()); assertEquals(0, ref.getCorrespondingDeclaration().getNumberOfParams()); }