Search in sources :

Example 16 with JavaParserTypeSolver

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

the class SymbolSolverTest 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"))));
    typeSolverNewCode = combinedTypeSolverNewCode;
    symbolSolver = new SymbolSolver(typeSolverNewCode);
}
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 17 with JavaParserTypeSolver

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

the class VariadicResolutionTest method selectMostSpecificVariadic.

@Test
public void selectMostSpecificVariadic() {
    CompilationUnit cu = parseSample("MethodCalls");
    ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MethodCalls");
    MethodDeclaration method = Navigator.demandMethod(clazz, "variadicTest");
    List<MethodCallExpr> calls = method.findAll(MethodCallExpr.class);
    File src = adaptPath(new File("src/test/resources"));
    TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(src));
    JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
    MethodUsage call1 = javaParserFacade.solveMethodAsUsage(calls.get(0));
    MethodUsage call2 = javaParserFacade.solveMethodAsUsage(calls.get(1));
    assertEquals("int", call1.returnType().describe());
    assertEquals("void", call2.returnType().describe());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) TypeSolver(com.github.javaparser.symbolsolver.model.resolution.TypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) JavaParserFacade(com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade) MethodUsage(com.github.javaparser.resolution.MethodUsage) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) File(java.io.File) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Test(org.junit.Test)

Example 18 with JavaParserTypeSolver

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

the class JavaParserClassDeclarationTest method setup.

@Before
public void setup() {
    File src = adaptPath(new File("src/test/test_sourcecode/javaparser_src/proper_source"));
    CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
    combinedTypeSolver.add(new ReflectionTypeSolver());
    combinedTypeSolver.add(new JavaParserTypeSolver(src));
    combinedTypeSolver.add(new JavaParserTypeSolver(adaptPath(new File("src/test/test_sourcecode/javaparser_src/generated"))));
    typeSolver = combinedTypeSolver;
    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"))));
    typeSolverNewCode = combinedTypeSolverNewCode;
    TypeSolver ts = new ReflectionTypeSolver();
    string = new ReferenceTypeImpl(ts.solveType(String.class.getCanonicalName()), ts);
    ResolvedReferenceType booleanC = new ReferenceTypeImpl(ts.solveType(Boolean.class.getCanonicalName()), ts);
    listOfBoolean = new ReferenceTypeImpl(ts.solveType(List.class.getCanonicalName()), ImmutableList.of(booleanC), ts);
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) TypeSolver(com.github.javaparser.symbolsolver.model.resolution.TypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) 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 19 with JavaParserTypeSolver

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

the class JavaParserEnumDeclarationTest method setup.

@Before
public void setup() {
    File srcNewCode = adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-core"));
    CombinedTypeSolver combinedtypeSolver = new CombinedTypeSolver();
    combinedtypeSolver.add(new ReflectionTypeSolver());
    combinedtypeSolver.add(new JavaParserTypeSolver(srcNewCode));
    combinedtypeSolver.add(new JavaParserTypeSolver(adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-generated-sources"))));
    typeSolver = 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) Before(org.junit.Before)

Example 20 with JavaParserTypeSolver

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

the class JavaParserInterfaceDeclarationTest method setup.

@Before
public void setup() {
    File srcNewCode = adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-core"));
    CombinedTypeSolver combinedtypeSolver = new CombinedTypeSolver();
    combinedtypeSolver.add(new ReflectionTypeSolver());
    combinedtypeSolver.add(new JavaParserTypeSolver(srcNewCode));
    combinedtypeSolver.add(new JavaParserTypeSolver(adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-generated-sources"))));
    typeSolver = 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) Before(org.junit.Before)

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