Force scan if the target is unresolvable.
authorJan Lahoda <jlahoda@netbeans.org>
Tue, 28 Jun 2011 16:04:04 +0200
changeset 61422655f5f498e
parent 613 42e4e6a66230
child 615 0558321930c2
Force scan if the target is unresolvable.
remoting/ide/usages/nbproject/genfiles.properties
remoting/ide/usages/nbproject/project.xml
remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Nodes.java
     1.1 --- a/remoting/ide/usages/nbproject/genfiles.properties	Tue Jun 28 16:03:00 2011 +0200
     1.2 +++ b/remoting/ide/usages/nbproject/genfiles.properties	Tue Jun 28 16:04:04 2011 +0200
     1.3 @@ -1,8 +1,8 @@
     1.4 -build.xml.data.CRC32=dc8b4dc8
     1.5 +build.xml.data.CRC32=1b87e477
     1.6  build.xml.script.CRC32=58a6b47a
     1.7  build.xml.stylesheet.CRC32=a56c6a5b@1.47
     1.8  # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
     1.9  # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
    1.10 -nbproject/build-impl.xml.data.CRC32=dc8b4dc8
    1.11 +nbproject/build-impl.xml.data.CRC32=1b87e477
    1.12  nbproject/build-impl.xml.script.CRC32=583fd407
    1.13  nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.47
     2.1 --- a/remoting/ide/usages/nbproject/project.xml	Tue Jun 28 16:03:00 2011 +0200
     2.2 +++ b/remoting/ide/usages/nbproject/project.xml	Tue Jun 28 16:04:04 2011 +0200
     2.3 @@ -7,6 +7,15 @@
     2.4              <suite-component/>
     2.5              <module-dependencies>
     2.6                  <dependency>
     2.7 +                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
     2.8 +                    <build-prerequisite/>
     2.9 +                    <compile-dependency/>
    2.10 +                    <run-dependency>
    2.11 +                        <release-version>1</release-version>
    2.12 +                        <specification-version>1.30</specification-version>
    2.13 +                    </run-dependency>
    2.14 +                </dependency>
    2.15 +                <dependency>
    2.16                      <code-name-base>org.netbeans.libs.javacapi</code-name-base>
    2.17                      <build-prerequisite/>
    2.18                      <compile-dependency/>
     3.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Nodes.java	Tue Jun 28 16:03:00 2011 +0200
     3.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Nodes.java	Tue Jun 28 16:04:04 2011 +0200
     3.3 @@ -55,20 +55,27 @@
     3.4  import java.util.LinkedList;
     3.5  import java.util.List;
     3.6  import java.util.Map;
     3.7 +import java.util.concurrent.atomic.AtomicBoolean;
     3.8  import java.util.logging.Level;
     3.9  import java.util.logging.Logger;
    3.10  import javax.lang.model.element.Element;
    3.11  import javax.lang.model.element.ElementKind;
    3.12  import javax.lang.model.element.ExecutableElement;
    3.13 +import javax.lang.model.element.Name;
    3.14  import javax.lang.model.element.TypeElement;
    3.15 +import javax.lang.model.type.TypeKind;
    3.16  import javax.swing.Action;
    3.17 +import org.netbeans.api.java.classpath.ClassPath;
    3.18 +import org.netbeans.api.java.classpath.GlobalPathRegistry;
    3.19  import org.netbeans.api.java.source.CompilationController;
    3.20  import org.netbeans.api.java.source.CompilationInfo;
    3.21  import org.netbeans.api.java.source.ElementHandle;
    3.22  import org.netbeans.api.java.source.JavaSource;
    3.23  import org.netbeans.api.java.source.JavaSource.Phase;
    3.24 +import org.netbeans.api.java.source.SourceUtils;
    3.25  import org.netbeans.api.java.source.Task;
    3.26  import org.netbeans.api.java.source.UiUtils;
    3.27 +import org.netbeans.api.java.source.support.CancellableTreePathScanner;
    3.28  import org.netbeans.api.project.FileOwnerQuery;
    3.29  import org.netbeans.api.project.Project;
    3.30  import org.netbeans.api.project.ProjectUtils;
    3.31 @@ -292,8 +299,9 @@
    3.32              this.eh = eh;
    3.33          }
    3.34  
    3.35 -        @Override
    3.36 -        protected boolean createKeys(final List<Node> toPopulate) {
    3.37 +        private boolean computeOccurrences(final List<Node> toPopulate) {
    3.38 +            final boolean[] success = new boolean[] {true};
    3.39 +
    3.40              try {
    3.41                  JavaSource.forFileObject(file).runUserActionTask(new Task<CompilationController>() {
    3.42                      @Override public void run(final CompilationController parameter) throws Exception {
    3.43 @@ -305,18 +313,27 @@
    3.44                              return;
    3.45                          }
    3.46  
    3.47 -                        new TreePathScanner<Void, Void>() {
    3.48 +                        final AtomicBoolean stop = new AtomicBoolean();
    3.49 +
    3.50 +                        new CancellableTreePathScanner<Void, Void>(stop) {
    3.51                              @Override public Void visitIdentifier(IdentifierTree node, Void p) {
    3.52 -                                handleNode();
    3.53 +                                handleNode(node.getName());
    3.54                                  return super.visitIdentifier(node, p);
    3.55                              }
    3.56                              @Override public Void visitMemberSelect(MemberSelectTree node, Void p) {
    3.57 -                                handleNode();
    3.58 +                                handleNode(node.getIdentifier());
    3.59                                  return super.visitMemberSelect(node, p);
    3.60                              }
    3.61 -                            private void handleNode() {
    3.62 +                            private void handleNode(Name simpleName) {
    3.63                                  Element el = parameter.getTrees().getElement(getCurrentPath());
    3.64  
    3.65 +                                if (el == null || el.asType().getKind() == TypeKind.ERROR) {
    3.66 +                                    if (toFind.getSimpleName().equals(simpleName)) {
    3.67 +                                        success[0] = false;
    3.68 +                                        stop.set(true);
    3.69 +                                        return; //TODO: should stop the computation altogether
    3.70 +                                    }
    3.71 +                                }
    3.72                                  if (Nodes.equals(parameter, toFind, el)) {
    3.73                                      toPopulate.add(new OccurrenceNode(parameter, getCurrentPath().getLeaf()));
    3.74                                  }
    3.75 @@ -328,6 +345,32 @@
    3.76                  Exceptions.printStackTrace(ex);
    3.77              }
    3.78  
    3.79 +            return success[0];
    3.80 +        }
    3.81 +
    3.82 +        @Override
    3.83 +        protected boolean createKeys(final List<Node> toPopulate) {
    3.84 +            List<Node> result = new ArrayList<Node>();
    3.85 +
    3.86 +            if (!computeOccurrences(result)) {
    3.87 +                result.clear();
    3.88 +
    3.89 +                ClassPath source = ClassPath.getClassPath(file, ClassPath.SOURCE);
    3.90 +
    3.91 +                GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {source});
    3.92 +
    3.93 +                try {
    3.94 +                    SourceUtils.waitScanFinished();
    3.95 +                    computeOccurrences(result);
    3.96 +                } catch (InterruptedException ex) {
    3.97 +                    Exceptions.printStackTrace(ex);
    3.98 +                } finally {
    3.99 +                    GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, new ClassPath[] {source});
   3.100 +                }
   3.101 +            }
   3.102 +
   3.103 +            toPopulate.addAll(result);
   3.104 +            
   3.105              if (toPopulate.isEmpty()) toPopulate.add(noOccurrencesNode());
   3.106  
   3.107              return true;