Commits

Jan Lahoda committed 65c143d

Making the usages computation cancellable.

Comments (0)

Files changed (3)

remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java

         FROM_BASE;
     }
 
-    public static boolean computeOccurrences(FileObject file, final ElementHandle<?> eh, final Set<RemoteUsages.SearchOptions> options, final TreeElement parent, final List<TreeElement> toPopulate) {
+    public static boolean computeOccurrences(FileObject file, final ElementHandle<?> eh, final Set<RemoteUsages.SearchOptions> options, final TreeElement parent, final AtomicBoolean stop, final List<TreeElement> toPopulate) {
         final boolean[] success = new boolean[] {true};
 
         try {
             JavaSource.forFileObject(file).runUserActionTask(new Task<CompilationController>() {
                 @Override public void run(final CompilationController parameter) throws Exception {
+                    if (stop.get()) return ;
+
                     parameter.toPhase(Phase.RESOLVED);
 
                     final Element toFind = eh.resolve(parameter);
                         return;
                     }
 
-                    final AtomicBoolean stop = new AtomicBoolean();
-
                     new CancellableTreePathScanner<Void, Void>(stop) {
                         @Override public Void visitIdentifier(IdentifierTree node, Void p) {
                             handleNode(node.getName(), getCurrentPath());

remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteWhereUsedQuery.java

 
         private final Impl impl;
         private final TreeElement delegateTo;
+        private final AtomicBoolean cancel = new AtomicBoolean();
 
         public TreeElementImpl(Impl impl, TreeElement delegateTo) {
             this.impl = impl;
 
         @Override
         public Iterator<TreeElement> iterator() {
+            cancel.set(false);
+
             final List<TreeElement> result = new ArrayList<TreeElement>();
 
-            RemoteUsages.computeOccurrences(impl.file, impl.eh, impl.searchOptions, this, result);
+            RemoteUsages.computeOccurrences(impl.file, impl.eh, impl.searchOptions, this, cancel, result);
             
             return result.iterator();
         }
 
         @Override
         public boolean cancel() {
-            // TODO: XXX
+            cancel.set(true);
+
             return true;
         }
     }

remoting/ide/usages/test/unit/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsagesTest.java

 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 import javax.lang.model.element.TypeElement;
 import org.netbeans.api.java.source.CompilationInfo;
 import org.netbeans.api.java.source.ElementHandle;
 import org.netbeans.modules.refactoring.spi.ui.TreeElement;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
-import org.openide.nodes.Node;
 
 /**
  *
         ElementHandle<?> eh = ElementHandle.create(info.getTopLevelElements().get(0).getEnclosedElements().get(0));
         List<TreeElement> constructed = new ArrayList<TreeElement>();
 
-        RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.USAGES), null, constructed);
+        RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.USAGES), null, new AtomicBoolean(), constructed);
 
         TreeElement n = constructed.get(0);
 
         ElementHandle<?> eh = ElementHandle.create(runnable.getEnclosedElements().get(0));
         List<TreeElement> constructed = new ArrayList<TreeElement>();
 
-        RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.SUB), null, constructed);
+        RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.SUB), null, new AtomicBoolean(), constructed);
 
         assertEquals(1, constructed.size());
         
         ElementHandle<?> eh = ElementHandle.create(runnable);
         List<TreeElement> constructed = new ArrayList<TreeElement>();
 
-        RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.SUB), null, constructed);
+        RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.SUB), null, new AtomicBoolean(), constructed);
 
         assertEquals(1, constructed.size());