From c622695382df5146548b31c5de588c7d954ec645 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 30 Mar 2011 18:13:33 +0200 Subject: [PATCH] minuscule matching by default --- .../normal/EnumWithoutConstants.java | 2 +- .../normal/EnumWithoutConstants_after.java | 2 +- .../normalSorting/HonorUppercaseLetters.java | 6 ---- .../normalSorting/UppercaseMatters.java | 8 ----- .../normalSorting/UppercaseMatters2.java | 8 ----- .../NormalCompletionOrderingTest.java | 29 +----------------- .../completion/VariablesCompletionTest.java | 7 ----- .../completion/CompletionTestCase.java | 14 +++++++++ .../completion/impl/CamelHumpMatcher.java | 22 ++++++-------- .../src/misc/registry.properties | 2 +- .../com/intellij/psi/codeStyle/NameUtil.java | 30 ++++++++++++------- 11 files changed, 47 insertions(+), 83 deletions(-) delete mode 100644 java/java-tests/testData/codeInsight/completion/normalSorting/HonorUppercaseLetters.java delete mode 100644 java/java-tests/testData/codeInsight/completion/normalSorting/UppercaseMatters.java delete mode 100644 java/java-tests/testData/codeInsight/completion/normalSorting/UppercaseMatters2.java diff --git a/java/java-tests/testData/codeInsight/completion/normal/EnumWithoutConstants.java b/java/java-tests/testData/codeInsight/completion/normal/EnumWithoutConstants.java index 6cf0d47ebe80..ea1066eea019 100644 --- a/java/java-tests/testData/codeInsight/completion/normal/EnumWithoutConstants.java +++ b/java/java-tests/testData/codeInsight/completion/normal/EnumWithoutConstants.java @@ -1 +1 @@ -public enum Foo { private Fo } \ No newline at end of file +public enum Foooooo { private Fooo } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normal/EnumWithoutConstants_after.java b/java/java-tests/testData/codeInsight/completion/normal/EnumWithoutConstants_after.java index 99cf939d827e..0aef69ab4fdd 100644 --- a/java/java-tests/testData/codeInsight/completion/normal/EnumWithoutConstants_after.java +++ b/java/java-tests/testData/codeInsight/completion/normal/EnumWithoutConstants_after.java @@ -1 +1 @@ -public enum Foo { private Foo } \ No newline at end of file +public enum Foooooo { private Foooooo } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normalSorting/HonorUppercaseLetters.java b/java/java-tests/testData/codeInsight/completion/normalSorting/HonorUppercaseLetters.java deleted file mode 100644 index b4dac6bdb4d2..000000000000 --- a/java/java-tests/testData/codeInsight/completion/normalSorting/HonorUppercaseLetters.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Beda { - { - Object clsLoader; - cL - } -} diff --git a/java/java-tests/testData/codeInsight/completion/normalSorting/UppercaseMatters.java b/java/java-tests/testData/codeInsight/completion/normalSorting/UppercaseMatters.java deleted file mode 100644 index ab7af0549fa2..000000000000 --- a/java/java-tests/testData/codeInsight/completion/normalSorting/UppercaseMatters.java +++ /dev/null @@ -1,8 +0,0 @@ -class Foo { - { - Object classLoader; - Object classBeforeLoader; - cL - } - -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normalSorting/UppercaseMatters2.java b/java/java-tests/testData/codeInsight/completion/normalSorting/UppercaseMatters2.java deleted file mode 100644 index 19fc5f857151..000000000000 --- a/java/java-tests/testData/codeInsight/completion/normalSorting/UppercaseMatters2.java +++ /dev/null @@ -1,8 +0,0 @@ -class Foo { - { - Object classLoader; - Object classLoader2; - cL - } - -} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java index 787b21cc96f6..9c45f1491166 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java @@ -5,7 +5,6 @@ package com.intellij.codeInsight.completion; import com.intellij.JavaTestUtil; -import com.intellij.codeInsight.CodeInsightSettings; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.impl.LookupImpl; import com.intellij.psi.PsiClass; @@ -68,32 +67,6 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase { checkPreferredItems(0, "getService", "getService", "class"); } - public void testUppercaseMatters() throws Throwable { - final int old = CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE; - try { - CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER; - checkPreferredItems(0, "classLoader", "class", "classBeforeLoader", "clone"); - } - finally { - CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = old; - } - } - - public void testUppercaseMatters2() throws Throwable { - final int old = CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE; - try { - CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.ALL; - checkPreferredItems(0, "classLoader", "classLoader2"); - } - finally { - CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = old; - } - } - - public void testHonorUppercaseLetters() throws Throwable { - checkPreferredItems(0, "clsLoader", "clone", "class"); - } - public void testClassStaticMembersInVoidContext() throws Throwable { checkPreferredItems(0, "booleanMethod", "voidMethod", "AN_OBJECT", "BOOLEAN", "class"); } @@ -232,4 +205,4 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase { checkPreferredItems(0, "Bar9", "Bar1", "Bar2", "Bar3", "Bar4"); } -} \ No newline at end of file +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.java index 6c4ebbe4c565..e094aef705b4 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.java @@ -142,11 +142,4 @@ public class VariablesCompletionTest extends CompletionTestCase { assertStringItems(LineTokenizer.tokenize(FileDocumentManager.getInstance().getDocument(result).getCharsSequence(), false)); } - - private void assertStringItems(String... strings) { - assertNotNull(myItems); - for (int i = 0; i < myItems.length; i++) { - assertEquals(strings[i], myItems[i].toString()); - } - } } diff --git a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionTestCase.java b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionTestCase.java index 5ce8f5f978da..d91987d1302b 100644 --- a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionTestCase.java @@ -7,9 +7,12 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl; import com.intellij.psi.statistics.StatisticsManager; import com.intellij.psi.statistics.impl.StatisticsManagerImpl; import com.intellij.testFramework.PlatformTestCase; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Nullable; import java.util.Arrays; +import java.util.List; /** * @author mike @@ -95,4 +98,15 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase { protected LookupImpl getActiveLookup() { return (LookupImpl)LookupManager.getActiveLookup(myEditor); } + + protected void assertStringItems(String... strings) { + assertNotNull(myItems); + List actual = ContainerUtil.map(myItems, new Function() { + @Override + public String fun(LookupElement element) { + return element.getLookupString(); + } + }); + assertOrderedEquals(actual, strings); + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CamelHumpMatcher.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CamelHumpMatcher.java index ae7fd6f9295b..c3670d93f9bf 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CamelHumpMatcher.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CamelHumpMatcher.java @@ -49,10 +49,10 @@ public class CamelHumpMatcher extends PrefixMatcher { ourLastCompletionCaseSetting = currentSetting; } - myMatcher = obtainMatcher(myRelaxedMatching); + myMatcher = obtainMatcher(myRelaxedMatching, myCaseSensitive); } if (myMatcher.matches(name)) { - if (myRelaxedMatching && obtainMatcher(false).matches(name)) { + if (myRelaxedMatching && obtainMatcher(false, myCaseSensitive).matches(name)) { return false; } @@ -62,11 +62,11 @@ public class CamelHumpMatcher extends PrefixMatcher { } } - private NameUtil.Matcher obtainMatcher(final boolean relax) { - String key = relax + myPrefix; + private NameUtil.Matcher obtainMatcher(final boolean relax, final boolean caseSensitive) { + String key = relax + myPrefix + caseSensitive; NameUtil.Matcher pattern = ourPatternCache.get(key); if (pattern == null) { - pattern = createCamelHumpsMatcher(relax); + pattern = createCamelHumpsMatcher(relax, caseSensitive); ourPatternCache.put(key, pattern); } return pattern; @@ -86,12 +86,8 @@ public class CamelHumpMatcher extends PrefixMatcher { if (itemCaseInsensitive && StringUtil.startsWithIgnoreCase(name, myPrefix) || prefixMatches(name)) { return true; } - if (itemCaseInsensitive && - CodeInsightSettings.ALL != CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE && - name.length() > 0) { - final char c = name.charAt(0); - String swappedCase = (Character.isUpperCase(c) ? Character.toLowerCase(c) : Character.toUpperCase(c)) + name.substring(1); - if (prefixMatches(swappedCase)) { + if (itemCaseInsensitive && CodeInsightSettings.ALL != CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) { + if (obtainMatcher(false, false).matches(name)) { return true; } } @@ -104,8 +100,8 @@ public class CamelHumpMatcher extends PrefixMatcher { return new CamelHumpMatcher(prefix, myCaseSensitive, myRelaxedMatching); } - private NameUtil.Matcher createCamelHumpsMatcher(final boolean relaxedMatching) { - if (!myCaseSensitive) { + private NameUtil.Matcher createCamelHumpsMatcher(final boolean relaxedMatching, final boolean caseSensitive) { + if (!caseSensitive) { return NameUtil.buildCompletionMatcher(myPrefix, 0, true, true); } diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index e2f11f731887..05be970b0c44 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -121,7 +121,7 @@ navbar.userActivityMergeTime=500 navbar.newpopup=true inspectionGadgets.telemetry.enabled=false -minuscule.humps.matching=false +minuscule.humps.matching=true minuscule.humps.matching.description=Camel Case without holding Shift in Ctrl+N/Ctrl+Shift+N etc jvmbugfix.mac.caccessibleLeak=true diff --git a/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java b/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java index 5d9283210452..21b842ddef2a 100644 --- a/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java +++ b/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java @@ -317,6 +317,10 @@ public class NameUtil { private enum WordState { NO_WORD, PREV_UC, WORD } + private static boolean isWordStart(char p) { + return Character.isUpperCase(p) || Character.isDigit(p); + } + private static void addAllWords(String word, List result) { CharacterIterator it = new StringCharacterIterator(word); StringBuffer b = new StringBuffer(); @@ -325,7 +329,7 @@ public class NameUtil { for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) { switch (state) { case NO_WORD: - if (!Character.isUpperCase(c)) { + if (!isWordStart(c)) { b.append(c); state = WordState.WORD; } @@ -335,7 +339,7 @@ public class NameUtil { } break; case PREV_UC: - if (!Character.isUpperCase(c)) { + if (!isWordStart(c)) { b = startNewWord(result, b, curPrevUC); b.append(c); state = WordState.WORD; @@ -347,7 +351,7 @@ public class NameUtil { } break; case WORD: - if (Character.isUpperCase(c)) { + if (isWordStart(c)) { startNewWord(result, b, c); b.setLength(0); state = WordState.PREV_UC; @@ -475,14 +479,13 @@ public class NameUtil { } } - public static class MinusculeMatcher implements Matcher { private final char[] myPattern; private final boolean myFirstLetterCaseMatters; public MinusculeMatcher(String pattern, boolean firstLetterCaseMatters) { myFirstLetterCaseMatters = firstLetterCaseMatters; - myPattern = pattern.replaceAll(":", "\\*:").replaceAll("\\.", "\\*\\.").toCharArray(); + myPattern = StringUtil.trimEnd(pattern, "* ").replaceAll(":", "\\*:").replaceAll("\\.", "\\*\\.").toCharArray(); } private boolean matches(int patternIndex, List words, int wordIndex) { @@ -501,7 +504,14 @@ public class NameUtil { if (isWordSeparator(w.charAt(0))) { assert w.length() == 1 : "'" + w + "'"; - return matches(isWordSeparator(myPattern[patternIndex]) ? patternIndex + 1 : patternIndex, words, wordIndex + 1); + if (isWordSeparator(myPattern[patternIndex])) { + return matches(patternIndex + 1, words, wordIndex + 1); + } + if (patternIndex == 0 && myFirstLetterCaseMatters) { + return false; + } + + return matches(patternIndex, words, wordIndex + 1); } if (patternIndex == 0 && myFirstLetterCaseMatters && w.charAt(0) != myPattern[0]) { @@ -512,7 +522,7 @@ public class NameUtil { return false; } - boolean uppers = Character.isUpperCase(myPattern[patternIndex]); + boolean uppers = isWordStart(myPattern[patternIndex]); int i = 1; while (true) { @@ -523,7 +533,7 @@ public class NameUtil { break; } char p = myPattern[patternIndex + i]; - if (uppers && Character.isUpperCase(p)) { + if (uppers && isWordStart(p)) { p = StringUtil.toLowerCase(p); } else { uppers = false; @@ -570,7 +580,7 @@ public class NameUtil { break; } List newWords = new ArrayList(); - newWords.add(s.substring(fromIndex)); + newWords.add(s.substring(next)); newWords.addAll(words.subList(i + 1, words.size())); if (matches(patternIndex, newWords, 0)) { return true; @@ -587,7 +597,7 @@ public class NameUtil { @Override public boolean matches(String name) { - StringTokenizer tokenizer = new StringTokenizer(name, " -_.:", true); + StringTokenizer tokenizer = new StringTokenizer(name, " -_.:/", true); List words = new ArrayList(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken();