Example usage for org.eclipse.jdt.internal.core.util CommentRecorderParser CommentRecorderParser

List of usage examples for org.eclipse.jdt.internal.core.util CommentRecorderParser CommentRecorderParser

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.util CommentRecorderParser CommentRecorderParser.

Prototype

public CommentRecorderParser(ProblemReporter problemReporter, boolean optimizeStringLiterals) 

Source Link

Usage

From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaCompilationUtils.java

License:Apache License

private static Parser createCommentRecorderParser(CompilerOptions options) {
    return new CommentRecorderParser(new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(),
            options, new DefaultProblemFactory()), false);
}

From source file:ch.uzh.ifi.seal.changedistiller.util.CompilationUtils.java

License:Apache License

private static Parser createCommentRecorderParser(CompilerOptions options) {
    Parser parser = new CommentRecorderParser(
            new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), options,
                    new DefaultProblemFactory()),
            false);// w  w w .j a va2 s  . co m
    return parser;
}

From source file:org.codehaus.jdt.groovy.integration.DefaultLanguageSupport.java

License:Open Source License

public Parser getParser(Object requestor, CompilerOptions compilerOptions, ProblemReporter problemReporter,
        boolean parseLiteralExpressionsAsConstants, int variant) {
    if (variant == 1) {
        return new Parser(problemReporter, parseLiteralExpressionsAsConstants);
    } else { // if (variant==2) {
        return new CommentRecorderParser(problemReporter, parseLiteralExpressionsAsConstants);
    }//from   ww  w  . j av  a2 s . co  m
}

From source file:org.eclipse.jdt.core.dom.CompilationUnitResolver.java

License:Open Source License

public static void parse(ICompilationUnit[] compilationUnits, ASTRequestor astRequestor, int apiLevel,
        Map options, int flags, IProgressMonitor monitor) {
    try {//from w ww .  jav  a  2s.c o m
        CompilerOptions compilerOptions = new CompilerOptions(options);
        compilerOptions.ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
        Parser parser = new CommentRecorderParser(
                new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions,
                        new DefaultProblemFactory()),
                false);
        int unitLength = compilationUnits.length;
        if (monitor != null)
            monitor.beginTask("", unitLength); //$NON-NLS-1$
        for (int i = 0; i < unitLength; i++) {
            org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) compilationUnits[i];
            CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0,
                    compilerOptions.maxProblemsPerUnit);
            CompilationUnitDeclaration compilationUnitDeclaration = parser.dietParse(sourceUnit,
                    compilationResult);

            if (compilationUnitDeclaration.ignoreMethodBodies) {
                compilationUnitDeclaration.ignoreFurtherInvestigation = true;
                // if initial diet parse did not work, no need to dig into method bodies.
                continue;
            }

            //fill the methods bodies in order for the code to be generated
            //real parse of the method....
            org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types;
            if (types != null) {
                for (int j = 0, typeLength = types.length; j < typeLength; j++) {
                    types[j].parseMethods(parser, compilationUnitDeclaration);
                }
            }

            // convert AST
            CompilationUnit node = convert(compilationUnitDeclaration, parser.scanner.getSource(), apiLevel,
                    options, false/*don't resolve binding*/, null/*no owner needed*/,
                    null/*no binding table needed*/, flags /* flags */, monitor, true);
            node.setTypeRoot(compilationUnits[i]);

            // accept AST
            astRequestor.acceptAST(compilationUnits[i], node);

            if (monitor != null)
                monitor.worked(1);
        }
    } finally {
        if (monitor != null)
            monitor.done();
    }
}

From source file:org.eclipse.jdt.core.dom.CompilationUnitResolver.java

License:Open Source License

public static void parse(String[] sourceUnits, String[] encodings, FileASTRequestor astRequestor, int apiLevel,
        Map options, int flags, IProgressMonitor monitor) {
    try {//w  w w.ja  v a  2 s.  co  m
        CompilerOptions compilerOptions = new CompilerOptions(options);
        compilerOptions.ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
        Parser parser = new CommentRecorderParser(
                new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions,
                        new DefaultProblemFactory()),
                false);
        int unitLength = sourceUnits.length;
        if (monitor != null)
            monitor.beginTask("", unitLength); //$NON-NLS-1$
        for (int i = 0; i < unitLength; i++) {
            char[] contents = null;
            String encoding = encodings != null ? encodings[i] : null;
            try {
                contents = Util.getFileCharContent(new File(sourceUnits[i]), encoding);
            } catch (IOException e) {
                // go to the next unit
                continue;
            }
            if (contents == null) {
                // go to the next unit
                continue;
            }
            org.eclipse.jdt.internal.compiler.batch.CompilationUnit compilationUnit = new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(
                    contents, sourceUnits[i], encoding);
            org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = compilationUnit;
            CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0,
                    compilerOptions.maxProblemsPerUnit);
            CompilationUnitDeclaration compilationUnitDeclaration = parser.dietParse(sourceUnit,
                    compilationResult);

            if (compilationUnitDeclaration.ignoreMethodBodies) {
                compilationUnitDeclaration.ignoreFurtherInvestigation = true;
                // if initial diet parse did not work, no need to dig into method bodies.
                continue;
            }

            //fill the methods bodies in order for the code to be generated
            //real parse of the method....
            org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types;
            if (types != null) {
                for (int j = 0, typeLength = types.length; j < typeLength; j++) {
                    types[j].parseMethods(parser, compilationUnitDeclaration);
                }
            }

            // convert AST
            CompilationUnit node = convert(compilationUnitDeclaration, parser.scanner.getSource(), apiLevel,
                    options, false/*don't resolve binding*/, null/*no owner needed*/,
                    null/*no binding table needed*/, flags /* flags */, monitor, true);
            node.setTypeRoot(null);

            // accept AST
            astRequestor.acceptAST(sourceUnits[i], node);

            if (monitor != null)
                monitor.worked(1);
        }
    } finally {
        if (monitor != null)
            monitor.done();
    }
}