Java Code Examples for com.github.javaparser.ParserConfiguration

The following examples show how to use com.github.javaparser.ParserConfiguration. 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: gradle-modules-plugin   Source File: ModuleName.java    License: MIT License 6 votes vote down vote up
private Optional<String> findModuleName(Path moduleInfoJava, String projectPath) {
    try {
        JavaParser parser = new JavaParser();
        parser.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_11);

        Optional<CompilationUnit> compilationUnit = parser.parse(moduleInfoJava).getResult();
        if (compilationUnit.isEmpty()) {
            LOGGER.debug("Project {} => compilation unit is empty", projectPath);
            return Optional.empty();
        }

        Optional<ModuleDeclaration> module = compilationUnit.get().getModule();
        if (module.isEmpty()) {
            LOGGER.warn("Project {} => module-info.java found, but module name could not be parsed", projectPath);
            return Optional.empty();
        }

        String name = module.get().getName().toString();
        LOGGER.lifecycle("Project {} => '{}' Java module", projectPath, name);
        return Optional.of(name);

    } catch (IOException e) {
        LOGGER.error("Project {} => error opening module-info.java at {}", projectPath, moduleInfoJava);
        return Optional.empty();
    }
}
 
Example 2
Source Project: Recaf   Source File: Workspace.java    License: MIT License 5 votes vote down vote up
/**
 * Creates a source config with a type resolver that can access all types in the workspace.
 */
public void updateSourceConfig() {
	TypeSolver solver = new WorkspaceTypeResolver(this);
	config = new ParserConfiguration()
			.setSymbolResolver(new JavaSymbolSolver(solver))
			.setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_14);
}
 
Example 3
Source Project: flow   Source File: OpenApiObjectGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private void init() {
    if (javaSourcePaths == null || configuration == null) {
        throw new IllegalStateException(
                "Java source path and configuration should not be null");
    }
    openApiModel = createBasicModel();
    nonEndpointMap = new HashMap<>();
    qualifiedNameToPath = new HashMap<>();
    pathItems = new TreeMap<>();
    usedTypes = new HashMap<>();
    generatedSchema = new HashSet<>();
    endpointsJavadoc = new HashMap<>();
    schemaResolver = new SchemaResolver();
    ParserConfiguration parserConfiguration = createParserConfiguration();


    javaSourcePaths.stream()
            .map(path -> new SourceRoot(path, parserConfiguration))
            .forEach(this::parseSourceRoot);

    for (Map.Entry<String, ResolvedReferenceType> entry : usedTypes
            .entrySet()) {
        List<Schema> schemas = createSchemasFromQualifiedNameAndType(
                entry.getKey(), entry.getValue());
        schemas.forEach(schema -> {
            if (qualifiedNameToPath.get(schema.getName()) != null) {
                schema.addExtension(EXTENSION_VAADIN_FILE_PATH,
                        qualifiedNameToPath.get(schema.getName()));
            }
            openApiModel.getComponents().addSchemas(schema.getName(),
                    schema);
        });
    }
    addTagsInformation();
}
 
Example 4
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));
}
 
Example 5
Source Project: Recaf   Source File: Workspace.java    License: MIT License 4 votes vote down vote up
/**
 * @return JavaParser config to assist in resolving symbols.
 */
public ParserConfiguration getSourceParseConfig() {
	if (config == null)
		updateSourceConfig();
	return config;
}