use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project structr by structr.
the class JavaParserModule method addJarsToIndex.
/**
* Add compilation units of all jar files found in the given folder to the index.
*
* @param folderPath
*/
public void addJarsToIndex(final String folderPath) {
logger.info("Starting adding jar files in " + folderPath);
final CombinedTypeSolver typeSolver = new CombinedTypeSolver();
typeSolver.add(new ReflectionTypeSolver());
final AtomicLong count = new AtomicLong(0);
try {
Files.newDirectoryStream(Paths.get(folderPath), path -> path.toString().endsWith(".jar")).forEach((file) -> {
try {
typeSolver.add(new JarTypeSolver(new FileInputStream(file.toFile())));
count.addAndGet(1L);
} catch (IOException ex) {
}
});
} catch (IOException ex) {
}
logger.info("Added " + count.toString() + " jar files to the type solver");
typeSolver.add(structrTypeSolver);
facade = JavaParserFacade.get(typeSolver);
logger.info("Done with adding jar files in " + folderPath);
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project javaparser by javaparser.
the class Issue144 method issue144WithCombinedTypeSolver.
@Test
public void issue144WithCombinedTypeSolver() {
CompilationUnit cu = parseSampleWithStandardExtension("issue144/HelloWorld");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "HelloWorld");
ExpressionStmt expressionStmt = (ExpressionStmt) clazz.getMethodsByName("main").get(0).getBody().get().getStatement(0);
MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression();
Expression firstParameter = methodCallExpr.getArgument(0);
JavaParserFacade javaParserFacade = JavaParserFacade.get(new CombinedTypeSolver(typeSolver, new ReflectionTypeSolver(true)));
assertEquals(true, javaParserFacade.solve(firstParameter).isSolved());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver 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);
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project javaparser by javaparser.
the class SymbolSolverWithJavassistEnumTest 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);
enumDeclarationConcrete = (JavassistEnumDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.ConcreteEnum");
enumDeclarationInterfaceUserOwnJar = (JavassistEnumDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.EnumInterfaceUserOwnJar");
enumDeclarationInterfaceUserIncludedJar = (JavassistEnumDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.EnumInterfaceUserIncludedJar");
enumDeclarationInterfaceUserExcludedJar = (JavassistEnumDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.EnumInterfaceUserExcludedJar");
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver 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());
}
Aggregations