1. Jan Lahoda
  2. jackpot30

Commits

Jan Lahoda  committed 58312b6

Adding hacky ClassPathBasedHintProvider.

  • Participants
  • Parent commits d14379c
  • Branches default

Comments (0)

Files changed (5)

File api/src/org/netbeans/modules/jackpot30/impl/RulesManager.java

View file
 import java.util.concurrent.atomic.AtomicBoolean;
 import javax.lang.model.element.Element;
 import javax.lang.model.element.PackageElement;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.source.ClasspathInfo;
+import org.netbeans.api.java.source.ClasspathInfo.PathKind;
 import org.netbeans.api.java.source.CompilationInfo;
 import org.netbeans.api.java.source.support.CancellableTreePathScanner;
+import org.netbeans.modules.jackpot30.spi.ClassPathBasedHintProvider;
 import org.netbeans.modules.jackpot30.spi.ElementBasedHintProvider;
 import org.netbeans.modules.jackpot30.spi.HintDescription;
 import org.netbeans.modules.jackpot30.spi.HintDescription.PatternDescription;
 import org.netbeans.modules.jackpot30.spi.HintProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
 import org.openide.util.Lookup;
 
 /**
     }
 
     public static void computeElementBasedHintsXXX(final CompilationInfo info, AtomicBoolean cancel, final Map<Kind, List<HintDescription>> kind2Hints, final Map<PatternDescription, List<HintDescription>> pattern2Hint) {
-        computeElementBasedHintsXXX(info, cancel, Lookup.getDefault().lookupAll(ElementBasedHintProvider.class), kind2Hints, pattern2Hint);
+        computeElementBasedHintsXXX(info, cancel, Lookup.getDefault().lookupAll(ElementBasedHintProvider.class), Lookup.getDefault().lookupAll(ClassPathBasedHintProvider.class), kind2Hints, pattern2Hint);
     }
 
-    public static void computeElementBasedHintsXXX(final CompilationInfo info, AtomicBoolean cancel, final Collection<? extends ElementBasedHintProvider> providers, final Map<Kind, List<HintDescription>> kind2Hints, final Map<PatternDescription, List<HintDescription>> pattern2Hint) {
-        new CancellableTreePathScanner(cancel) {
+    public static void computeElementBasedHintsXXX(final CompilationInfo info, AtomicBoolean cancel, final Collection<? extends ElementBasedHintProvider> providers, final Collection<? extends ClassPathBasedHintProvider> cpBasedProviders, final Map<Kind, List<HintDescription>> kind2Hints, final Map<PatternDescription, List<HintDescription>> pattern2Hint) {
+        new CancellableTreePathScanner<Void, Void>(cancel) {
             private Set<Element> handledElements = new HashSet<Element>();
             private void handleElementImpl(Element el) {
                 if (!handledElements.add(el)) return ;
             }
 
             @Override
-            public Object scan(Tree tree, Object p) {
+            public Void scan(Tree tree, Void p) {
                 if (tree == null) return null;
 
                 TreePath tp = new TreePath(getCurrentPath(), tree);
                 return super.scan(tree, p);
             }
         }.scan(info.getCompilationUnit(), null);
+
+        ClasspathInfo cpInfo = info.getClasspathInfo();
+        List<ClassPath> cps = new LinkedList<ClassPath>();
+        
+        //ignoring bootclasspath for now
+        cps.add(cpInfo.getClassPath(PathKind.COMPILE));
+        cps.add(cpInfo.getClassPath(PathKind.SOURCE));
+
+        ClassPath compound = ClassPathSupport.createProxyClassPath(cps.toArray(new ClassPath[0]));
+
+        for (ClassPathBasedHintProvider p : cpBasedProviders) {
+            sortOut(p.computeHints(compound), kind2Hints, pattern2Hint);
+        }
+
     }
 
     //used by tests:

File api/src/org/netbeans/modules/jackpot30/impl/hints/HintsInvoker.java

View file
     }
 
     private List<ErrorDescription> computeHints(CompilationInfo info, TreePath startAt) {
-        Map<Kind, List<HintDescription>> kindHints = new HashMap<Kind, List<HintDescription>>(RulesManager.getInstance().getKindBasedHints());
-        Map<PatternDescription, List<HintDescription>> patternHints = new HashMap<PatternDescription, List<HintDescription>>(RulesManager.getInstance().getPatternBasedHints());
+        Map<Kind, List<HintDescription>> kindHints = new HashMap<Kind, List<HintDescription>>();
+        Map<PatternDescription, List<HintDescription>> patternHints = new HashMap<PatternDescription, List<HintDescription>>();
+        
+        for (Entry<Kind, List<HintDescription>> e : RulesManager.getInstance().getKindBasedHints().entrySet()) {
+            kindHints.put(e.getKey(), new LinkedList<HintDescription>(e.getValue()));
+        }
+
+        for (Entry<PatternDescription, List<HintDescription>> e : RulesManager.getInstance().getPatternBasedHints().entrySet()) {
+            patternHints.put(e.getKey(), new LinkedList<HintDescription>(e.getValue()));
+        }
 
         RulesManager.computeElementBasedHintsXXX(info, cancel, kindHints, patternHints);
         
 
             descs.add(e.getKey());
         }
-        
+
         BulkPattern bulkPattern = BulkSearch.create(info, patternTests.keySet());
         Set<String> occurringPatterns = BulkSearch.match(info, info.getCompilationUnit(), bulkPattern);
 

File api/src/org/netbeans/modules/jackpot30/spi/ClassPathBasedHintProvider.java

View file
+package org.netbeans.modules.jackpot30.spi;
+
+import java.util.Collection;
+import org.netbeans.api.java.classpath.ClassPath;
+
+/**
+ * XXX: this is another ugly hack!
+ * @author lahvac
+ */
+public interface ClassPathBasedHintProvider {
+
+    public Collection<? extends HintDescription> computeHints(ClassPath cp);
+
+}

File file/nbproject/project.xml

View file
             <suite-component/>
             <module-dependencies>
                 <dependency>
+                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <specification-version>1.19</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
                     <code-name-base>org.netbeans.libs.javacapi</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
                     </run-dependency>
                 </dependency>
                 <dependency>
+                    <code-name-base>org.netbeans.modules.parsing.api</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>1.12.1</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
                     <code-name-base>org.netbeans.spi.editor.hints</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>

File file/src/org/netbeans/modules/jackpot30/file/DeclarativeHintRegistry.java

View file
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.modules.jackpot30.spi.ClassPathBasedHintProvider;
 import org.netbeans.modules.jackpot30.spi.HintDescription;
 import org.netbeans.modules.jackpot30.spi.HintDescription.PatternDescription;
 import org.netbeans.modules.jackpot30.spi.HintProvider;
  * @author Jan Lahoda
  */
 @ServiceProvider(service=HintProvider.class)
-public class DeclarativeHintRegistry implements HintProvider {
+public class DeclarativeHintRegistry implements HintProvider, ClassPathBasedHintProvider {
 
     public Collection<? extends HintDescription> computeHints() {
         FileObject folder = FileUtil.getConfigFile("org-netbeans-modules-java-hints/declarative");
         }
 
         List<HintDescription> result = new LinkedList<HintDescription>();
+        
+        readHintsFromFolder(folder, result);
 
-        for (FileObject f : folder.getChildren()) {
-            if (!"hint".equals(f.getExt())) {
-                continue;
-            }
+        return result;
+    }
 
-            result.addAll(parseHintFile(f));
+    public Collection<? extends HintDescription> computeHints(ClassPath cp) {
+        List<HintDescription> result = new LinkedList<HintDescription>();
+        
+        for (FileObject folder : cp.findAllResources("META-INF/upgrade")) {
+            readHintsFromFolder(folder, result);
         }
 
         return result;
     }
 
+    private void readHintsFromFolder(FileObject folder, List<HintDescription> result) {
+        for (FileObject f : folder.getChildren()) {
+            if (!"hint".equals(f.getExt())) {
+                continue;
+            }
+            result.addAll(parseHintFile(f));
+        }
+    }
+    
     private static List<HintDescription> parseHintFile(FileObject file) {
         StringBuilder sb = new StringBuilder();