Search in sources :

Example 1 with SourceRoot

use of com.github.javaparser.utils.SourceRoot in project javaparser by javaparser.

the class MetaModelGenerator method main.

public static void main(String[] args) throws IOException, NoSuchMethodException {
    if (args.length != 1) {
        throw new RuntimeException("Need 1 parameter: the JavaParser source checkout root directory.");
    }
    final Path root = Paths.get(args[0], "..", "javaparser-core", "src", "main", "java");
    final SourceRoot sourceRoot = new SourceRoot(root);
    sourceRoot.setPrinter(new PrettyPrinter(new PrettyPrinterConfiguration().setEndOfLineCharacter("\n"))::print);
    new MetaModelGenerator().run(sourceRoot);
    sourceRoot.saveAll();
}
Also used : Path(java.nio.file.Path) PrettyPrinter(com.github.javaparser.printer.PrettyPrinter) SourceRoot(com.github.javaparser.utils.SourceRoot) PrettyPrinterConfiguration(com.github.javaparser.printer.PrettyPrinterConfiguration)

Example 2 with SourceRoot

use of com.github.javaparser.utils.SourceRoot in project javaparser by javaparser.

the class SymbolSolverQuickSetupTest method notResolve.

@Test(expected = IllegalStateException.class)
public void notResolve() throws IOException {
    SourceRoot sourceRoot = new SourceRoot(root);
    sourceRoot.tryToParse();
    // try to resolve, this will fail
    sourceRoot.getCompilationUnits().forEach(compilationUnit -> compilationUnit.findAll(ClassOrInterfaceDeclaration.class).forEach(ClassOrInterfaceDeclaration::resolve));
}
Also used : SourceRoot(com.github.javaparser.utils.SourceRoot) Test(org.junit.Test)

Example 3 with SourceRoot

use of com.github.javaparser.utils.SourceRoot in project javaparser by javaparser.

the class SymbolSolverQuickSetupTest method resolve.

@Test
public void resolve() throws IOException {
    SourceRoot sourceRoot = new SourceRoot(root, parserConfiguration);
    sourceRoot.tryToParse();
    // try to resolve, this should succeed
    sourceRoot.getCompilationUnits().forEach(compilationUnit -> compilationUnit.findAll(ClassOrInterfaceDeclaration.class).forEach(ClassOrInterfaceDeclaration::resolve));
}
Also used : SourceRoot(com.github.javaparser.utils.SourceRoot) Test(org.junit.Test)

Example 4 with SourceRoot

use of com.github.javaparser.utils.SourceRoot in project javaparser by javaparser.

the class CoreGenerator method main.

public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        throw new RuntimeException("Need 1 parameter: the JavaParser source checkout root directory.");
    }
    Log.setAdapter(new Log.StandardOutStandardErrorAdapter());
    final Path root = Paths.get(args[0], "..", "javaparser-core", "src", "main", "java");
    final SourceRoot sourceRoot = new SourceRoot(root, parserConfiguration);
    final Path generatedJavaCcRoot = Paths.get(args[0], "..", "javaparser-core", "target", "generated-sources", "javacc");
    final SourceRoot generatedJavaCcSourceRoot = new SourceRoot(generatedJavaCcRoot, parserConfiguration);
    new CoreGenerator().run(sourceRoot, generatedJavaCcSourceRoot);
    sourceRoot.saveAll();
}
Also used : Path(java.nio.file.Path) Log(com.github.javaparser.utils.Log) SourceRoot(com.github.javaparser.utils.SourceRoot)

Example 5 with SourceRoot

use of com.github.javaparser.utils.SourceRoot 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

SourceRoot (com.github.javaparser.utils.SourceRoot)6 Path (java.nio.file.Path)4 Test (org.junit.Test)2 ParseResult (com.github.javaparser.ParseResult)1 ParserConfiguration (com.github.javaparser.ParserConfiguration)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 NodeList (com.github.javaparser.ast.NodeList)1 BodyDeclaration (com.github.javaparser.ast.body.BodyDeclaration)1 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)1 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)1 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 Parameter (com.github.javaparser.ast.body.Parameter)1 TypeDeclaration (com.github.javaparser.ast.body.TypeDeclaration)1 AnnotationExpr (com.github.javaparser.ast.expr.AnnotationExpr)1 Expression (com.github.javaparser.ast.expr.Expression)1 LiteralStringValueExpr (com.github.javaparser.ast.expr.LiteralStringValueExpr)1 SingleMemberAnnotationExpr (com.github.javaparser.ast.expr.SingleMemberAnnotationExpr)1 NodeWithSimpleName (com.github.javaparser.ast.nodeTypes.NodeWithSimpleName)1 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)1 Type (com.github.javaparser.ast.type.Type)1