Making the usages computation cancellable. remote-usages-to-find-usages
authorJan Lahoda <jlahoda@netbeans.org>
Sat, 25 Aug 2012 08:04:23 +0200
branchremote-usages-to-find-usages
changeset 857ddabc8ca59a9
parent 856 126afba7ab30
child 858 610a3830e451
Making the usages computation cancellable.
remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java
remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteWhereUsedQuery.java
remoting/ide/usages/test/unit/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsagesTest.java
     1.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java	Fri Aug 24 17:25:14 2012 +0200
     1.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java	Sat Aug 25 08:04:23 2012 +0200
     1.3 @@ -189,12 +189,14 @@
     1.4          FROM_BASE;
     1.5      }
     1.6  
     1.7 -    public static boolean computeOccurrences(FileObject file, final ElementHandle<?> eh, final Set<RemoteUsages.SearchOptions> options, final TreeElement parent, final List<TreeElement> toPopulate) {
     1.8 +    public static boolean computeOccurrences(FileObject file, final ElementHandle<?> eh, final Set<RemoteUsages.SearchOptions> options, final TreeElement parent, final AtomicBoolean stop, final List<TreeElement> toPopulate) {
     1.9          final boolean[] success = new boolean[] {true};
    1.10  
    1.11          try {
    1.12              JavaSource.forFileObject(file).runUserActionTask(new Task<CompilationController>() {
    1.13                  @Override public void run(final CompilationController parameter) throws Exception {
    1.14 +                    if (stop.get()) return ;
    1.15 +
    1.16                      parameter.toPhase(Phase.RESOLVED);
    1.17  
    1.18                      final Element toFind = eh.resolve(parameter);
    1.19 @@ -203,8 +205,6 @@
    1.20                          return;
    1.21                      }
    1.22  
    1.23 -                    final AtomicBoolean stop = new AtomicBoolean();
    1.24 -
    1.25                      new CancellableTreePathScanner<Void, Void>(stop) {
    1.26                          @Override public Void visitIdentifier(IdentifierTree node, Void p) {
    1.27                              handleNode(node.getName(), getCurrentPath());
     2.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteWhereUsedQuery.java	Fri Aug 24 17:25:14 2012 +0200
     2.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteWhereUsedQuery.java	Sat Aug 25 08:04:23 2012 +0200
     2.3 @@ -184,6 +184,7 @@
     2.4  
     2.5          private final Impl impl;
     2.6          private final TreeElement delegateTo;
     2.7 +        private final AtomicBoolean cancel = new AtomicBoolean();
     2.8  
     2.9          public TreeElementImpl(Impl impl, TreeElement delegateTo) {
    2.10              this.impl = impl;
    2.11 @@ -212,9 +213,11 @@
    2.12  
    2.13          @Override
    2.14          public Iterator<TreeElement> iterator() {
    2.15 +            cancel.set(false);
    2.16 +
    2.17              final List<TreeElement> result = new ArrayList<TreeElement>();
    2.18  
    2.19 -            RemoteUsages.computeOccurrences(impl.file, impl.eh, impl.searchOptions, this, result);
    2.20 +            RemoteUsages.computeOccurrences(impl.file, impl.eh, impl.searchOptions, this, cancel, result);
    2.21              
    2.22              return result.iterator();
    2.23          }
    2.24 @@ -226,7 +229,8 @@
    2.25  
    2.26          @Override
    2.27          public boolean cancel() {
    2.28 -            // TODO: XXX
    2.29 +            cancel.set(true);
    2.30 +
    2.31              return true;
    2.32          }
    2.33      }
     3.1 --- a/remoting/ide/usages/test/unit/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsagesTest.java	Fri Aug 24 17:25:14 2012 +0200
     3.2 +++ b/remoting/ide/usages/test/unit/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsagesTest.java	Sat Aug 25 08:04:23 2012 +0200
     3.3 @@ -44,6 +44,7 @@
     3.4  import java.util.ArrayList;
     3.5  import java.util.EnumSet;
     3.6  import java.util.List;
     3.7 +import java.util.concurrent.atomic.AtomicBoolean;
     3.8  import javax.lang.model.element.TypeElement;
     3.9  import org.netbeans.api.java.source.CompilationInfo;
    3.10  import org.netbeans.api.java.source.ElementHandle;
    3.11 @@ -56,7 +57,6 @@
    3.12  import org.netbeans.modules.refactoring.spi.ui.TreeElement;
    3.13  import org.openide.filesystems.FileObject;
    3.14  import org.openide.filesystems.FileUtil;
    3.15 -import org.openide.nodes.Node;
    3.16  
    3.17  /**
    3.18   *
    3.19 @@ -79,7 +79,7 @@
    3.20          ElementHandle<?> eh = ElementHandle.create(info.getTopLevelElements().get(0).getEnclosedElements().get(0));
    3.21          List<TreeElement> constructed = new ArrayList<TreeElement>();
    3.22  
    3.23 -        RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.USAGES), null, constructed);
    3.24 +        RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.USAGES), null, new AtomicBoolean(), constructed);
    3.25  
    3.26          TreeElement n = constructed.get(0);
    3.27  
    3.28 @@ -103,7 +103,7 @@
    3.29          ElementHandle<?> eh = ElementHandle.create(runnable.getEnclosedElements().get(0));
    3.30          List<TreeElement> constructed = new ArrayList<TreeElement>();
    3.31  
    3.32 -        RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.SUB), null, constructed);
    3.33 +        RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.SUB), null, new AtomicBoolean(), constructed);
    3.34  
    3.35          assertEquals(1, constructed.size());
    3.36          
    3.37 @@ -129,7 +129,7 @@
    3.38          ElementHandle<?> eh = ElementHandle.create(runnable);
    3.39          List<TreeElement> constructed = new ArrayList<TreeElement>();
    3.40  
    3.41 -        RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.SUB), null, constructed);
    3.42 +        RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.SUB), null, new AtomicBoolean(), constructed);
    3.43  
    3.44          assertEquals(1, constructed.size());
    3.45