Search in sources :

Example 21 with JavaParserTypeSolver

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

the class FieldsResolutionTest method accessClassFieldThroughThisWithCompetingSymbolInParentContext.

@Test
public void accessClassFieldThroughThisWithCompetingSymbolInParentContext() {
    CompilationUnit cu = parseSample("AccessClassMemberThroughThis");
    com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "AccessClassMemberThroughThis");
    MethodDeclaration method = Navigator.demandMethod(clazz, "setLabel");
    ExpressionStmt expressionStmt = (ExpressionStmt) method.getBody().get().getStatements().get(0);
    AssignExpr assignExpr = (AssignExpr) expressionStmt.getExpression();
    FieldAccessExpr fieldAccessExpr = (FieldAccessExpr) assignExpr.getTarget();
    File src = adaptPath(new File("src/test/resources"));
    CombinedTypeSolver typeSolver = new CombinedTypeSolver(new JavaParserTypeSolver(src), new ReflectionTypeSolver());
    SymbolSolver symbolSolver = new SymbolSolver(typeSolver);
    SymbolReference<? extends ResolvedValueDeclaration> ref = symbolSolver.solveSymbol(fieldAccessExpr.getName().getId(), fieldAccessExpr);
    assertTrue(ref.isSolved());
    assertTrue(ref.getCorrespondingDeclaration().isField());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) File(java.io.File) Test(org.junit.Test)

Example 22 with JavaParserTypeSolver

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

the class MethodsResolutionLogicTest method setup.

@Before
public void setup() {
    File srcNewCode = adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-core"));
    CombinedTypeSolver combinedTypeSolverNewCode = new CombinedTypeSolver();
    combinedTypeSolverNewCode.add(new ReflectionTypeSolver());
    combinedTypeSolverNewCode.add(new JavaParserTypeSolver(srcNewCode));
    combinedTypeSolverNewCode.add(new JavaParserTypeSolver(adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-generated-sources"))));
    typeSolver = combinedTypeSolverNewCode;
}
Also used : JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) File(java.io.File) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) Before(org.junit.Before)

Example 23 with JavaParserTypeSolver

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

the class MethodCallExprContextResolutionTest method createTypeSolver.

private CombinedTypeSolver createTypeSolver() {
    File src = adaptPath(new File("src/test/resources"));
    CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
    combinedTypeSolver.add(new ReflectionTypeSolver());
    combinedTypeSolver.add(new JavaParserTypeSolver(src));
    return combinedTypeSolver;
}
Also used : JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) File(java.io.File) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)

Aggregations

JavaParserTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver)23 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)22 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)22 File (java.io.File)20 CompilationUnit (com.github.javaparser.ast.CompilationUnit)9 Before (org.junit.Before)9 Test (org.junit.Test)8 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)6 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)6 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)5 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)4 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)3 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)3 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)3 SourceFileInfoExtractor (com.github.javaparser.symbolsolver.SourceFileInfoExtractor)3 LambdaExpr (com.github.javaparser.ast.expr.LambdaExpr)2 ResolvedReferenceType (com.github.javaparser.resolution.types.ResolvedReferenceType)2 Context (com.github.javaparser.symbolsolver.core.resolution.Context)2 LambdaExprContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext)2 Value (com.github.javaparser.symbolsolver.model.resolution.Value)2