Search in sources :

Example 16 with ClassOrInterfaceDeclarationContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodAsUsageWithMoreSpecializedParameter.

@Test
public void solveMethodAsUsageWithMoreSpecializedParameter() {
    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());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) ReflectionClassDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration) MethodUsage(com.github.javaparser.resolution.MethodUsage) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 17 with ClassOrInterfaceDeclarationContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveSymbolReferringToUnknownElement.

@Test
public void solveSymbolReferringToUnknownElement() {
    CompilationUnit cu = parseSample("ClassWithSymbols");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    SymbolReference<? extends ResolvedValueDeclaration> ref = context.solveSymbol("zzz", new MemoryTypeSolver());
    assertEquals(false, ref.isSolved());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) MemoryTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 18 with ClassOrInterfaceDeclarationContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveSymbolReferringToInterfaceInheritedInstanceField.

@Test
public void solveSymbolReferringToInterfaceInheritedInstanceField() {
    CompilationUnit cu = parseSample("ClassWithSymbols");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    SymbolReference<? extends ResolvedValueDeclaration> ref = context.solveSymbol("o", new MemoryTypeSolver());
    assertEquals(true, ref.isSolved());
    assertEquals("int", ref.getCorrespondingDeclaration().getType().describe());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) MemoryTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 19 with ClassOrInterfaceDeclarationContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveExistingGenericType.

@Test
public void solveExistingGenericType() {
    CompilationUnit cu = parseSample("ClassWithTypeVariables");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    Optional<ResolvedType> a = context.solveGenericType("A", new MemoryTypeSolver());
    Optional<ResolvedType> b = context.solveGenericType("B", new MemoryTypeSolver());
    Optional<ResolvedType> c = context.solveGenericType("C", new MemoryTypeSolver());
    assertEquals(true, a.isPresent());
    assertEquals("A", a.get().describe());
    assertEquals(true, a.get().isTypeVariable());
    assertEquals(true, b.isPresent());
    assertEquals("B", b.get().describe());
    assertEquals(true, b.get().isTypeVariable());
    assertEquals(true, c.isPresent());
    assertEquals("C", c.get().describe());
    assertEquals(true, c.get().isTypeVariable());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) MemoryTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 20 with ClassOrInterfaceDeclarationContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodWithMoreSpecializedParameter.

@Test
public void solveMethodWithMoreSpecializedParameter() {
    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);
    SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("foo4", ImmutableList.of(stringType), false, new ReflectionTypeSolver());
    assertEquals(true, ref.isSolved());
    assertEquals("A", ref.getCorrespondingDeclaration().declaringType().getName());
    assertEquals(1, ref.getCorrespondingDeclaration().getNumberOfParams());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) ReflectionClassDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Aggregations

CompilationUnit (com.github.javaparser.ast.CompilationUnit)38 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)38 ClassOrInterfaceDeclarationContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext)38 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)38 Test (org.junit.Test)38 Context (com.github.javaparser.symbolsolver.core.resolution.Context)37 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)37 MemoryTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver)23 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)14 ResolvedTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration)11 MethodUsage (com.github.javaparser.resolution.MethodUsage)6 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)6 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)6 Value (com.github.javaparser.symbolsolver.model.resolution.Value)6 ReferenceTypeImpl (com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl)2 ReflectionClassDeclaration (com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration)2