Search in sources :

Example 1 with OnEclipseVersionUpgrade

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();
    }
}
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 2 with OnEclipseVersionUpgrade

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

Aggregations

OnEclipseVersionUpgrade (org.autorefactor.util.OnEclipseVersionUpgrade)2 UnhandledException (org.autorefactor.util.UnhandledException)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AggregateASTVisitor (org.autorefactor.refactoring.rules.AggregateASTVisitor)1 IllegalStateException (org.autorefactor.util.IllegalStateException)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 SearchMatch (org.eclipse.jdt.core.search.SearchMatch)1 SearchRequestor (org.eclipse.jdt.core.search.SearchRequestor)1