Search in sources :

Example 41 with CombinedTypeSolver

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

the class SymbolSolverWithJavassistClassTest method setup.

@Before
public void setup() throws IOException {
    final String pathToMainJar = adaptPath("src/test/resources/javassist_symbols/main_jar/main_jar.jar");
    final String pathToIncludedJar = adaptPath("src/test/resources/javassist_symbols/included_jar/included_jar.jar");
    typeSolver = new CombinedTypeSolver(new JarTypeSolver(pathToIncludedJar), new JarTypeSolver(pathToMainJar), new ReflectionTypeSolver());
    symbolSolver = new SymbolSolver(typeSolver);
    classDeclarationConcreteClass = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.ConcreteClass");
    classDeclarationSubClassOwnJar = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.SubClassOwnJar");
    classDeclarationSubClassIncludedJar = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.SubClassIncludedJar");
    classDeclarationSubClassExcludedJar = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.SubClassExcludedJar");
    classDeclarationInterfaceUserOwnJar = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.InterfaceUserOwnJar");
    classDeclarationInterfaceUserIncludedJar = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.InterfaceUserIncludedJar");
    classDeclarationInterfaceUserExcludedJar = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.InterfaceUserExcludedJar");
}
Also used : JarTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) Before(org.junit.Before)

Example 42 with CombinedTypeSolver

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

the class JavassistEnumDeclarationTest method setup.

@Before
public void setup() throws IOException {
    String pathToJar = adaptPath("src/test/resources/javaparser-core-3.0.0-alpha.2.jar");
    typeSolver = new CombinedTypeSolver(new JarTypeSolver(pathToJar), new ReflectionTypeSolver());
    String anotherPathToJar = adaptPath("src/test/resources/test-artifact-1.0.0.jar");
    anotherTypeSolver = new CombinedTypeSolver(new JarTypeSolver(anotherPathToJar), new ReflectionTypeSolver());
}
Also used : JarTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) Before(org.junit.Before)

Example 43 with CombinedTypeSolver

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

the class MethodCallExprContextResolutionTest method assertCanSolveGenericMethodCallCanInferFromArguments.

private void assertCanSolveGenericMethodCallCanInferFromArguments(String callMethodName) {
    MethodCallExpr methodCallExpr = getMethodCallExpr("genericMethodTest", callMethodName);
    CombinedTypeSolver typeSolver = createTypeSolver();
    MethodCallExprContext context = new MethodCallExprContext(methodCallExpr, typeSolver);
    ResolvedReferenceTypeDeclaration stringType = typeSolver.solveType("java.lang.String");
    List<ResolvedType> argumentsTypes = new ArrayList<>();
    argumentsTypes.add(new ReferenceTypeImpl(stringType, typeSolver));
    Optional<MethodUsage> ref = context.solveMethodAsUsage(callMethodName, argumentsTypes, typeSolver);
    assertTrue(ref.isPresent());
    assertEquals("MethodCalls", ref.get().declaringType().getQualifiedName());
    assertEquals(Collections.singletonList("java.lang.String"), ref.get().typeParametersMap().getTypes().stream().map(ty -> ty.asReferenceType().describe()).collect(Collectors.toList()));
}
Also used : MethodCallExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext) ResolvedReferenceTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) ArrayList(java.util.ArrayList) MethodUsage(com.github.javaparser.resolution.MethodUsage) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 44 with CombinedTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver 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)

Example 45 with CombinedTypeSolver

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

the class MethodCallExprContextResolutionTest method solveNestedMethodCallExprContextWithoutScope.

@Test
public void solveNestedMethodCallExprContextWithoutScope() {
    MethodCallExpr methodCallExpr = getMethodCallExpr("bar1", "foo");
    CombinedTypeSolver typeSolver = createTypeSolver();
    Context context = new MethodCallExprContext(methodCallExpr, typeSolver);
    Optional<MethodUsage> ref = context.solveMethodAsUsage("foo", Collections.emptyList(), typeSolver);
    assertTrue(ref.isPresent());
    assertEquals("MethodCalls", ref.get().declaringType().getQualifiedName());
}
Also used : Context(com.github.javaparser.symbolsolver.core.resolution.Context) MethodCallExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext) MethodCallExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext) MethodUsage(com.github.javaparser.resolution.MethodUsage) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Aggregations

CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)49 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)46 CompilationUnit (com.github.javaparser.ast.CompilationUnit)23 JavaParserTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver)22 Test (org.junit.Test)21 File (java.io.File)20 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)19 JarTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver)15 Before (org.junit.Before)15 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)12 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)11 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)9 MethodUsage (com.github.javaparser.resolution.MethodUsage)9 Context (com.github.javaparser.symbolsolver.core.resolution.Context)9 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)6 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)6 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)6 Value (com.github.javaparser.symbolsolver.model.resolution.Value)4 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)3 SourceFileInfoExtractor (com.github.javaparser.symbolsolver.SourceFileInfoExtractor)3