Search in sources :

Example 6 with ClassOrInterfaceDeclarationContext

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

the class ClassOrInterfaceDeclarationContextResolutionTest method solveSymbolAsValueReferringToDeclaredStaticField.

@Test
public void solveSymbolAsValueReferringToDeclaredStaticField() {
    CompilationUnit cu = parseSample("ClassWithSymbols");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    Optional<Value> ref = context.solveSymbolAsValue("j", new MemoryTypeSolver());
    assertEquals(true, ref.isPresent());
    assertEquals("long", ref.get().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) Value(com.github.javaparser.symbolsolver.model.resolution.Value) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 7 with ClassOrInterfaceDeclarationContext

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

the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodAsUsageSimpleCase.

@Test
public void solveMethodAsUsageSimpleCase() {
    CompilationUnit cu = parseSample("ClassWithMethods");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    Optional<MethodUsage> ref = context.solveMethodAsUsage("foo0", ImmutableList.of(), new ReflectionTypeSolver());
    assertEquals(true, ref.isPresent());
    assertEquals("A", ref.get().declaringType().getName());
    assertEquals(0, 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) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) MethodUsage(com.github.javaparser.resolution.MethodUsage) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 8 with ClassOrInterfaceDeclarationContext

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

the class ClassOrInterfaceDeclarationContextResolutionTest method solveSymbolReferringToInheritedStaticField.

@Test
public void solveSymbolReferringToInheritedStaticField() {
    CompilationUnit cu = parseSample("ClassWithSymbols");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    SymbolReference<? extends ResolvedValueDeclaration> ref = context.solveSymbol("m", new MemoryTypeSolver());
    assertEquals(true, ref.isSolved());
    assertEquals("char", 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 9 with ClassOrInterfaceDeclarationContext

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

the class ClassOrInterfaceDeclarationContextResolutionTest method solveTypeRefToInternalEnum.

@Test
public void solveTypeRefToInternalEnum() {
    CompilationUnit cu = parseSample("ClassWithTypes");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    SymbolReference<ResolvedTypeDeclaration> ref = context.solveType("E", new MemoryTypeSolver());
    assertEquals(true, 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) ResolvedTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 10 with ClassOrInterfaceDeclarationContext

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

the class ClassOrInterfaceDeclarationContextResolutionTest method solveTypeRefToInternalClass.

@Test
public void solveTypeRefToInternalClass() {
    CompilationUnit cu = parseSample("ClassWithTypes");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    SymbolReference<ResolvedTypeDeclaration> ref = context.solveType("B", new MemoryTypeSolver());
    assertEquals(true, 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) ResolvedTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration) 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