Java Code Examples for com.github.javaparser.utils.SourceRoot

The following examples show how to use com.github.javaparser.utils.SourceRoot. 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: Apigcc.java    License: MIT License 6 votes vote down vote up
/**
 * 解析源代码
 *
 * @return
 */
public Project parse() {
    for (Path source : this.context.getSources()) {
        SourceRoot root = new SourceRoot(source, parserConfiguration);
        try {
            for (ParseResult<CompilationUnit> result : root.tryToParse()) {
                if (result.isSuccessful() && result.getResult().isPresent()) {
                    result.getResult().get().accept(visitorParser, project);
                }
            }
        } catch (IOException e) {
            log.warn("parse root {} error {}", source, e.getMessage());
        }
    }
    return project;
}
 
Example 2
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 3
Source Project: flow   Source File: OpenApiObjectGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private void parseSourceRoot(SourceRoot sourceRoot) {
    try {
        sourceRoot.parse("", this::process);
    } catch (Exception e) {
        throw new IllegalStateException(String.format(
                "Can't parse the java files in the source root '%s'",
                sourceRoot), e);
    }
}
 
Example 4
Source Project: flow   Source File: OpenApiObjectGenerator.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("squid:S1172")
private SourceRoot.Callback.Result process(Path localPath,
        Path absolutePath, ParseResult<CompilationUnit> result) {
    result.ifSuccessful(compilationUnit -> compilationUnit.getPrimaryType()
            .filter(BodyDeclaration::isClassOrInterfaceDeclaration)
            .map(BodyDeclaration::asClassOrInterfaceDeclaration)
            .filter(classOrInterfaceDeclaration -> !classOrInterfaceDeclaration
                    .isInterface())
            .map(this::appendNestedClasses).orElse(Collections.emptyList())
            .forEach(classOrInterfaceDeclaration -> this.parseClass(
                    classOrInterfaceDeclaration, compilationUnit)));
    pathItems.forEach((pathName, pathItem) -> openApiModel.getPaths()
            .addPathItem(pathName, pathItem));
    return SourceRoot.Callback.Result.DONT_SAVE;
}
 
Example 5
public SourceProjectImpl(Path outputLocation) {
  this(new SourceRoot(outputLocation));
}
 
Example 6
public SourceProjectImpl(SourceRoot sourceRoot) {
  this.sourceRoot = sourceRoot;
  this.compilationUnitCache = new HashMap<>();
}