Java Code Examples for com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver

The following examples show how to use com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: apigcc   Source File: Context.java    License: MIT License 6 votes vote down vote up
/**
 * 构建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;
}
 
Example 2
Source Project: jeddict   Source File: SourceExplorer.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source Project: Refactoring-Bot   Source File: RemoveMethodParameter.java    License: MIT License 5 votes vote down vote up
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);
}
 
Example 4
Source Project: Refactoring-Bot   Source File: RenameMethod.java    License: MIT License 5 votes vote down vote up
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);
}
 
Example 5
Source Project: Refactoring-Bot   Source File: RefactoringHelperTest.java    License: MIT License 5 votes vote down vote up
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);
}
 
Example 6
Source Project: flow   Source File: OpenApiObjectGenerator.java    License: Apache License 2.0 5 votes vote down vote up
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));
}