1 package com.github.javaparser.symbolsolver;
2 
3 import com.github.javaparser.JavaParser;
4 import com.github.javaparser.ParseStart;
5 import com.github.javaparser.StreamProvider;
6 import com.github.javaparser.ast.CompilationUnit;
7 import com.github.javaparser.ast.expr.MethodCallExpr;
8 import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
9 import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
10 import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver;
11 import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
12 import com.github.javaparser.symbolsolver.utils.LeanParserConfiguration;
13 import org.junit.jupiter.api.Test;
14 
15 import java.io.IOException;
16 import java.nio.file.Files;
17 import java.nio.file.Path;
18 
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 
21 class Issue1485Test extends AbstractSymbolResolutionTest {
22 
23     @Test
issue1485withoutSpecifyingJARs()24     void issue1485withoutSpecifyingJARs() throws IOException {
25         Path dir = adaptPath("src/test/resources/issue1485");
26         Path file = adaptPath("src/test/resources/issue1485/Complex.java");
27 
28         CombinedTypeSolver typeSolver = new CombinedTypeSolver();
29         typeSolver.add(new ReflectionTypeSolver());
30         typeSolver.add(new JavaParserTypeSolver(dir, new LeanParserConfiguration()));
31 
32         JavaParser javaParser = new JavaParser();
33         javaParser.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver));
34 
35         CompilationUnit unit = javaParser.parse(ParseStart.COMPILATION_UNIT,
36                 new StreamProvider(Files.newInputStream(file))).getResult().get();
37 
38         MethodCallExpr methodCallExpr = unit.findFirst(MethodCallExpr.class, m -> m.getName().getIdentifier().equals("println")).get();
39         ResolvedMethodDeclaration resolvedMethodDeclaration = methodCallExpr.resolve();
40         assertEquals("java.io.PrintStream.println(java.lang.String)", resolvedMethodDeclaration.getQualifiedSignature());
41     }
42 }