Also work with ClassPath-based hints.
1.1 --- a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java Tue Nov 01 19:36:49 2011 +0100
1.2 +++ b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java Tue Nov 15 11:21:09 2011 +0100
1.3 @@ -49,9 +49,12 @@
1.4 import java.net.URL;
1.5 import java.util.ArrayList;
1.6 import java.util.Collection;
1.7 +import java.util.Collections;
1.8 +import java.util.HashMap;
1.9 import java.util.Iterator;
1.10 import java.util.LinkedList;
1.11 import java.util.List;
1.12 +import java.util.Map;
1.13 import java.util.Map.Entry;
1.14 import java.util.Set;
1.15 import java.util.TreeSet;
1.16 @@ -71,6 +74,7 @@
1.17 import org.netbeans.core.startup.MainLookup;
1.18 import org.netbeans.modules.java.hints.jackpot.impl.MessageImpl;
1.19 import org.netbeans.modules.java.hints.jackpot.impl.RulesManager;
1.20 +import org.netbeans.modules.java.hints.jackpot.impl.Utilities;
1.21 import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch;
1.22 import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.BatchResult;
1.23 import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Folder;
1.24 @@ -179,11 +183,6 @@
1.25
1.26 CacheFolder.setCacheFolder(FileUtil.toFileObject(FileUtil.normalizeFile(cacheDir)));
1.27
1.28 - if (parsed.has("list")) {
1.29 - listHints();
1.30 - return 0;
1.31 - }
1.32 -
1.33 org.netbeans.api.project.ui.OpenProjects.getDefault().getOpenProjects();
1.34 RepositoryUpdater.getDefault().start(false);
1.35
1.36 @@ -200,17 +199,27 @@
1.37 }
1.38 }
1.39
1.40 - if (roots.isEmpty()) {
1.41 + if (roots.isEmpty() && !parsed.has("list")) {
1.42 System.err.println("no source roots to work on");
1.43 return 1;
1.44 }
1.45
1.46 Iterable<? extends HintDescription> hints;
1.47
1.48 + ClassPath bootCP = createClassPath(parsed.has(bootclasspath) ? parsed.valuesOf(bootclasspath) : null, createDefaultBootClassPath());
1.49 + ClassPath compileCP = createClassPath(parsed.has(classpath) ? parsed.valuesOf(classpath) : null, ClassPath.EMPTY);
1.50 + ClassPath sourceCP = createClassPath(parsed.has(sourcepath) ? parsed.valuesOf(sourcepath) : null, ClassPathSupport.createClassPath(roots.toArray(new FileObject[0])));
1.51 + ClassPath hintsCP = ClassPathSupport.createProxyClassPath(bootCP, compileCP, sourceCP);
1.52 +
1.53 + if (parsed.has("list")) {
1.54 + printHints(hintsCP);
1.55 + return 0;
1.56 + }
1.57 +
1.58 if (parsed.has(hint)) {
1.59 - hints = findHints(parsed.valueOf(hint));
1.60 + hints = findHints(hintsCP, parsed.valueOf(hint));
1.61 } else {
1.62 - hints = allHints();
1.63 + hints = allHints(hintsCP);
1.64 }
1.65
1.66 if (!hints.iterator().hasNext()) {
1.67 @@ -260,9 +269,6 @@
1.68 }
1.69
1.70 try {
1.71 - ClassPath bootCP = createClassPath(parsed.has(bootclasspath) ? parsed.valuesOf(bootclasspath) : null, createDefaultBootClassPath());
1.72 - ClassPath compileCP = createClassPath(parsed.has(classpath) ? parsed.valuesOf(classpath) : null, ClassPath.EMPTY);
1.73 - ClassPath sourceCP = createClassPath(parsed.has(sourcepath) ? parsed.valuesOf(sourcepath) : null, ClassPathSupport.createClassPath(roots.toArray(new FileObject[0])));
1.74 MainLookup.register(new ClassPathProviderImpl(bootCP, compileCP, sourceCP));
1.75 MainLookup.register(new JavaPathRecognizer());
1.76 MainLookup.register(new SourceLevelQueryImpl(sourceCP, "1.7"));
1.77 @@ -293,10 +299,24 @@
1.78 return 0;
1.79 }
1.80
1.81 - private static Iterable<? extends HintDescription> findHints(String name) {
1.82 + private static Map<HintMetadata, Collection<? extends HintDescription>> listHints(ClassPath from) {
1.83 + Map<HintMetadata, Collection<? extends HintDescription>> result = new HashMap<HintMetadata, Collection<? extends HintDescription>>();
1.84 +
1.85 + for (Map.Entry<HintMetadata, Collection<? extends HintDescription>> entry: RulesManager.getInstance().allHints.entrySet()) {
1.86 + result.put(entry.getKey(), entry.getValue());
1.87 + }
1.88 +
1.89 + for (Map.Entry<? extends HintMetadata, ? extends Collection<? extends HintDescription>> entry: org.netbeans.modules.java.hints.jackpot.impl.refactoring.Utilities.sortByMetadata(Utilities.listClassPathHints(Collections.singleton(from))).entrySet()) {
1.90 + result.put(entry.getKey(), entry.getValue());
1.91 + }
1.92 +
1.93 + return result;
1.94 + }
1.95 +
1.96 + private static Iterable<? extends HintDescription> findHints(ClassPath from, String name) {
1.97 List<HintDescription> descs = new LinkedList<HintDescription>();
1.98
1.99 - for (Entry<HintMetadata, Collection<? extends HintDescription>> e : RulesManager.getInstance().allHints.entrySet()) {
1.100 + for (Entry<HintMetadata, Collection<? extends HintDescription>> e : listHints(from).entrySet()) {
1.101 if (e.getKey().displayName.equals(name)) {
1.102 descs.addAll(e.getValue());
1.103 }
1.104 @@ -305,10 +325,10 @@
1.105 return descs;
1.106 }
1.107
1.108 - private static Iterable<? extends HintDescription> allHints() {
1.109 + private static Iterable<? extends HintDescription> allHints(ClassPath from) {
1.110 List<HintDescription> descs = new LinkedList<HintDescription>();
1.111
1.112 - for (Entry<HintMetadata, Collection<? extends HintDescription>> e : RulesManager.getInstance().allHints.entrySet()) {
1.113 + for (Entry<HintMetadata, Collection<? extends HintDescription>> e : listHints(from).entrySet()) {
1.114 if (e.getKey().kind != Kind.HINT) continue;
1.115 if (!e.getKey().enabled) continue;
1.116 descs.addAll(e.getValue());
1.117 @@ -394,10 +414,10 @@
1.118 }
1.119 }
1.120
1.121 - private static void listHints() throws IOException {
1.122 + private static void printHints(ClassPath from) throws IOException {
1.123 Set<String> hints = new TreeSet<String>();
1.124
1.125 - for (Entry<HintMetadata, Collection<? extends HintDescription>> e : RulesManager.getInstance().allHints.entrySet()) {
1.126 + for (Entry<HintMetadata, Collection<? extends HintDescription>> e : listHints(from).entrySet()) {
1.127 hints.add(e.getKey().displayName);
1.128 }
1.129