Search in sources :

Example 1 with EcjTreeConverter

use of lombok.ast.ecj.EcjTreeConverter in project android by JetBrains.

the class LombokPsiConverterTest method parse.

@Nullable
private static Node parse(String code) {
    CompilerOptions options = new CompilerOptions();
    options.complianceLevel = options.sourceLevel = options.targetJDK = ClassFileConstants.JDK1_7;
    options.parseLiteralExpressionsAsConstants = true;
    ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.exitOnFirstError(), options, new DefaultProblemFactory());
    Parser parser = new Parser(problemReporter, options.parseLiteralExpressionsAsConstants);
    parser.javadocParser.checkDocComment = false;
    EcjTreeConverter converter = new EcjTreeConverter();
    org.eclipse.jdt.internal.compiler.batch.CompilationUnit sourceUnit = new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(code.toCharArray(), "unitTest", "UTF-8");
    CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
    CompilationUnitDeclaration unit = parser.parse(sourceUnit, compilationResult);
    if (unit == null) {
        return null;
    }
    converter.visit(code, unit);
    List<? extends Node> nodes = converter.getAll();
    for (lombok.ast.Node node : nodes) {
        if (node instanceof lombok.ast.CompilationUnit) {
            return node;
        }
    }
    return null;
}
Also used : CompilationUnit(lombok.ast.CompilationUnit) ProblemReporter(org.eclipse.jdt.internal.compiler.problem.ProblemReporter) Node(lombok.ast.Node) Parser(org.eclipse.jdt.internal.compiler.parser.Parser) EcjTreeConverter(lombok.ast.ecj.EcjTreeConverter) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) DefaultProblemFactory(org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory) CompilationResult(org.eclipse.jdt.internal.compiler.CompilationResult) Nullable(com.android.annotations.Nullable)

Aggregations

Nullable (com.android.annotations.Nullable)1 CompilationUnit (lombok.ast.CompilationUnit)1 Node (lombok.ast.Node)1 EcjTreeConverter (lombok.ast.ecj.EcjTreeConverter)1 CompilationResult (org.eclipse.jdt.internal.compiler.CompilationResult)1 CompilationUnitDeclaration (org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration)1 CompilerOptions (org.eclipse.jdt.internal.compiler.impl.CompilerOptions)1 Parser (org.eclipse.jdt.internal.compiler.parser.Parser)1 DefaultProblemFactory (org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory)1 ProblemReporter (org.eclipse.jdt.internal.compiler.problem.ProblemReporter)1