Commits

Jan Lahoda committed fa689df

Support for overlapping pattern occurrences (hack).

  • Participants
  • Parent commits 9fab0d5

Comments (0)

Files changed (2)

api/src/org/netbeans/modules/jackpot30/impl/pm/BulkSearch.java

 
         long s2 = System.currentTimeMillis();
         Matcher m = pattern.toRegexpPattern().matcher(serialized);
+        int start = 0; //XXX: hack to allow matches inside other matches (see testTwoPatterns)
 
 //        System.err.println("matcher=" + (System.currentTimeMillis() - s2));
 
-        while (m.find()) {
+        while (m.find(start)) {
             for (int cntr = 0; cntr < pattern.groups.length; cntr++) {
                 if (m.group(pattern.groups[cntr]) != null) {
                     String patt = pattern.original.get(cntr);
                     occurrences.addAll(serializedEnd2Tree.get(m.end()));
                 }
             }
+
+            start = m.start() + 1;
         }
 
         long e2 = System.currentTimeMillis();

api/test/unit/src/org/netbeans/modules/jackpot30/impl/pm/BulkSearchTest.java

 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
                     Collections.<String>emptyList());
     }
 
+    public void testTwoPatterns() throws Exception {
+        Map<String, List<String>> contained = new HashMap<String, List<String>>();
+
+        contained.put("if ($a) $ret = $b; else $ret = $c;", Arrays.asList("if (b) q = 2; else q = 3;"));
+        contained.put("{ $p$; $T $v; if($a) $v = $b; else $v = $c; $q$; }", Arrays.asList("{ int q = 3; if (b) q = 2; else q = 3; }"));
+        
+        performTest("package test; public class Test { public void test1(boolean b) { int q = 3; if (b) q = 2; else q = 3; } }",
+                    contained,
+                    Collections.<String>emptyList());
+    }
+
     public void XtestMeasureTime() throws Exception {
         String code = TestUtilities.copyFileToString(new File("/usr/local/home/lahvac/src/nb//outgoing/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java"));
         List<String> patterns = new LinkedList<String>();