Example usage for org.eclipse.jdt.core.compiler CompilationParticipant processAnnotations

List of usage examples for org.eclipse.jdt.core.compiler CompilationParticipant processAnnotations

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.compiler CompilationParticipant processAnnotations.

Prototype

public void processAnnotations(BuildContext[] files) 

Source Link

Document

Notifies this participant that a compile operation has found source files using Annotations.

Usage

From source file:org.eclipse.ajdt.core.builder.AJBuilder.java

License:Open Source License

/**
 * Performs post build actions including calling listeners and handling compilation participants
 * //w  w  w.j  a v a2s.c o m
 * returns any extra problems to be applied for this build
 */
private void postBuild(int kind, boolean noSourceChanges, CompilationParticipant[] participants,
        AjCompiler compiler) {

    final IJavaProject javaProject = JavaCore.create(getProject());
    Map<IFile, List<CategorizedProblem>> newProblems = Collections.emptyMap();

    // now handle participants
    if (participants != null) {
        if (noSourceChanges) {
            for (final CompilationParticipant participant : participants) {
                // from ReconcileWorkingCopyOperation
                SafeRunner.run(new ISafeRunnable() {
                    public void handleException(Throwable exception) {
                        if (exception instanceof Error) {
                            throw (Error) exception; // errors are not supposed to be caught
                        } else if (exception instanceof OperationCanceledException)
                            throw (OperationCanceledException) exception;
                        else if (exception instanceof UnsupportedOperationException) {
                            // might want to disable participant as it tried to modify the buffer of the working copy being reconciled
                            Util.log(exception,
                                    "Reconcile participant attempted to modify the buffer of the working copy being reconciled"); //$NON-NLS-1$
                        } else
                            Util.log(exception, "Exception occurred in reconcile participant"); //$NON-NLS-1$
                    }

                    public void run() throws Exception {
                        participant.buildStarting(new CompilationParticipantResult[0], false);
                        participant.buildFinished(javaProject);
                    }
                });
            }
        } else {
            // first calculate the CompilationParticipantResults
            final BuildContext[] results = calculateCompilationParticipantResults(
                    (CoreCompilerConfiguration) compiler.getCompilerConfiguration());
            for (final CompilationParticipant participant : participants) {
                SafeRunner.run(new ISafeRunnable() {
                    public void handleException(Throwable exception) {
                        if (exception instanceof Error) {
                            throw (Error) exception; // errors are not supposed to be caught
                        } else if (exception instanceof OperationCanceledException)
                            throw (OperationCanceledException) exception;
                        else if (exception instanceof UnsupportedOperationException) {
                            // might want to disable participant as it tried to modify the buffer of the working copy being reconciled
                            Util.log(exception,
                                    "Reconcile participant attempted to modify the buffer of the working copy being reconciled"); //$NON-NLS-1$
                        } else
                            Util.log(exception, "Exception occurred in reconcile participant"); //$NON-NLS-1$
                    }

                    public void run() throws Exception {
                        participant.buildStarting(results, false);
                        if (participant.isAnnotationProcessor()) {
                            participant.processAnnotations(results);
                        }
                        participant.buildFinished(javaProject);
                    }
                });
            }

            // extra problems and new dependencies
            newProblems = new HashMap<IFile, List<CategorizedProblem>>();
            for (int i = 0; i < results.length; i++) {
                AJCompilationParticipantResult result = (AJCompilationParticipantResult) results[i];
                // Bug 349963---why is result null?
                if (result == null) {
                    continue;
                }
                List<CategorizedProblem> problems = result.getProblems();
                if (problems != null) {
                    newProblems.put(result.getFile(), problems);
                }

                String[] dependencies = result.getDependencies();
                if (dependencies != null && dependencies.length > 0) {
                    compiler.addDependencies(result.getFile().getLocation().toFile(), dependencies);
                }
            }
        }
    }
    postCallListeners(kind, noSourceChanges, newProblems);
    ((CoreCompilerConfiguration) compiler.getCompilerConfiguration()).buildComplete();
}