From 9fcd0d98f797f539c713e3e1eb22785ee852e650 Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 8 Feb 2010 12:07:57 +0300 Subject: [PATCH] rename: suggest lower cased for non staticfinal (IDEA-13418) --- .../rename/JavaNameSuggestionProvider.java | 42 ++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/rename/JavaNameSuggestionProvider.java b/java/java-impl/src/com/intellij/refactoring/rename/JavaNameSuggestionProvider.java index 45c32fbfe8..a670185f3d 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/JavaNameSuggestionProvider.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/JavaNameSuggestionProvider.java @@ -80,7 +80,7 @@ public class JavaNameSuggestionProvider implements NameSuggestionProvider { } final String[] strings = info != null ? info.names : ArrayUtil.EMPTY_STRING_ARRAY; ArrayList list = new ArrayList(Arrays.asList(strings)); - final String properlyCased = suggestProperlyCasedName(element); + final String[] properlyCased = suggestProperlyCasedName(element); if (!list.contains(initialName)) { list.add(0, initialName); } @@ -89,8 +89,10 @@ public class JavaNameSuggestionProvider implements NameSuggestionProvider { list.remove(i); list.add(0, initialName); } - if (properlyCased != null && !properlyCased.equals(initialName)) { - list.add(1, properlyCased); + if (properlyCased != null) { + for (String properlyCasedSuggestion : properlyCased) { + list.add(1, properlyCasedSuggestion); + } } if (parameterName != null && !list.contains(parameterName)) { list.add(parameterName); @@ -137,7 +139,7 @@ public class JavaNameSuggestionProvider implements NameSuggestionProvider { } @Nullable - private static String suggestProperlyCasedName(PsiElement psiElement) { + private static String[] suggestProperlyCasedName(PsiElement psiElement) { if (!(psiElement instanceof PsiNamedElement)) return null; String name = ((PsiNamedElement)psiElement).getName(); if (name == null) return null; @@ -156,25 +158,29 @@ public class JavaNameSuggestionProvider implements NameSuggestionProvider { if (i > 0) buffer.append('_'); buffer.append(word.toUpperCase()); } - return buffer.toString(); + return new String[] {buffer.toString()}; } else { - StringBuilder buffer = new StringBuilder(prefix); - for (int i = 0; i < words.length; i++) { - String word = words[i]; - final boolean prefixRequiresCapitalization = prefix.length() > 0 && !StringUtil.endsWithChar(prefix, '_'); - if (i > 0 || prefixRequiresCapitalization) { - buffer.append(StringUtil.capitalize(word)); - } - else { - buffer.append(StringUtil.decapitalize(word)); - } - } - return buffer.toString(); + return new String[]{suggestProperlyCasedName(prefix, words), suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name.toLowerCase()))}; } } - return name; + return new String[]{name}; + } + + private static String suggestProperlyCasedName(String prefix, String[] words) { + StringBuilder buffer = new StringBuilder(prefix); + for (int i = 0; i < words.length; i++) { + String word = words[i]; + final boolean prefixRequiresCapitalization = prefix.length() > 0 && !StringUtil.endsWithChar(prefix, '_'); + if (i > 0 || prefixRequiresCapitalization) { + buffer.append(StringUtil.capitalize(word)); + } + else { + buffer.append(StringUtil.decapitalize(word)); + } + } + return buffer.toString(); } @Nullable -- 2.11.4.GIT