Example usage for org.eclipse.jdt.internal.compiler CompilationResult getTasks

List of usage examples for org.eclipse.jdt.internal.compiler CompilationResult getTasks

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler CompilationResult getTasks.

Prototype

public CategorizedProblem[] getTasks() 

Source Link

Document

Answer the tasks (TO-DO, ...) encountered during compilation.

Usage

From source file:io.gige.compiler.internal.CompilerRequestorImpl.java

License:Apache License

@Override
public void acceptResult(CompilationResult result) {
    if (result.hasProblems()) {
        report(Kind.ERROR, result.getErrors());
    }// w w w.  j av  a  2s.  c  o  m
    if (result.hasTasks()) {
        report(Kind.NOTE, result.getTasks());
    }
    try {
        for (ClassFile cf : result.getClassFiles()) {
            String className = new String(cf.fileName());
            JavaFileObject obj = this.manager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, className,
                    javax.tools.JavaFileObject.Kind.CLASS, null);
            try (OutputStream out = obj.openOutputStream()) {
                out.write(cf.getBytes());
            }
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:net.sf.j2s.core.builder.AbstractImageBuilder.java

License:Open Source License

protected void updateTasksFor(SourceFile sourceFile, CompilationResult result) throws CoreException {
    CategorizedProblem[] tasks = result.getTasks();
    if (tasks == null || tasks.length == 0)
        return;/*  w  w  w  .  j  a v a 2 s .  co  m*/

    storeTasksFor(sourceFile, tasks);
}

From source file:net.sf.j2s.core.builder.IncrementalImageBuilder.java

License:Open Source License

protected void updateTasksFor(SourceFile sourceFile, CompilationResult result) throws CoreException {
    IMarker[] markers = JavaBuilder.getTasksFor(sourceFile.resource);
    CategorizedProblem[] tasks = result.getTasks();
    if (tasks == null && markers.length == 0)
        return;/*from w  ww  . ja v  a 2  s. c o  m*/

    JavaBuilder.removeTasksFor(sourceFile.resource);
    storeTasksFor(sourceFile, tasks);
}

From source file:org.eclipse.ajdt.core.parserbridge.AJCompilationUnitProblemFinder.java

License:Open Source License

public static CompilationUnitDeclaration processAJ( // AspectJ Change
        CompilationUnit unitElement, // AspectJ Change
        CommentRecorderParser parser, // AspectJ Change
        WorkingCopyOwner workingCopyOwner, HashMap<String, CategorizedProblem[]> problems, boolean creatingAST,
        int reconcileFlags, IProgressMonitor monitor) throws JavaModelException {

    boolean isJavaFileInAJEditor = (reconcileFlags & JAVA_FILE_IN_AJ_EDITOR) != 0;

    JavaProject project = (JavaProject) unitElement.getJavaProject();
    ITDAwareNameEnvironment environment = null;
    CancelableProblemFactory problemFactory = null;
    AJCompilationUnitProblemFinder problemFinder = null; // AspectJ Change
    try {/* ww  w . j a  v  a2 s .c om*/

        // AspectJ Change begin
        // use an ITDAware environment to ensure that ITDs are included for source types
        environment = new ITDAwareNameEnvironment(project, workingCopyOwner, monitor);
        // AspectJ Change end

        problemFactory = new CancelableProblemFactory(monitor);
        problemFinder = new AJCompilationUnitProblemFinder( // AspectJ Change
                environment, getHandlingPolicy(),
                getCompilerOptions(project.getOptions(true), creatingAST,
                        ((reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0)),
                getRequestor(), problemFactory, unitElement);
        CompilationUnitDeclaration unit = null;

        // AspectJ Change begin 
        // the parser should be a SourceElementParser or AJSourceElementParser2.
        // this ensures that a diet parse can be done, while at the same time
        // all declarations be reported
        if (parser != null) {
            problemFinder.parser = parser;
        }
        try {
            if (problemFinder.parser instanceof SourceElementParser) {
                unit = ((SourceElementParser) problemFinder.parser).parseCompilationUnit(unitElement,
                        true/* full parse */, monitor);
                problemFinder.resolve(unit, unitElement, true, // verify methods
                        true, // analyze code
                        true); // generate code
            } else if (problemFinder.parser instanceof AJSourceElementParser2) {
                unit = ((AJSourceElementParser2) problemFinder.parser).parseCompilationUnit(unitElement,
                        true/* full parse */, monitor);
                problemFinder.resolve(unit, unitElement, true, // verify methods
                        true, // analyze code
                        true); // generate code
            } else {
                unit = problemFinder.resolve(unitElement, true, // verify methods
                        true, // analyze code
                        true); // generate code
            }

        } catch (AbortCompilation e) {
            problemFinder.handleInternalException(e, unit);
        }

        // revert the compilation units that have ITDs in them
        ((ITDAwareLookupEnvironment) problemFinder.lookupEnvironment).revertCompilationUnits();
        // AspectJ Change end

        CompilationResult unitResult = unit.compilationResult;
        CategorizedProblem[] unitProblems = unitResult.getProblems();
        int length = unitProblems == null ? 0 : unitProblems.length;
        if (length > 0) {
            // AspectJ Change begin
            // filter out spurious problems
            CategorizedProblem[] categorizedProblems = new CategorizedProblem[length];
            System.arraycopy(unitProblems, 0, categorizedProblems, 0, length);
            categorizedProblems = removeAJNonProblems(categorizedProblems, unitElement, isJavaFileInAJEditor);
            if (categorizedProblems.length > 0) {
                problems.put(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, categorizedProblems);
            }
            // AspectJ Change end
        }
        unitProblems = unitResult.getTasks();
        length = unitProblems == null ? 0 : unitProblems.length;
        if (length > 0) {
            CategorizedProblem[] categorizedProblems = new CategorizedProblem[length];
            System.arraycopy(unitProblems, 0, categorizedProblems, 0, length);
            problems.put(IJavaModelMarker.TASK_MARKER, categorizedProblems);
        }
        if (NameLookup.VERBOSE) {
            AJLog.log(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " //$NON-NLS-1$
                    + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$
            AJLog.log(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " //$NON-NLS-1$
                    + environment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$
        }
        return unit;
    } catch (OperationCanceledException e) {
        // catch this exception so as to not enter the
        // catch(RuntimeException e) below
        throw e;
    } catch (RuntimeException e) {
        String message = handleException(unitElement, environment, e);
        throw new JavaModelException(new RuntimeException(message, e),
                IJavaModelStatusConstants.COMPILER_FAILURE);

    } finally {
        if (environment != null)
            environment.setMonitor(null); // AJDT 3.6 // don't hold a reference to this
                                          // external object
        if (problemFactory != null)
            problemFactory.monitor = null; // don't hold a reference to this
                                           // external object
                                           // NB: unit.cleanUp() is done by caller
        if (problemFinder != null && !creatingAST)
            problemFinder.lookupEnvironment.reset();
    }
}

From source file:org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.java

License:Open Source License

public static CompilationUnitDeclaration process(CompilationUnit unitElement, SourceElementParser parser,
        WorkingCopyOwner workingCopyOwner, HashMap problems, boolean creatingAST, int reconcileFlags,
        IProgressMonitor monitor) throws JavaModelException {

    JavaProject project = (JavaProject) unitElement.getJavaProject();
    CancelableNameEnvironment environment = null;
    CancelableProblemFactory problemFactory = null;
    CompilationUnitProblemFinder problemFinder = null;
    CompilationUnitDeclaration unit = null;
    try {/*from ww w .  j  a  v  a  2s  .  c  om*/
        environment = new CancelableNameEnvironment(project, workingCopyOwner, monitor);
        problemFactory = new CancelableProblemFactory(monitor);
        CompilerOptions compilerOptions = getCompilerOptions(project.getOptions(true), creatingAST,
                ((reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0));
        boolean ignoreMethodBodies = (reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
        compilerOptions.ignoreMethodBodies = ignoreMethodBodies;
        // GROOVY start
        // options fetched prior to building problem finder then configured based on project
        CompilerUtils.configureOptionsBasedOnNature(compilerOptions, project);
        // GROOVY end
        problemFinder = new CompilationUnitProblemFinder(environment, getHandlingPolicy(), compilerOptions,
                getRequestor(), problemFactory);
        boolean analyzeAndGenerateCode = true;
        if (ignoreMethodBodies) {
            analyzeAndGenerateCode = false;
        }
        try {
            if (parser != null) {
                problemFinder.parser = parser;
                unit = parser.parseCompilationUnit(unitElement, true/*full parse*/, monitor);
                problemFinder.resolve(unit, unitElement, true, // verify methods
                        analyzeAndGenerateCode, // analyze code
                        analyzeAndGenerateCode); // generate code
            } else {
                unit = problemFinder.resolve(unitElement, true, // verify methods
                        analyzeAndGenerateCode, // analyze code
                        analyzeAndGenerateCode); // generate code
            }
        } catch (AbortCompilation e) {
            problemFinder.handleInternalException(e, unit);
        }
        if (unit != null) {
            CompilationResult unitResult = unit.compilationResult;
            CategorizedProblem[] unitProblems = unitResult.getProblems();
            int length = unitProblems == null ? 0 : unitProblems.length;
            if (length > 0) {
                CategorizedProblem[] categorizedProblems = new CategorizedProblem[length];
                System.arraycopy(unitProblems, 0, categorizedProblems, 0, length);
                problems.put(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, categorizedProblems);
            }
            unitProblems = unitResult.getTasks();
            length = unitProblems == null ? 0 : unitProblems.length;
            if (length > 0) {
                CategorizedProblem[] categorizedProblems = new CategorizedProblem[length];
                System.arraycopy(unitProblems, 0, categorizedProblems, 0, length);
                problems.put(IJavaModelMarker.TASK_MARKER, categorizedProblems);
            }
            if (NameLookup.VERBOSE) {
                System.out.println(
                        Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " //$NON-NLS-1$
                                + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$
                System.out.println(
                        Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " //$NON-NLS-1$
                                + environment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$
            }
        }
    } catch (OperationCanceledException e) {
        // catch this exception so as to not enter the catch(RuntimeException e) below
        throw e;
    } catch (RuntimeException e) {
        // avoid breaking other tools due to internal compiler failure (40334)
        String lineDelimiter = unitElement.findRecommendedLineSeparator();
        StringBuffer message = new StringBuffer("Exception occurred during problem detection:"); //$NON-NLS-1$
        message.append(lineDelimiter);
        message.append(
                "----------------------------------- SOURCE BEGIN -------------------------------------"); //$NON-NLS-1$
        message.append(lineDelimiter);
        message.append(unitElement.getSource());
        message.append(lineDelimiter);
        message.append("----------------------------------- SOURCE END -------------------------------------"); //$NON-NLS-1$
        Util.log(e, message.toString());
        throw new JavaModelException(e, IJavaModelStatusConstants.COMPILER_FAILURE);
    } finally {
        if (environment != null)
            environment.setMonitor(null); // don't hold a reference to this external object
        if (problemFactory != null)
            problemFactory.monitor = null; // don't hold a reference to this external object
        // NB: unit.cleanUp() is done by caller
        if (problemFinder != null && !creatingAST)
            problemFinder.lookupEnvironment.reset();
    }
    return unit;
}