Search in sources :

Example 1 with UnhandledException

use of org.autorefactor.util.UnhandledException in project AutoRefactor by JnRouvignac.

the class ChooseRefactoringWizardPage method createSelectAllCheckbox.

private void createSelectAllCheckbox(Composite parent) {
    selectAllVisibleCheckbox = new Button(parent, SWT.CHECK);
    selectAllVisibleCheckbox.setText("Toggle all the visible refactorings");
    selectAllVisibleCheckbox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            final Object[] visibleElements = filter(tableViewer, tableViewer.getInput());
            for (Object element : visibleElements) {
                setChecked(element, selectAllVisibleCheckbox.getSelection());
            }
        }

        private Object[] filter(StructuredViewer viewer, Object input) {
            try {
                final Class<StructuredViewer> clazz = StructuredViewer.class;
                Method m = clazz.getDeclaredMethod("filter", Object[].class);
                m.setAccessible(true);
                return (Object[]) m.invoke(viewer, (Object) ((List<?>) input).toArray());
            } catch (Exception e) {
                throw new UnhandledException(null, e);
            }
        }
    });
}
Also used : UnhandledException(org.autorefactor.util.UnhandledException) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Method(java.lang.reflect.Method) UnhandledException(org.autorefactor.util.UnhandledException)

Example 2 with UnhandledException

use of org.autorefactor.util.UnhandledException in project AutoRefactor by JnRouvignac.

the class DisplayEventLoop method syncExec.

@Override
public <E extends Exception> void syncExec(final Callable<E> call) throws E {
    final FutureTask<E> future = new FutureTask<E>(call);
    Display.getDefault().syncExec(future);
    final E ex;
    try {
        ex = future.get();
    } catch (ExecutionException e) {
        throw new UnhandledException(null, e.getCause());
    } catch (Exception e) {
        throw new UnhandledException(null, e);
    }
    if (ex != null) {
        throw ex;
    }
}
Also used : UnhandledException(org.autorefactor.util.UnhandledException) FutureTask(java.util.concurrent.FutureTask) ExecutionException(java.util.concurrent.ExecutionException) ExecutionException(java.util.concurrent.ExecutionException) UnhandledException(org.autorefactor.util.UnhandledException)

Example 3 with UnhandledException

use of org.autorefactor.util.UnhandledException in project AutoRefactor by JnRouvignac.

the class SuperCallRatherThanUselessOverridingRefactoring method isMethodUsedInItsPackage.

/** This method is extremely expensive. */
@OnEclipseVersionUpgrade("Replace monitor.newChild(1) by monitor.split(1)")
private boolean isMethodUsedInItsPackage(IMethodBinding methodBinding, MethodDeclaration node) {
    final IPackageBinding methodPackage = methodBinding.getDeclaringClass().getPackage();
    final AtomicBoolean methodIsUsedInPackage = new AtomicBoolean(false);
    final SearchRequestor requestor = new SearchRequestor() {

        @Override
        public void acceptSearchMatch(SearchMatch match) {
            methodIsUsedInPackage.set(true);
        }
    };
    final SubMonitor subMonitor = SubMonitor.convert(ctx.getProgressMonitor(), 1);
    final SubMonitor childMonitor = subMonitor.newChild(1);
    try {
        final SearchEngine searchEngine = new SearchEngine();
        searchEngine.search(createPattern(methodBinding.getJavaElement(), REFERENCES, R_EXACT_MATCH), new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createJavaSearchScope(new IJavaElement[] { methodPackage.getJavaElement() }), requestor, childMonitor);
        return methodIsUsedInPackage.get();
    } catch (CoreException e) {
        throw new UnhandledException(node, e);
    } finally {
        childMonitor.done();
    }
}
Also used : SearchRequestor(org.eclipse.jdt.core.search.SearchRequestor) UnhandledException(org.autorefactor.util.UnhandledException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IJavaElement(org.eclipse.jdt.core.IJavaElement) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CoreException(org.eclipse.core.runtime.CoreException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IPackageBinding(org.eclipse.jdt.core.dom.IPackageBinding) OnEclipseVersionUpgrade(org.autorefactor.util.OnEclipseVersionUpgrade)

Example 4 with UnhandledException

use of org.autorefactor.util.UnhandledException in project AutoRefactor by JnRouvignac.

the class ApplyRefactoringsJob method run0.

@OnEclipseVersionUpgrade({ "Remove the check to monitor.isCanceled()", "Replace monitor.newChild(1) by monitor.split(1)" })
private IStatus run0(IProgressMonitor monitor) throws Exception {
    if (refactoringUnits.isEmpty()) {
        // No java project exists.
        return Status.OK_STATUS;
    }
    final SubMonitor loopMonitor = SubMonitor.convert(monitor, refactoringUnits.size());
    try {
        RefactoringUnit toRefactor;
        while ((toRefactor = refactoringUnits.poll()) != null) {
            if (loopMonitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            final ICompilationUnit compilationUnit = toRefactor.getCompilationUnit();
            final JavaProjectOptions options = toRefactor.getOptions();
            try {
                loopMonitor.subTask("Applying refactorings to " + getClassName(compilationUnit));
                final AggregateASTVisitor refactoring = new AggregateASTVisitor(refactoringRulesToApply);
                applyRefactoring(compilationUnit, refactoring, options, loopMonitor.newChild(1));
            } catch (Exception e) {
                final String msg = "Exception when applying refactorings to file \"" + compilationUnit.getPath() + "\": " + e.getMessage();
                throw new UnhandledException(null, msg, e);
            }
        }
    } finally {
        loopMonitor.done();
    }
    return Status.OK_STATUS;
}
Also used : UnhandledException(org.autorefactor.util.UnhandledException) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SubMonitor(org.eclipse.core.runtime.SubMonitor) AggregateASTVisitor(org.autorefactor.refactoring.rules.AggregateASTVisitor) IllegalStateException(org.autorefactor.util.IllegalStateException) UnhandledException(org.autorefactor.util.UnhandledException) OnEclipseVersionUpgrade(org.autorefactor.util.OnEclipseVersionUpgrade)

Example 5 with UnhandledException

use of org.autorefactor.util.UnhandledException in project AutoRefactor by JnRouvignac.

the class PrepareApplyRefactoringsJob method collectRefactoringUnits.

private Queue<RefactoringUnit> collectRefactoringUnits(List<IJavaElement> javaElements) {
    try {
        final Queue<RefactoringUnit> results = new ConcurrentLinkedQueue<RefactoringUnit>();
        addAll(results, javaElements);
        return results;
    } catch (Exception e) {
        throw new UnhandledException(null, e);
    }
}
Also used : UnhandledException(org.autorefactor.util.UnhandledException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) NotImplementedException(org.autorefactor.util.NotImplementedException) JavaModelException(org.eclipse.jdt.core.JavaModelException) UnhandledException(org.autorefactor.util.UnhandledException)

Aggregations

UnhandledException (org.autorefactor.util.UnhandledException)6 OnEclipseVersionUpgrade (org.autorefactor.util.OnEclipseVersionUpgrade)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 ExecutionException (java.util.concurrent.ExecutionException)1 FutureTask (java.util.concurrent.FutureTask)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Matcher (java.util.regex.Matcher)1 AggregateASTVisitor (org.autorefactor.refactoring.rules.AggregateASTVisitor)1 IllegalStateException (org.autorefactor.util.IllegalStateException)1 NotImplementedException (org.autorefactor.util.NotImplementedException)1 CoreException (org.eclipse.core.runtime.CoreException)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IPackageBinding (org.eclipse.jdt.core.dom.IPackageBinding)1 SearchEngine (org.eclipse.jdt.core.search.SearchEngine)1