Search in sources :

Example 61 with Context

use of com.github.javaparser.symbolsolver.core.resolution.Context 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 62 with Context

use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.

the class CompilationUnitContextResolutionTest method solveMethodStaticallyImportedWithoutAsterisk.

@Test
public void solveMethodStaticallyImportedWithoutAsterisk() throws ParseException, IOException {
    CompilationUnit cu = parseSample("CompilationUnitSymbols");
    Context context = new CompilationUnitContext(cu, typeSolver);
    CombinedTypeSolver typeSolver = new CombinedTypeSolver();
    typeSolver.add(new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
    typeSolver.add(new ReflectionTypeSolver());
    SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("assertEquals", ImmutableList.of(NullType.INSTANCE, NullType.INSTANCE), false, typeSolver);
    assertEquals(true, ref.isSolved());
    assertEquals("assertEquals", ref.getCorrespondingDeclaration().getName());
    assertEquals(2, ref.getCorrespondingDeclaration().getNumberOfParams());
    assertEquals("java.lang.Object", ref.getCorrespondingDeclaration().getParam(0).getType().asReferenceType().getQualifiedName());
    assertEquals("java.lang.Object", ref.getCorrespondingDeclaration().getParam(1).getType().asReferenceType().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) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) JarTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 63 with Context

use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.

the class CompilationUnitContextResolutionTest method solveSymbolReferringToStaticallyImportedUsingAsteriskValue.

@Test
public void solveSymbolReferringToStaticallyImportedUsingAsteriskValue() throws ParseException, IOException {
    CompilationUnit cu = parseSample("CompilationUnitSymbols");
    Context context = new CompilationUnitContext(cu, typeSolver);
    CombinedTypeSolver typeSolver = new CombinedTypeSolver();
    typeSolver.add(new ReflectionTypeSolver());
    typeSolver.add(new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
    SymbolReference<? extends ResolvedValueDeclaration> ref = context.solveSymbol("err", typeSolver);
    assertEquals(true, ref.isSolved());
    assertEquals("java.io.PrintStream", ref.getCorrespondingDeclaration().getType().asReferenceType().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) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) JarTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 64 with Context

use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.

the class CompilationUnitContextResolutionTest method solveSymbolAsValueReferringToStaticallyImportedValue.

@Test
public void solveSymbolAsValueReferringToStaticallyImportedValue() throws ParseException, IOException {
    CompilationUnit cu = parseSample("CompilationUnitSymbols");
    Context context = new CompilationUnitContext(cu, typeSolver);
    CombinedTypeSolver typeSolver = new CombinedTypeSolver();
    typeSolver.add(new ReflectionTypeSolver());
    typeSolver.add(new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
    Optional<Value> ref = context.solveSymbolAsValue("out", typeSolver);
    assertEquals(true, ref.isPresent());
    assertEquals("java.io.PrintStream", ref.get().getType().describe());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) Value(com.github.javaparser.symbolsolver.model.resolution.Value) JarTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 65 with Context

use of com.github.javaparser.symbolsolver.core.resolution.Context 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

Context (com.github.javaparser.symbolsolver.core.resolution.Context)72 CompilationUnit (com.github.javaparser.ast.CompilationUnit)65 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)63 Test (org.junit.Test)63 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)51 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)40 ClassOrInterfaceDeclarationContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext)37 MemoryTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver)32 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)26 ResolvedTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration)17 Value (com.github.javaparser.symbolsolver.model.resolution.Value)16 MethodUsage (com.github.javaparser.resolution.MethodUsage)14 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)11 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)10 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)9 UnsolvedSymbolException (com.github.javaparser.resolution.UnsolvedSymbolException)7 JarTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver)7 EnumDeclarationContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.EnumDeclarationContext)6 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)6 ReflectionClassDeclaration (com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration)5