include underscore matches into matching fragments
authorpeter <peter@jetbrains.com>
Wed, 25 Jan 2012 12:10:19 +0000 (13:10 +0100)
committerpeter <peter@jetbrains.com>
Wed, 25 Jan 2012 12:10:59 +0000 (13:10 +0100)
platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilTest.java
platform/util/src/com/intellij/psi/codeStyle/NameUtil.java

index 1a4bbac2867d1619f2849fa4689c81f1ec77c8b3..a018f4dd6000faec877494e0ec6231b9f2b65aa8 100644 (file)
@@ -282,6 +282,11 @@ public class NameUtilTest extends UsefulTestCase {
     assertOrderedEquals(new NameUtil.MinusculeMatcher("doge*st", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample),
                         TextRange.from(0, 4), TextRange.from(22, 2));
 
+    sample = "_test";
+    assertOrderedEquals(new NameUtil.MinusculeMatcher("_", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample),
+                        TextRange.from(0, 1));
+    assertOrderedEquals(new NameUtil.MinusculeMatcher("_t", NameUtil.MatchingCaseSensitivity.NONE).matchingFragments(sample),
+                        TextRange.from(0, 2));
   }
 
   public void testMatchingDegree() {
index c20e0b586745eaa9b85006e6af9fc48cfec2a583..7eea21fb31ea34c6faa9d5707be533def68fbf83 100644 (file)
@@ -486,17 +486,21 @@ public class NameUtil {
       while (i > 0) {
         FList<TextRange> ranges = matchName(name, patternIndex + i, nextStart);
         if (ranges != null) {
-          TextRange head = ranges.getHead();
-          if (head != null && head.getStartOffset() == nameIndex + i) {
-            return ranges.getTail().prepend(new TextRange(nameIndex, head.getEndOffset()));
-          }
-          return ranges.prepend(TextRange.from(nameIndex, i));
+          return prependRange(ranges, nameIndex, i);
         }
         i--;
       }
       return null;
     }
 
+    private static FList<TextRange> prependRange(FList<TextRange> ranges, int from, int to) {
+      TextRange head = ranges.getHead();
+      if (head != null && head.getStartOffset() == from + to) {
+        return ranges.getTail().prepend(new TextRange(from, head.getEndOffset()));
+      }
+      return ranges.prepend(TextRange.from(from, to));
+    }
+
     private boolean isWordSeparator(char c) {
       return mySeparatorFunction.fun(c);
     }
@@ -513,7 +517,12 @@ public class NameUtil {
           return null;
         }
 
-        return matchName(name, patternIndex + 1, nextStart);
+        final FList<TextRange> ranges = matchName(name, patternIndex + 1, nextStart);
+        if (ranges != null) {
+          return prependRange(ranges, patternIndex, patternIndex + 1);
+        }
+
+        return ranges;
       }
 
       return matchName(name, patternIndex, nextStart);