|
31 | 31 | import org.eclipse.core.resources.IProject; |
32 | 32 | import org.eclipse.core.runtime.CoreException; |
33 | 33 | import org.eclipse.core.runtime.IProgressMonitor; |
| 34 | +import org.eclipse.core.runtime.ProgressMonitorWrapper; |
34 | 35 | import org.eclipse.core.runtime.SubMonitor; |
35 | 36 | import org.eclipse.jdt.core.IJavaProject; |
36 | 37 | import org.eclipse.jdt.core.JavaCore; |
@@ -187,8 +188,27 @@ private boolean isPackageReferenced(ImportPackageObject pkg, IJavaProject javaPr |
187 | 188 | SearchPattern pattern = SearchPattern.createPattern(packageName, IJavaSearchConstants.PACKAGE, |
188 | 189 | IJavaSearchConstants.REFERENCES, SearchPattern.R_EXACT_MATCH); |
189 | 190 | if (pattern != null) { |
190 | | - engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, |
191 | | - searchScope, requestor, monitor); |
| 191 | + ProgressMonitorWrapper wrapper = new ProgressMonitorWrapper(monitor) { |
| 192 | + |
| 193 | + @Override |
| 194 | + public boolean isCanceled() { |
| 195 | + return monitor.isCanceled() || requestor.used; |
| 196 | + } |
| 197 | + |
| 198 | + @Override |
| 199 | + public void setCanceled(boolean b) { |
| 200 | + } |
| 201 | + }; |
| 202 | + try { |
| 203 | + engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, |
| 204 | + searchScope, requestor, wrapper); |
| 205 | + } catch (org.eclipse.core.runtime.OperationCanceledException e) { |
| 206 | + if (monitor.isCanceled()) { |
| 207 | + // the the user really canceled, rethrow it here, |
| 208 | + // otherwise we just found a match! |
| 209 | + throw e; |
| 210 | + } |
| 211 | + } |
192 | 212 | return requestor.used; |
193 | 213 | } |
194 | 214 | } catch (CoreException e) { |
@@ -352,10 +372,10 @@ private void minimizeDependencies(Map<String, IPluginImport> usedPlugins, List<I |
352 | 372 | } |
353 | 373 |
|
354 | 374 | private static class Requestor extends SearchRequestor { |
355 | | - boolean used; |
| 375 | + volatile boolean used; |
356 | 376 |
|
357 | 377 | @Override |
358 | | - public void acceptSearchMatch(SearchMatch match) throws CoreException { |
| 378 | + public void acceptSearchMatch(SearchMatch match) { |
359 | 379 | used = true; |
360 | 380 | } |
361 | 381 | } |
|
0 commit comments