accessor name convention
authorMaxim Medvedev <maxim.medvedev@jetbrains.com>
Tue, 10 Nov 2009 13:36:08 +0000 (16:36 +0300)
committerMaxim Medvedev <maxim.medvedev@jetbrains.com>
Wed, 11 Nov 2009 09:42:28 +0000 (12:42 +0300)
java/openapi/src/com/intellij/psi/util/PropertyUtil.java
platform/util/src/com/intellij/openapi/util/text/StringUtil.java

index e60bded0ee716d509f25332e0d9b80be55e651c0..b28d808c2a35904a62d2557dd57f901686419a90 100644 (file)
@@ -296,7 +296,7 @@ public class PropertyUtil {
   }
 
   public static String suggestGetterName(@NotNull String propertyName, @Nullable PsiType propertyType, @NonNls String existingGetterName) {
-    @NonNls StringBuffer name = new StringBuffer(StringUtil.capitalize(propertyName));
+    @NonNls StringBuffer name = new StringBuffer(StringUtil.capitalizeWithJavaBeanConvention(propertyName));
     if (isBoolean(propertyType)) {
       if (existingGetterName == null || !existingGetterName.startsWith("get")) {
         name.insert(0, "is");
@@ -319,12 +319,12 @@ public class PropertyUtil {
 
   @NonNls
   public static String[] suggestGetterNames(String propertyName) {
-    final String str = StringUtil.capitalize(propertyName);
+    final String str = StringUtil.capitalizeWithJavaBeanConvention(propertyName);
     return new String[] { "is" + str, "get" + str };
   }
 
   public static String suggestSetterName(String propertyName) {
-    @NonNls StringBuffer name = new StringBuffer(StringUtil.capitalize(propertyName));
+    @NonNls StringBuffer name = new StringBuffer(StringUtil.capitalizeWithJavaBeanConvention(propertyName));
     name.insert(0, "set");
     return name.toString();
   }
index 5a196ff2aa7c4405bd8cdb0588663f28deabd317..8de7b5992d8081784497197dacd293cddc4c6c8e 100644 (file)
@@ -610,6 +610,14 @@ public class StringUtil {
     return toUpperCase(s.charAt(0)) + s.substring(1);
   }
 
+  @NotNull
+  public static String capitalizeWithJavaBeanConvention(@NotNull String s) {
+    if (s.length() > 1 && Character.isUpperCase(s.charAt(1))) {
+      return s;
+    }
+    return capitalize(s);
+  }
+
   public static int stringHashCode(CharSequence chars) {
     if (chars instanceof String) return chars.hashCode();
     if (chars instanceof CharSequenceWithStringHash) return chars.hashCode();