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);
}
}
});
}
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;
}
}
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();
}
}
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;
}
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);
}
}
Aggregations