Commits

Jan Lahoda committed 84b6795

Various improvements to make the o.o.text.Line.show upgrade script work.

Comments (0)

Files changed (3)

file/src/org/netbeans/modules/jackpot30/file/DeclarativeFix.java

     }
 
     public static DeclarativeFix parse(String spec) {
-        String[] s = DeclarativeHintRegistry.splitNameAndPattern(spec);
+        String[] s = DeclarativeHintRegistry.splitNameAndPattern(spec, null);
 
         return new DeclarativeFix(s[1], s[0]);
     }

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

             fixes.add(DeclarativeFix.parse(s));
         }
 
-        String[] s = splitNameAndPattern(split.get(0));
+        String[] s = splitNameAndPattern(split.get(0), "TODO: No display name");
 
         Map<String, String> constraints = new HashMap<String, String>();
         String pattern = parseOutTypesFromPattern(s[1], constraints);
                                      .produce();
     }
 
-    static String[] splitNameAndPattern(String spec) {
+    static String[] splitNameAndPattern(String spec, String defaultDisplayName) {
         spec = spec.trim();
 
-        String[] s = spec.split("\"");
+        String[] s = spec.split("\":");
 
         if (s.length == 1) {
             return new String[] {
-                "TODO: No display name",
+                defaultDisplayName,
                 spec
             };
         }
+
+        String[] captionAndWS = s[0].split("\"");
+
         return new String[] {
-            s[1],
-            s[2].substring(1)
+            captionAndWS[1],
+            s[1]
         };
     }
 
     private static String parseOutTypesFromPattern(String pattern, Map<String, String> constraints) {
-        //XXX:
-        Pattern p = Pattern.compile("(\\$.)(\\{([^}]*)\\})?");
+        Pattern p = Pattern.compile("(\\$[A-Za-z0-9_]+)(\\{([^}]*)\\})?");
         StringBuffer filtered = new StringBuffer();
         Matcher m = p.matcher(pattern);
         int i = 0;

file/test/unit/src/org/netbeans/modules/jackpot30/file/DeclarativeHintRegistryTest.java

 
     @Test
     public void testParse() {
-        HintDescription h = DeclarativeHintRegistry.parse("\"test\":$1:java.io.File:.toURL()=>\"fix\":$1.toURI().toURL()");
+        HintDescription h = DeclarativeHintRegistry.parse("\"test\":$1A{java.io.File}.toURL()=>\"fix\":$1B.toURI().toURL()");
+        String textRepr = dumpDescription(h);
         
+        assertEquals("{$1A.toURL()}{test}=>{$1B.toURI().toURL()}{fix};", textRepr);
+    }
+
+    @Test
+    public void testParseNoFixName() {
+        HintDescription h = DeclarativeHintRegistry.parse("\"test\":$1A{java.io.File}.toURL()=>$1B.toURI().toURL()");
+        String textRepr = dumpDescription(h);
+
+        assertEquals("{$1A.toURL()}{test}=>{$1B.toURI().toURL()};", textRepr);
+    }
+
+    private static String dumpDescription(HintDescription h) {
         StringBuilder dump = new StringBuilder();
 
         dump.append("{");
         dump.append("{");
 
         DeclarativeHintsWorker w = (DeclarativeHintsWorker) h.getWorker();
-        
+
         dump.append(w.getDisplayName());
         dump.append("}");
 
             dump.append("=>{");
             dump.append(f.getPattern());
             dump.append("}");
-            dump.append("{");
-            dump.append(f.getDisplayName());
-            dump.append("}");
+            if (f.getDisplayName() != null) {
+                dump.append("{");
+                dump.append(f.getDisplayName());
+                dump.append("}");
+            }
         }
 
         dump.append(";");
 
-        assertEquals("{$1:java.io.File:.toURL()}{test}=>{$1.toURI().toURL()}{fix};", dump.toString());
+        return dump.toString();
     }
 
 }