Search in sources :

Example 26 with MemoryTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveSymbolAsValueReferringToInheritedStaticField.

@Test
public void solveSymbolAsValueReferringToInheritedStaticField() {
    CompilationUnit cu = parseSample("ClassWithSymbols");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    Optional<Value> ref = context.solveSymbolAsValue("m", new MemoryTypeSolver());
    assertEquals(true, ref.isPresent());
    assertEquals("char", 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 27 with MemoryTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveTypeRefToMoreQualifiedInternalOfInternalClass.

@Test
public void solveTypeRefToMoreQualifiedInternalOfInternalClass() {
    CompilationUnit cu = parseSample("ClassWithTypes");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    SymbolReference<ResolvedTypeDeclaration> ref = context.solveType("A.B.C", 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 28 with MemoryTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver in project javaparser by javaparser.

the class CompilationUnitContextResolutionTest method solveTypeInSamePackage.

@Test
public void solveTypeInSamePackage() {
    CompilationUnit cu = parseSample("CompilationUnitWithImports");
    Context context = new CompilationUnitContext(cu, typeSolver);
    ResolvedReferenceTypeDeclaration otherClass = mock(ResolvedReferenceTypeDeclaration.class);
    when(otherClass.getQualifiedName()).thenReturn("com.foo.OtherClassInSamePackage");
    MemoryTypeSolver memoryTypeSolver = new MemoryTypeSolver();
    memoryTypeSolver.addDeclaration("com.foo.OtherClassInSamePackage", otherClass);
    SymbolReference<ResolvedTypeDeclaration> ref = context.solveType("OtherClassInSamePackage", memoryTypeSolver);
    assertEquals(true, ref.isSolved());
    assertEquals("com.foo.OtherClassInSamePackage", ref.getCorrespondingDeclaration().getQualifiedName());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) MemoryTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) ResolvedReferenceTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration) ResolvedTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 29 with MemoryTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver in project javaparser by javaparser.

the class CompilationUnitContextResolutionTest method solveExistingGenericType.

@Test
public void solveExistingGenericType() {
    CompilationUnit cu = parseSample("ClassWithTypeVariables");
    Context context = new CompilationUnitContext(cu, 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(false, a.isPresent());
    assertEquals(false, b.isPresent());
    assertEquals(false, c.isPresent());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) MemoryTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 30 with MemoryTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver in project javaparser by javaparser.

the class EnumDeclarationContextResolutionTest method solveSymbolAsValueReferringToValue.

@Test
public void solveSymbolAsValueReferringToValue() {
    CompilationUnit cu = parseSample("AnEnum");
    com.github.javaparser.ast.body.EnumDeclaration enumDeclaration = Navigator.demandEnum(cu, "MyEnum");
    Context context = new EnumDeclarationContext(enumDeclaration, typeSolver);
    Optional<Value> ref = context.solveSymbolAsValue("E1", new MemoryTypeSolver());
    assertEquals(true, ref.isPresent());
    assertEquals("MyEnum", ref.get().getType().describe());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) EnumDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.EnumDeclarationContext) Context(com.github.javaparser.symbolsolver.core.resolution.Context) MemoryTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver) EnumDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.EnumDeclarationContext) Value(com.github.javaparser.symbolsolver.model.resolution.Value) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Aggregations

MemoryTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver)36 Test (org.junit.Test)36 CompilationUnit (com.github.javaparser.ast.CompilationUnit)33 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)33 Context (com.github.javaparser.symbolsolver.core.resolution.Context)32 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)25 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)24 ClassOrInterfaceDeclarationContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext)23 ResolvedTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration)11 Value (com.github.javaparser.symbolsolver.model.resolution.Value)9 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)7 EnumDeclarationContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.EnumDeclarationContext)6 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)2 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 ResolvedReferenceTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration)1 MethodContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext)1