Search in sources :

Example 1 with ParserCollectionStrategy

use of com.github.javaparser.utils.ParserCollectionStrategy in project checker-framework by typetools.

the class JavaStubifier method process.

/**
 * Process each file in the given directory; see class documentation for details.
 *
 * @param dir directory to process
 */
private static void process(String dir) {
    Path root = dirnameToPath(dir);
    MinimizerCallback mc = new MinimizerCallback();
    CollectionStrategy strategy = new ParserCollectionStrategy();
    // Required to include directories that contain a module-info.java, which don't parse by
    // default.
    strategy.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_11);
    ProjectRoot projectRoot = strategy.collect(root);
    projectRoot.getSourceRoots().forEach(sourceRoot -> {
        try {
            sourceRoot.parse("", mc);
        } catch (IOException e) {
            System.err.println("IOException: " + e);
        }
    });
}
Also used : Path(java.nio.file.Path) CollectionStrategy(com.github.javaparser.utils.CollectionStrategy) ParserCollectionStrategy(com.github.javaparser.utils.ParserCollectionStrategy) ParserCollectionStrategy(com.github.javaparser.utils.ParserCollectionStrategy) ProjectRoot(com.github.javaparser.utils.ProjectRoot) IOException(java.io.IOException)

Example 2 with ParserCollectionStrategy

use of com.github.javaparser.utils.ParserCollectionStrategy in project checker-framework by typetools.

the class RemoveAnnotationsForInference method process.

/**
 * Process each file in the given directory; see the {@link RemoveAnnotationsForInference class
 * documentation} for details.
 *
 * @param dir directory to process
 */
private static void process(String dir) {
    Path root = JavaStubifier.dirnameToPath(dir);
    RemoveAnnotationsCallback rac = new RemoveAnnotationsCallback();
    CollectionStrategy strategy = new ParserCollectionStrategy();
    // Required to include directories that contain a module-info.java, which don't parse by
    // default.
    strategy.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_11);
    ProjectRoot projectRoot = strategy.collect(root);
    for (SourceRoot sourceRoot : projectRoot.getSourceRoots()) {
        try {
            sourceRoot.parse("", rac);
        } catch (IOException e) {
            throw new BugInCF(e);
        }
    }
}
Also used : ClassPath(com.google.common.reflect.ClassPath) Path(java.nio.file.Path) CollectionStrategy(com.github.javaparser.utils.CollectionStrategy) ParserCollectionStrategy(com.github.javaparser.utils.ParserCollectionStrategy) ParserCollectionStrategy(com.github.javaparser.utils.ParserCollectionStrategy) ProjectRoot(com.github.javaparser.utils.ProjectRoot) IOException(java.io.IOException) SourceRoot(com.github.javaparser.utils.SourceRoot) BugInCF(org.checkerframework.javacutil.BugInCF)

Aggregations

CollectionStrategy (com.github.javaparser.utils.CollectionStrategy)2 ParserCollectionStrategy (com.github.javaparser.utils.ParserCollectionStrategy)2 ProjectRoot (com.github.javaparser.utils.ProjectRoot)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 SourceRoot (com.github.javaparser.utils.SourceRoot)1 ClassPath (com.google.common.reflect.ClassPath)1 BugInCF (org.checkerframework.javacutil.BugInCF)1