Java源码示例:com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver
示例1
/**
* 构建TypeSolver
* @return
*/
public TypeSolver buildTypeSolver(){
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
for (Path dependency : dependencies) {
typeSolver.add(new JavaParserTypeSolver(dependency));
}
for (Path jar : jars) {
try {
typeSolver.add(new JarTypeSolver(jar));
} catch (IOException e) {
log.warn("exception on {} {}", jar, e.getMessage());
}
}
if (!codeTypeDeclarations.isEmpty()) {
for (CodeTypeDeclaration codeTypeDeclaration : codeTypeDeclarations) {
Path path = dependencyPath.resolve(codeTypeDeclaration.path());
FileHelper.write(path, codeTypeDeclaration.code());
}
typeSolver.add(new JavaParserTypeSolver(dependencyPath));
}
typeSolver.add(new ReflectionTypeSolver());
return typeSolver;
}
示例2
private void configureJavaParser(FileObject sourceRoot) {
// Set up a minimal type solver that only looks at the classes used to run this sample.
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new JavaParserTypeSolver(FileUtil.toFile(sourceRoot)));
combinedTypeSolver.add(new ReflectionTypeSolver());
SourceGroup sourceGroup = getFolderSourceGroup(sourceRoot);
Project project = FileOwnerQuery.getOwner(sourceRoot);
List<ClassLoader> classLoaders = getClassLoaders(project, sourceGroup);
for (ClassLoader classLoader : classLoaders) {
combinedTypeSolver.add(new ClassloaderTypeSolver(classLoader));
}
// Configure JavaParser to use type resolution
JavaSymbolSolver symbolSolver = new JavaSymbolSolver(combinedTypeSolver);
javaParser.getParserConfiguration().setSymbolResolver(symbolSolver);
}
示例3
private void configureJavaParserForProject(BotIssue issue) {
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
for (String javaRoot : issue.getJavaRoots()) {
typeSolver.add(new JavaParserTypeSolver(javaRoot));
}
typeSolver.add(new ReflectionTypeSolver());
JavaSymbolSolver javaSymbolSolver = new JavaSymbolSolver(typeSolver);
StaticJavaParser.getConfiguration().setSymbolResolver(javaSymbolSolver);
}
示例4
private void configureJavaParserForProject(BotIssue issue) {
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
for (String javaRoot : issue.getJavaRoots()) {
typeSolver.add(new JavaParserTypeSolver(javaRoot));
}
typeSolver.add(new ReflectionTypeSolver());
JavaSymbolSolver javaSymbolSolver = new JavaSymbolSolver(typeSolver);
StaticJavaParser.getConfiguration().setSymbolResolver(javaSymbolSolver);
}
示例5
private void configureStaticJavaParserForResolving() {
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
String javaRoot = TestUtils.getAbsolutePathOfTestsFolder();
typeSolver.add(new JavaParserTypeSolver(javaRoot));
typeSolver.add(new ReflectionTypeSolver());
JavaSymbolSolver javaSymbolSolver = new JavaSymbolSolver(typeSolver);
StaticJavaParser.getConfiguration().setSymbolResolver(javaSymbolSolver);
}
示例6
private ParserConfiguration createParserConfiguration() {
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver(
new ReflectionTypeSolver(false));
if (typeResolverClassLoader != null) {
combinedTypeSolver
.add(new ClassLoaderTypeSolver(typeResolverClassLoader));
}
return new ParserConfiguration()
.setSymbolResolver(new JavaSymbolSolver(combinedTypeSolver));
}