Search in sources :

Example 1 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project che by eclipse.

the class ASTProvider method createAST.

/**
     * Creates a new compilation unit AST.
     *
     * @param input the Java element for which to create the AST
     * @param progressMonitor the progress monitor
     * @return AST
     */
public static CompilationUnit createAST(final ITypeRoot input, final IProgressMonitor progressMonitor) {
    if (!hasSource(input))
        return null;
    if (progressMonitor != null && progressMonitor.isCanceled())
        return null;
    final CheASTParser parser = CheASTParser.newParser(SHARED_AST_LEVEL);
    parser.setResolveBindings(true);
    parser.setStatementsRecovery(SHARED_AST_STATEMENT_RECOVERY);
    parser.setBindingsRecovery(SHARED_BINDING_RECOVERY);
    parser.setSource(input);
    if (progressMonitor != null && progressMonitor.isCanceled())
        return null;
    final CompilationUnit[] root = new CompilationUnit[1];
    SafeRunner.run(new ISafeRunnable() {

        public void run() {
            try {
                if (progressMonitor != null && progressMonitor.isCanceled())
                    return;
                if (DEBUG)
                    System.err.println(getThreadName() + " - " + DEBUG_PREFIX + "creating AST for: " + //$NON-NLS-1$ //$NON-NLS-2$
                    input.getElementName());
                root[0] = (CompilationUnit) parser.createAST(progressMonitor);
                //mark as unmodifiable
                ASTNodes.setFlagsToAST(root[0], ASTNode.PROTECT);
            } catch (OperationCanceledException ex) {
                return;
            }
        }

        public void handleException(Throwable ex) {
            LOG.error(ex.getMessage(), ex);
        }
    });
    return root[0];
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) CheASTParser(org.eclipse.jdt.core.dom.CheASTParser)

Example 2 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project che by eclipse.

the class RefactoringHistoryService method fireRefactoringHistoryEvent.

private void fireRefactoringHistoryEvent(final RefactoringDescriptorProxy proxy, final int eventType) {
    Assert.isNotNull(proxy);
    final Object[] listeners = fHistoryListeners.getListeners();
    for (int index = 0; index < listeners.length; index++) {
        final IRefactoringHistoryListener listener = (IRefactoringHistoryListener) listeners[index];
        SafeRunner.run(new ISafeRunnable() {

            public void handleException(final Throwable throwable) {
                RefactoringCorePlugin.log(throwable);
            }

            public void run() throws Exception {
                listener.historyNotification(new RefactoringHistoryEvent(RefactoringHistoryService.this, eventType, proxy));
            }
        });
    }
}
Also used : RefactoringHistoryEvent(org.eclipse.ltk.core.refactoring.history.RefactoringHistoryEvent) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IRefactoringHistoryListener(org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryListener)

Example 3 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project che by eclipse.

the class RefactoringHistoryService method fireRefactoringExecutionEvent.

private void fireRefactoringExecutionEvent(final RefactoringDescriptorProxy proxy, final int eventType) {
    Assert.isNotNull(proxy);
    final Object[] listeners = fExecutionListeners.getListeners();
    for (int index = 0; index < listeners.length; index++) {
        final IRefactoringExecutionListener listener = (IRefactoringExecutionListener) listeners[index];
        SafeRunner.run(new ISafeRunnable() {

            public void handleException(final Throwable throwable) {
                RefactoringCorePlugin.log(throwable);
            }

            public void run() throws Exception {
                listener.executionNotification(new RefactoringExecutionEvent(RefactoringHistoryService.this, eventType, proxy));
            }
        });
    }
}
Also used : IRefactoringExecutionListener(org.eclipse.ltk.core.refactoring.history.IRefactoringExecutionListener) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) RefactoringExecutionEvent(org.eclipse.ltk.core.refactoring.history.RefactoringExecutionEvent)

Example 4 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project che by eclipse.

the class UndoManager2 method fireChangePerformed.

private void fireChangePerformed(final Change change) {
    if (fListeners == null)
        return;
    Object[] listeners = fListeners.getListeners();
    for (int i = 0; i < listeners.length; i++) {
        final IUndoManagerListener listener = (IUndoManagerListener) listeners[i];
        SafeRunner.run(new ISafeRunnable() {

            public void run() throws Exception {
                listener.changePerformed(UndoManager2.this, change);
            }

            public void handleException(Throwable exception) {
                RefactoringCorePlugin.log(exception);
            }
        });
    }
}
Also used : IUndoManagerListener(org.eclipse.ltk.core.refactoring.IUndoManagerListener) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 5 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project che by eclipse.

the class UndoManager2 method fireRedoStackChanged.

private void fireRedoStackChanged() {
    if (fListeners == null)
        return;
    Object[] listeners = fListeners.getListeners();
    for (int i = 0; i < listeners.length; i++) {
        final IUndoManagerListener listener = (IUndoManagerListener) listeners[i];
        SafeRunner.run(new ISafeRunnable() {

            public void run() throws Exception {
                listener.redoStackChanged(UndoManager2.this);
            }

            public void handleException(Throwable exception) {
                RefactoringCorePlugin.log(exception);
            }
        });
    }
}
Also used : IUndoManagerListener(org.eclipse.ltk.core.refactoring.IUndoManagerListener) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)27 CoreException (org.eclipse.core.runtime.CoreException)23 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)11 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)5 ExecutionException (org.eclipse.core.commands.ExecutionException)4 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)4 IUndoManagerListener (org.eclipse.ltk.core.refactoring.IUndoManagerListener)4 ArrayList (java.util.ArrayList)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 ASTParser (org.eclipse.jdt.core.dom.ASTParser)3 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 PerformanceStats (org.eclipse.core.runtime.PerformanceStats)2 IElementChangedListener (org.eclipse.jdt.core.IElementChangedListener)2 IJavaElement (org.eclipse.jdt.core.IJavaElement)2