diff --git a/platform/platform-tests/testSrc/com/intellij/psi/codeStyle/TypoTolerantMatcherTest.java b/platform/platform-tests/testSrc/com/intellij/psi/codeStyle/TypoTolerantMatcherTest.java index b2b790e5e762..f1e865fe0eb3 100644 --- a/platform/platform-tests/testSrc/com/intellij/psi/codeStyle/TypoTolerantMatcherTest.java +++ b/platform/platform-tests/testSrc/com/intellij/psi/codeStyle/TypoTolerantMatcherTest.java @@ -8,7 +8,7 @@ import java.util.List; import java.util.SplittableRandom; import java.util.stream.Stream; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; public class TypoTolerantMatcherTest { @Test @@ -42,4 +42,11 @@ public class TypoTolerantMatcherTest { List expected = List.of("foo", "bar", "buzz"); assertEquals(expected, matched); } + + @Test + public void testLongPattern() { + MinusculeMatcher matcher = NameUtil.buildMatcher("MyLongTestClassName").typoTolerant().build(); + assertFalse(matcher instanceof TypoTolerantMatcher); + assertTrue(matcher.matches("MyLongTestClassName")); + } } diff --git a/platform/util/text-matching/src/com/intellij/psi/codeStyle/NameUtil.java b/platform/util/text-matching/src/com/intellij/psi/codeStyle/NameUtil.java index 4d8b670abd48..c75b5508a55a 100644 --- a/platform/util/text-matching/src/com/intellij/psi/codeStyle/NameUtil.java +++ b/platform/util/text-matching/src/com/intellij/psi/codeStyle/NameUtil.java @@ -13,6 +13,8 @@ import java.util.function.Function; public final class NameUtil { private static final int MAX_LENGTH = 40; + //heuristics: 15 can take 10-20 ms in some cases, while 10 works in 1-5 ms + private static final int TYPO_AWARE_PATTERN_LIMIT = 13; private NameUtil() {} @@ -295,7 +297,7 @@ public final class NameUtil { } public MatcherBuilder typoTolerant() { - this.typoTolerant = true; + this.typoTolerant = pattern.length() <= TYPO_AWARE_PATTERN_LIMIT; return this; } diff --git a/platform/util/text-matching/src/com/intellij/psi/codeStyle/TypoTolerantMatcher.java b/platform/util/text-matching/src/com/intellij/psi/codeStyle/TypoTolerantMatcher.java index 797c2d2a045a..55e2cdd5685d 100644 --- a/platform/util/text-matching/src/com/intellij/psi/codeStyle/TypoTolerantMatcher.java +++ b/platform/util/text-matching/src/com/intellij/psi/codeStyle/TypoTolerantMatcher.java @@ -15,10 +15,6 @@ import java.util.BitSet; import java.util.List; final class TypoTolerantMatcher extends MinusculeMatcher { - - //heuristics: 15 can take 10-20 ms in some cases, while 10 works in 1-5 ms - private static final int TYPO_AWARE_PATTERN_LIMIT = 13; - private final char[] myPattern; private final String myHardSeparators; private final NameUtil.MatchingCaseSensitivity myOptions; @@ -231,9 +227,6 @@ final class TypoTolerantMatcher extends MinusculeMatcher { FList ranges = new Session(name, false, ascii).matchingFragments(); if (ranges != null) return ranges; - //do not apply typo aware matching for long patterns, it can take too much time - if (myPattern.length > TYPO_AWARE_PATTERN_LIMIT) return null; - return new Session(name, true, ascii).matchingFragments(); } @@ -281,8 +274,6 @@ final class TypoTolerantMatcher extends MinusculeMatcher { } public @Nullable FList matchingFragments() { - if (myPattern.length > TYPO_AWARE_PATTERN_LIMIT) return null; - int length = myName.length(); if (length < myMinNameLength) { return null;