Commits

Jan Lahoda committed c7fbe9b

listAllHints in batch apply works again.

  • Participants
  • Parent commits e33cbb9

Comments (0)

Files changed (3)

api/src/org/netbeans/modules/jackpot30/impl/Utilities.java

 import com.sun.source.tree.NewArrayTree;
 import com.sun.source.tree.Tree;
 import com.sun.source.tree.Tree.Kind;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.type.TypeMirror;
+import java.util.Set;
+import org.netbeans.api.java.classpath.ClassPath;
 import org.netbeans.api.java.source.TreeMaker;
-import org.netbeans.api.java.source.WorkingCopy;
+import org.netbeans.modules.jackpot30.spi.ClassPathBasedHintProvider;
 import org.netbeans.modules.jackpot30.spi.HintDescription;
+import org.netbeans.modules.jackpot30.spi.HintProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.util.Lookup;
 import org.openide.util.NbCollections;
 
 /**
         return output;
     }
 
+    public static List<HintDescription> listAllHints(Set<ClassPath> cps) {
+        List<HintDescription> result = new LinkedList<HintDescription>();
+
+        for (HintProvider p : Lookup.getDefault().lookupAll(HintProvider.class)) {
+            for (HintDescription hd : p.computeHints()) {
+                if (hd.getTriggerPattern() == null) continue; //TODO: only pattern based hints are currently supported
+                result.add(hd);
+            }
+        }
+
+        ClassPath cp = ClassPathSupport.createProxyClassPath(cps.toArray(new ClassPath[cps.size()]));
+
+        for (ClassPathBasedHintProvider p : Lookup.getDefault().lookupAll(ClassPathBasedHintProvider.class)) {
+            result.addAll(p.computeHints(cp));
+        }
+
+        return result;
+    }
+    
 }

api/src/org/netbeans/modules/jackpot30/impl/batch/BatchApplyAction.java

     }
 
     private List<HintDescription> listAllHints() {
-        List<HintDescription> result = new LinkedList<HintDescription>();
-        
-        for (HintProvider p : Lookup.getDefault().lookupAll(HintProvider.class)) {
-            for (HintDescription hd : p.computeHints()) {
-                if (hd.getTriggerPattern() == null) continue; //TODO: only pattern based hints are currently supported
-                result.add(hd);
-            }
-        }
-
         Set<ClassPath> cps = new HashSet<ClassPath>();
 
         for (FileObject file : BatchApply.toProcess(context)) {
 
         cps.remove(null);
 
-        ClassPath cp = ClassPathSupport.createProxyClassPath(cps.toArray(new ClassPath[cps.size()]));
-
-        for (ClassPathBasedHintProvider p : Lookup.getDefault().lookupAll(ClassPathBasedHintProvider.class)) {
-            result.addAll(p.computeHints(cp));
-        }
-
-        return result;
+        return org.netbeans.modules.jackpot30.impl.Utilities.listAllHints(cps);
     }
 
     public void actionPerformed(ActionEvent e) {

api/src/org/netbeans/modules/jackpot30/impl/batch/OptionProcessorImpl.java

 import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
+import java.util.TreeMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.netbeans.api.java.classpath.ClassPath;
 import org.netbeans.api.project.SourceGroup;
 import org.netbeans.api.project.ui.OpenProjects;
 import org.netbeans.api.sendopts.CommandException;
+import org.netbeans.modules.jackpot30.impl.Utilities;
+import org.netbeans.modules.jackpot30.spi.HintDescription;
 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
 import org.netbeans.spi.sendopts.Env;
 import org.netbeans.spi.sendopts.Option;
     
     private static final String APPLY_TRANSFORMATIONS_PROJECT_OPTION = "apply-transformations-project";
 
-//    private static final Option LIST = Option.withoutArgument(Option.NO_SHORT_NAME, "list-hints-transformation");
+    private static final Option LIST = Option.withoutArgument(Option.NO_SHORT_NAME, "list-hints-transformation");
     private static final Option APPLY_TRANSFORMATIONS = Option.shortDescription(
                                                             Option.requiredArgument(Option.NO_SHORT_NAME, "apply-transformations"),
                                                             "org.netbeans.modules.jackpot30.hints.batch.Bundle",
                                                             "org.netbeans.modules.jackpot30.hints.batch.Bundle",
                                                             "SD_ApplyTransformationsProject");
 
-    private static final Set<Option> OPTIONS = new HashSet<Option>(Arrays.asList(/*LIST, */APPLY_TRANSFORMATIONS, APPLY_TRANSFORMATIONS_PROJECT));
+    private static final Set<Option> OPTIONS = new HashSet<Option>(Arrays.asList(LIST, APPLY_TRANSFORMATIONS, APPLY_TRANSFORMATIONS_PROJECT));
     
     @Override
     protected Set<Option> getOptions() {
 
     @Override
     protected void process(Env env, Map<Option, String[]> optionValues) throws CommandException {
-//        if (optionValues.containsKey(LIST)) {
-//            env.getOutputStream().println("Supported Hints:");
-//            for (TreeRule r : BatchApply.listHints()) {
-//                env.getOutputStream().println(r.getDisplayName() + " - " + r.getId());
-//            }
-//        }
-
         List<Project> projects = new LinkedList<Project>();
         Map<String, List<ClassPath>> classPaths = new HashMap<String, List<ClassPath>>();
         
                 throw new CommandException(1);
             }
 
+            FileObject currentDirectory = FileUtil.toFileObject(env.getCurrentDirectory());
+            
             OUTER: for (String p : projectNames) {
-                File loc = new File(env.getCurrentDirectory(), p);
-                FileObject projectFile = FileUtil.toFileObject(loc);
+                FileObject projectFile = currentDirectory.getFileObject(p);
+
+                if (projectFile == null) {
+                    projectFile = FileUtil.toFileObject(new File(p));
+                }
 
                 if (projectFile == null) {
                     env.getErrorStream().println("Ignoring file " + p + " - cannot be found.");
 
                 projects.add(project);
             }
-
-            for (Entry<String, List<ClassPath>> cps : classPaths.entrySet()) {
-                LOG.log(Level.INFO, "registering classpaths: type={0}, classpaths={1}", new Object[] {cps.getKey(), cps.getValue()});
-                GlobalPathRegistry.getDefault().register(cps.getKey(), cps.getValue().toArray(new ClassPath[0]));
-            }
         } else {
             projects.addAll(Arrays.asList(OpenProjects.getDefault().getOpenProjects()));
         }
         
-        try {
-            waitScanFinished();
-        } catch (InterruptedException ex) {
-            Exceptions.printStackTrace(ex);
+        if (optionValues.containsKey(LIST)) {
+            env.getOutputStream().println("Supported Hints:");
+
+            Set<ClassPath> cps = new HashSet<ClassPath>();
+
+            for (List<ClassPath> c : classPaths.values()) {
+                cps.addAll(c);
+            }
+
+            Set<String> displayNames = Utilities.sortOutHints(Utilities.listAllHints(cps), new TreeMap<String, Collection<HintDescription>>()).keySet();
+
+            for (String displayName : displayNames) {
+                env.getOutputStream().println(displayName);
+            }
         }
-        
+
         if (optionValues.containsKey(APPLY_TRANSFORMATIONS)) {
+            for (Entry<String, List<ClassPath>> cps : classPaths.entrySet()) {
+                LOG.log(Level.INFO, "registering classpaths: type={0}, classpaths={1}", new Object[]{cps.getKey(), cps.getValue()});
+                GlobalPathRegistry.getDefault().register(cps.getKey(), cps.getValue().toArray(new ClassPath[0]));
+            }
+
+            try {
+                waitScanFinished();
+            } catch (InterruptedException ex) {
+                Exceptions.printStackTrace(ex);
+            }
+
             String hintsArg = optionValues.get(APPLY_TRANSFORMATIONS)[0];
 //            String[] hints = hintsArg.split(":");
 
 //            if (error != null) {
 //                env.getErrorStream().println("Cannot apply hints because of: " + error);
 //            }
+
+            for (Entry<String, List<ClassPath>> cps : classPaths.entrySet()) {
+                GlobalPathRegistry.getDefault().unregister(cps.toString(), cps.getValue().toArray(new ClassPath[0]));
+            }
         }
 
-        for (Entry<String, List<ClassPath>> cps : classPaths.entrySet()) {
-            GlobalPathRegistry.getDefault().unregister(cps.toString(), cps.getValue().toArray(new ClassPath[0]));
-        }
     }
 
     private boolean handleClassPath(FileObject root, String type, Env env, String p, Map<String, List<ClassPath>> classPaths) {