From 2e5edb09b52199eb0b1e2570debc1ce3152deac9 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 18 Jul 2012 11:10:00 +0200 Subject: [PATCH] one-letter prefix is not a subject for middle-word matching --- .../completion/CompletionStyleTest.java | 1 - .../completion/JavaAutoPopupTest.groovy | 10 +++++++--- .../completion/JavadocCompletionTest.java | 2 +- .../completion/KeywordCompletionTest.java | 4 ++-- .../completion/VariablesCompletionTest.groovy | 2 +- .../lookup/impl/BackspaceHandler.java | 4 ++++ .../com/intellij/psi/util/NameUtilTest.java | 19 +++++++++++++----- .../psi/codeStyle/MinusculeMatcher.java | 20 +++++++++++++++++++ 8 files changed, 49 insertions(+), 13 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java index 28ac231a533a..0ad4a0585a4a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java @@ -110,7 +110,6 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{ configureByFile(path + "/before3.java"); performSmartCompletion(); - select(Lookup.NORMAL_SELECT_CHAR, 0); checkResultByFile(path + "/after3.java"); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index 3f2a50a1d1b2..8f8b427b5e14 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -558,11 +558,15 @@ public interface Test { edt { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT) } assert myFixture.editor.caretModel.offset == offset + 1 + joinAutopopup() + joinCompletion() assertContains "iterable" assertEquals 'iterable', lookup.currentItem.lookupString edt { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT) } assert myFixture.editor.caretModel.offset == offset + joinAutopopup() + joinCompletion() assertContains "if", "iterable", "int" assertEquals 'iterable', lookup.currentItem.lookupString @@ -773,7 +777,7 @@ class Foo { public void testRestartWithVisibleLookup() { registerContributor(LongContributor, LoadingOrder.FIRST) - myFixture.configureByText("a.java", """ class Foo { { int abcdef; a } } """) + myFixture.configureByText("a.java", """ class Foo { { int abcdef, abcdefg; ab } } """) myFixture.completeBasic() while (!lookup.shown) { Thread.sleep(1) @@ -781,10 +785,10 @@ class Foo { def l = lookup edt { assert lookup.calculating - myFixture.type 'b' + myFixture.type 'c' } joinCommit { - myFixture.type 'c' + myFixture.type 'd' } joinAutopopup() joinCompletion() diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavadocCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavadocCompletionTest.java index 1f16310242b1..10751eac788d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavadocCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavadocCompletionTest.java @@ -54,7 +54,7 @@ public class JavadocCompletionTest extends LightFixtureCompletionTestCase { public void testNamesInMethod1() throws Exception { configureByFile("MethodTagName1.java"); - assertStringItems("see", "serialData", "since", "class", "throws"); + assertStringItems("see", "serialData", "since"); } public void testParamValueCompletion() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java index 21afce411e6f..97498c8b06eb 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java @@ -85,9 +85,9 @@ public class KeywordCompletionTest extends LightCompletionTestCase { public void testNullInIf() throws Exception { doTest(true); } public void testNullInReturn() throws Exception { doTest(true); } public void testExtendsInMethodParameters() throws Exception { doTest(false); } - public void testInstanceOf1() throws Exception { doTest(true); } + public void testInstanceOf1() throws Exception { doTest(false); } public void testInstanceOf2() throws Exception { doTest(false); } - public void testInstanceOf3() throws Exception { doTest(true); } + public void testInstanceOf3() throws Exception { doTest(false); } public void testCatchFinally() throws Exception { doTest(2, "catch", "finally"); } public void testSuper1() throws Exception { doTest(1, "super"); } public void testSuper2() throws Exception { doTest(0, "super"); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.groovy index 2d471c627e2b..4f40bd5d2ddc 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.groovy @@ -137,7 +137,7 @@ public class VariablesCompletionTest extends LightFixtureCompletionTestCase { } public void testFieldOutOfAnonymous() throws Exception { - doSelectTest("TestFieldOutOfAnonymous.java", "TestFieldOutOfAnonymousResult.java"); + doTest("TestFieldOutOfAnonymous.java", "TestFieldOutOfAnonymousResult.java"); } public void testUnresolvedMethodName() throws Exception { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/BackspaceHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/BackspaceHandler.java index 6075d795e216..4a83afe90d10 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/BackspaceHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/BackspaceHandler.java @@ -56,6 +56,10 @@ public class BackspaceHandler extends EditorActionHandler { return; } + if (process != null) { + process.prefixUpdated(); + } + if (hideOffset < editor.getCaretModel().getOffset()) { if (process != null) { process.scheduleRestart(); diff --git a/platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilTest.java b/platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilTest.java index 0351dafcd2b0..898f5bc39e0d 100644 --- a/platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilTest.java +++ b/platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilTest.java @@ -214,6 +214,15 @@ public class NameUtilTest extends UsefulTestCase { assertMatches("text*:sh", "textField:shouldChangeCharactersInRange:replacementString:"); } + public void testMiddleMatchingMinimumTwoConsecutiveLettersInWordMiddle() { + assertMatches("*fo", "reformat"); + assertMatches("*f", "reFormat"); + assertMatches("*f", "format"); + assertMatches("*f", "Format"); + assertMatches("*Stri", "string"); + assertDoesntMatch("*f", "reformat"); + } + public void testMiddleMatching() { assertTrue(caseInsensitiveMatcher("*old").matches("folder")); assertMatches("SWU*H*7", "SWUpgradeHdlrFSPR7Test"); @@ -395,9 +404,9 @@ public class NameUtilTest extends UsefulTestCase { public void testPreferStartMatchToMiddleMatch() { assertPreference(" fb", "FooBar", "_fooBar", NameUtil.MatchingCaseSensitivity.NONE); assertPreference("*foo", "barFoo", "foobar"); - assertPreference("*f", "barfoo", "barFoo"); - assertPreference("*f", "barfoo", "foo"); - assertPreference("*f", "asdf", "Foo", NameUtil.MatchingCaseSensitivity.NONE); + assertPreference("*fo", "barfoo", "barFoo"); + assertPreference("*fo", "barfoo", "foo"); + assertPreference("*fo", "asdfo", "Foo", NameUtil.MatchingCaseSensitivity.NONE); assertPreference(" sto", "ArrayStoreException", "StackOverflowError", NameUtil.MatchingCaseSensitivity.NONE); assertPreference(" EUC-", "x-EUC-TW", "EUC-JP"); assertPreference(" boo", "Boolean", "boolean", NameUtil.MatchingCaseSensitivity.NONE); @@ -450,10 +459,10 @@ public class NameUtilTest extends UsefulTestCase { public void run() { for (int i = 0; i < 100000; i++) { for (MinusculeMatcher matcher : matching) { - assertTrue(matcher.matches(longName)); + assertTrue(matcher.toString(), matcher.matches(longName)); } for (MinusculeMatcher matcher : nonMatching) { - assertFalse(matcher.matches(longName)); + assertFalse(matcher.toString(), matcher.matches(longName)); } } } diff --git a/platform/util/src/com/intellij/psi/codeStyle/MinusculeMatcher.java b/platform/util/src/com/intellij/psi/codeStyle/MinusculeMatcher.java index 0340f9d67652..a3111469116b 100644 --- a/platform/util/src/com/intellij/psi/codeStyle/MinusculeMatcher.java +++ b/platform/util/src/com/intellij/psi/codeStyle/MinusculeMatcher.java @@ -177,6 +177,7 @@ public class MinusculeMatcher implements Matcher { @Nullable private FList skipChars(String name, int patternIndex, int nameIndex, boolean maySkipNextChar) { + boolean veryStart = patternIndex == 0; while ('*' == myPattern[patternIndex]) { patternIndex++; if (patternIndex == myPattern.length) { @@ -201,6 +202,17 @@ public class MinusculeMatcher implements Matcher { continue; } + if (veryStart && next > 0 && !NameUtil.isWordStart(name, next)) { + if (next == name.length() - 1) { + return null; + } + if (patternIndex == myPattern.length - 1 || + myPattern[patternIndex + 1] != name.charAt(next + 1) && Character.isLetter(myPattern[patternIndex + 1])) { + fromIndex = next + 1; + continue; + } + } + FList ranges = matchName(name, patternIndex, next); if (ranges != null) { return ranges; @@ -324,4 +336,12 @@ public class MinusculeMatcher implements Matcher { return matchName(name, 0, 0); } + + @Override + public String toString() { + return "MinusculeMatcher{" + + "myPattern=" + new String(myPattern) + + ", myOptions=" + myOptions + + '}'; + } }