Commits

Jan Lahoda  committed 1d34a6a

#21: adding --hint-file command line option, allowing to specify a file with the rules to apply.

  • Participants
  • Parent commits 2a99064

Comments (0)

Files changed (2)

File cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java

 import org.netbeans.api.java.source.ModificationResult;
 import org.netbeans.core.startup.MainLookup;
 import org.netbeans.modules.jackpot30.ui.settings.XMLHintPreferences;
+import org.netbeans.modules.java.hints.jackpot.spi.PatternConvertor;
 import org.netbeans.modules.java.hints.providers.spi.HintDescription;
 import org.netbeans.modules.java.hints.providers.spi.HintMetadata;
 import org.netbeans.modules.java.hints.spiimpl.MessageImpl;
         ArgumentAcceptingOptionSpec<String> hint = parser.accepts("hint", "hint name").withRequiredArg().ofType(String.class);
         ArgumentAcceptingOptionSpec<String> config = parser.accepts("config", "configurations").withRequiredArg().ofType(String.class);
         ArgumentAcceptingOptionSpec<String> source = parser.accepts("source", "source level").withRequiredArg().ofType(String.class).defaultsTo(SOURCE_LEVEL_DEFAULT);
+        ArgumentAcceptingOptionSpec<File> hintFile = parser.accepts("hint-file", "file with rules that should be performed").withRequiredArg().ofType(File.class);
 
         parser.accepts("list", "list all known hints");
         parser.accepts("progress", "show progress");
 
             if (parsed.has(hint)) {
                 if (settingsFromConfigFile != null) {
-                    System.err.println("cannot specify --hint and --configFile together");
+                    System.err.println("cannot specify --hint and --config-file together");
                     return 1;
                 }
                 hints = findHints(sourceCP, binaryCP, parsed.valueOf(hint), hintSettings);
+            } else if (parsed.has(hintFile)) {
+                if (settingsFromConfigFile != null) {
+                    System.err.println("cannot specify --hint-file and --config-file together");
+                    return 1;
+                }
+                FileObject hintFileFO = FileUtil.toFileObject(parsed.valueOf(hintFile));
+                assert hintFileFO != null;
+                hints = PatternConvertor.create(hintFileFO.asText());
+                for (HintDescription hd : hints) {
+                    HintsSettings.setEnabled(hintSettings.node(hd.getMetadata().id), true);
+                }
             } else {
                 hints = readHints(sourceCP, binaryCP, hintSettings, settingsFromConfigFile != null ? settingsFromConfigFile.getBoolean("runDeclarative", true) : true);
             }

File cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java

                       "1.6",
                       "--no-apply");
     }
+    
+    public void testHintFile() throws Exception {
+        String golden =
+            "package test;\n" +
+            "public class Test {\n" +
+            "    private void test(java.util.Collection c) {\n" +
+            "        boolean b = c.size() == 0;\n" +
+            "    }\n" +
+            "}\n";
+
+        doRunCompiler(golden,
+                      "",
+                      null,
+                      "src/test/Test.java",
+                      "package test;\n" +
+                      "public class Test {\n" +
+                      "    private void test(java.util.Collection c) {\n" +
+                      "        boolean b = c.isEmpty();\n" +
+                      "    }\n" +
+                      "}\n",
+                      "test-rule.hint",
+                      "$var.isEmpty() => $var.size() == 0;;",
+                      null,
+                      "--hint-file",
+                      "${workdir}/test-rule.hint",
+                      "--source",
+                      "1.6",
+                      "--apply");
+    }
 
     private void doRunCompiler(String golden, String stdOut, String stdErr, String... fileContentAndExtraOptions) throws Exception {
         List<String> fileAndContent = new LinkedList<String>();