use of org.autorefactor.util.OnEclipseVersionUpgrade 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.OnEclipseVersionUpgrade 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;
}
Aggregations