Search in sources :

Example 66 with Context

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

the class EnumDeclarationContextResolutionTest method solveSymbolReferringToDeclaredInstanceField.

@Test
public void solveSymbolReferringToDeclaredInstanceField() {
    CompilationUnit cu = parseSample("AnEnum");
    com.github.javaparser.ast.body.EnumDeclaration enumDeclaration = Navigator.demandEnum(cu, "MyEnum");
    Context context = new EnumDeclarationContext(enumDeclaration, typeSolver);
    SymbolReference<? extends ResolvedValueDeclaration> ref = context.solveSymbol("i", new MemoryTypeSolver());
    assertEquals(true, ref.isSolved());
    assertEquals("int", ref.getCorrespondingDeclaration().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) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 67 with Context

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

the class EnumDeclarationContextResolutionTest method solveSymbolReferringToDeclaredStaticField.

@Test
public void solveSymbolReferringToDeclaredStaticField() {
    CompilationUnit cu = parseSample("AnEnum");
    com.github.javaparser.ast.body.EnumDeclaration enumDeclaration = Navigator.demandEnum(cu, "MyEnum");
    Context context = new EnumDeclarationContext(enumDeclaration, typeSolver);
    SymbolReference<? extends ResolvedValueDeclaration> ref = context.solveSymbol("j", new MemoryTypeSolver());
    assertEquals(true, ref.isSolved());
    assertEquals("long", ref.getCorrespondingDeclaration().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) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 68 with Context

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

the class EnumDeclarationContextResolutionTest method solveSymbolAsValueReferringToDeclaredStaticField.

@Test
public void solveSymbolAsValueReferringToDeclaredStaticField() {
    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("j", new MemoryTypeSolver());
    assertEquals(true, ref.isPresent());
    assertEquals("long", 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)

Example 69 with Context

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

the class EnumDeclarationContextResolutionTest method solveSymbolReferringToValue.

@Test
public void solveSymbolReferringToValue() {
    CompilationUnit cu = parseSample("AnEnum");
    com.github.javaparser.ast.body.EnumDeclaration enumDeclaration = Navigator.demandEnum(cu, "MyEnum");
    Context context = new EnumDeclarationContext(enumDeclaration, typeSolver);
    SymbolReference<? extends ResolvedValueDeclaration> ref = context.solveSymbol("E1", new MemoryTypeSolver());
    assertEquals(true, ref.isSolved());
    assertEquals("MyEnum", ref.getCorrespondingDeclaration().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) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 70 with Context

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

the class LambdaExprContextResolutionTest method solveParameterOfLambdaInMethodCallExpr.

@Test
public void solveParameterOfLambdaInMethodCallExpr() {
    CompilationUnit cu = parseSample("Lambda");
    com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
    MethodDeclaration method = Navigator.demandMethod(clazz, "lambdaMap");
    ReturnStmt returnStmt = Navigator.findReturnStmt(method);
    MethodCallExpr methodCallExpr = (MethodCallExpr) returnStmt.getExpression().get();
    LambdaExpr lambdaExpr = (LambdaExpr) methodCallExpr.getArguments().get(0);
    Context context = new LambdaExprContext(lambdaExpr, typeSolver);
    Optional<Value> ref = context.solveSymbolAsValue("p", typeSolver);
    assertTrue(ref.isPresent());
    assertEquals("? super java.lang.String", ref.get().getType().describe());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Context(com.github.javaparser.symbolsolver.core.resolution.Context) LambdaExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) LambdaExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext) Value(com.github.javaparser.symbolsolver.model.resolution.Value) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) 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