1.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java Wed Aug 15 20:10:02 2012 +0200
1.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java Sat Aug 25 08:06:43 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());
1.28 @@ -221,7 +221,7 @@
1.29 OUTER: while (true) {
1.30 switch (name.getLeaf().getKind()) {
1.31 case PARAMETERIZED_TYPE: name = new TreePath(name, ((ParameterizedTypeTree) name.getLeaf()).getType()); break;
1.32 - case MEMBER_SELECT: simpleName = ((MemberSelectTree) name).getIdentifier(); break OUTER;
1.33 + case MEMBER_SELECT: simpleName = ((MemberSelectTree) name.getLeaf()).getIdentifier(); break OUTER;
1.34 case IDENTIFIER: simpleName = ((IdentifierTree) name.getLeaf()).getName(); break OUTER;
1.35 default: name = getCurrentPath(); break OUTER;
1.36 }
2.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteWhereUsedQuery.java Wed Aug 15 20:10:02 2012 +0200
2.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteWhereUsedQuery.java Sat Aug 25 08:06:43 2012 +0200
2.3 @@ -21,14 +21,16 @@
2.4 import org.netbeans.modules.refactoring.api.Problem;
2.5 import org.netbeans.modules.refactoring.api.RefactoringElement;
2.6 import org.netbeans.modules.refactoring.api.Scope;
2.7 -import org.netbeans.modules.refactoring.api.ScopeDescription;
2.8 -import org.netbeans.modules.refactoring.api.ScopeProvider;
2.9 import org.netbeans.modules.refactoring.api.WhereUsedQuery;
2.10 +import org.netbeans.modules.refactoring.java.api.WhereUsedQueryConstants;
2.11 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
2.12 import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
2.13 import org.netbeans.modules.refactoring.spi.RefactoringPluginFactory;
2.14 import org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImplementation;
2.15 import org.netbeans.modules.refactoring.spi.ui.ExpandableTreeElement;
2.16 +import org.netbeans.modules.refactoring.spi.ui.ScopeDescription;
2.17 +import org.netbeans.modules.refactoring.spi.ui.ScopeProvider;
2.18 +import org.netbeans.modules.refactoring.spi.ui.ScopeReference;
2.19 import org.netbeans.modules.refactoring.spi.ui.TreeElement;
2.20 import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory;
2.21 import org.netbeans.modules.refactoring.spi.ui.TreeElementFactoryImplementation;
2.22 @@ -75,6 +77,15 @@
2.23 TreePathHandle handle = what.getRefactoringSource().lookup(TreePathHandle.class);
2.24 ElementHandle<?> toSearch = handle.getElementHandle();
2.25 Set<SearchOptions> searchOptions = EnumSet.noneOf(SearchOptions.class);
2.26 + if(what.getBooleanValue(WhereUsedQuery.FIND_REFERENCES)) {
2.27 + searchOptions.add(SearchOptions.USAGES);
2.28 + }
2.29 + if(what.getBooleanValue(WhereUsedQueryConstants.FIND_SUBCLASSES)) {
2.30 + searchOptions.add(SearchOptions.SUB);
2.31 + }
2.32 + if(what.getBooleanValue(WhereUsedQueryConstants.SEARCH_FROM_BASECLASS)) {
2.33 + searchOptions.add(SearchOptions.FROM_BASE);
2.34 + }
2.35
2.36 for (FileObject found : RemoteUsages.findUsages(toSearch, searchOptions, /*XXX*/new AtomicBoolean())) {
2.37 Impl i = new Impl(found, toSearch, searchOptions);
2.38 @@ -173,6 +184,7 @@
2.39
2.40 private final Impl impl;
2.41 private final TreeElement delegateTo;
2.42 + private final AtomicBoolean cancel = new AtomicBoolean();
2.43
2.44 public TreeElementImpl(Impl impl, TreeElement delegateTo) {
2.45 this.impl = impl;
2.46 @@ -201,38 +213,42 @@
2.47
2.48 @Override
2.49 public Iterator<TreeElement> iterator() {
2.50 + cancel.set(false);
2.51 +
2.52 final List<TreeElement> result = new ArrayList<TreeElement>();
2.53
2.54 - RemoteUsages.computeOccurrences(impl.file, impl.eh, impl.searchOptions, this, result);
2.55 + RemoteUsages.computeOccurrences(impl.file, impl.eh, impl.searchOptions, this, cancel, result);
2.56
2.57 return result.iterator();
2.58 }
2.59
2.60 @Override
2.61 - public int estimateSubNodesCount() {
2.62 + public int estimateChildCount() {
2.63 return 1;
2.64 }
2.65 +
2.66 + @Override
2.67 + public boolean cancel() {
2.68 + cancel.set(true);
2.69 +
2.70 + return true;
2.71 + }
2.72 }
2.73
2.74 private static final Scope REMOTE_SCOPE = Scope.create(Collections.<FileObject>emptyList(), Collections.<NonRecursiveFolder>emptyList(), Collections.<FileObject>emptyList());
2.75 - private static final ScopeDescription REMOTE_SCOPE_DESCRIPTION = new ScopeDescription("remote-scope", "Remote Scope", null, "A") {
2.76 - @Override public Scope getScope() {
2.77 +
2.78 + @ScopeDescription(id="remote-scope", displayName="Remote Scope", position=-300)
2.79 + @ScopeReference(path="org-netbeans-modules-refactoring-java-ui-WhereUsedPanel")
2.80 + public static class RemoteScopeProvider extends ScopeProvider {
2.81 +
2.82 + @Override
2.83 + public boolean initialize(Lookup context, AtomicBoolean cancel) {
2.84 + return RemoteIndex.loadIndices().iterator().hasNext();
2.85 + }
2.86 +
2.87 + @Override
2.88 + public Scope getScope() {
2.89 return REMOTE_SCOPE;
2.90 }
2.91 - };
2.92 -
2.93 - @ServiceProvider(service=ScopeProvider.class)
2.94 - public static final class ScopeProviderImpl implements ScopeProvider {
2.95 -
2.96 - @Override
2.97 - public Iterable<ScopeDescription> scopesFor(Lookup source) {
2.98 - if (RemoteIndex.loadIndices().iterator().hasNext()) {
2.99 - return Collections.singletonList(REMOTE_SCOPE_DESCRIPTION);
2.100 - } else {
2.101 - return Collections.emptyList();
2.102 - }
2.103 - }
2.104 -
2.105 }
2.106 -
2.107 }
3.1 --- a/remoting/ide/usages/test/unit/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsagesTest.java Wed Aug 15 20:10:02 2012 +0200
3.2 +++ b/remoting/ide/usages/test/unit/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsagesTest.java Sat Aug 25 08:06:43 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