From 753e91f815b47dcef63631fe0344edc61037f5d8 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Wed, 21 Oct 2009 18:19:21 +0400 Subject: [PATCH] IDEADEV-40041: the getter and setter method doesn't follow naming convention --- .../lang/psi/impl/statements/GrFieldImpl.java | 11 +++++------ .../groovy/lang/psi/util/GroovyPropertyUtils.java | 21 ++++++++++++++++++--- .../plugins/groovy/GroovyCompletionTest.java | 4 ++++ .../completion/PropertyWithSecondUpperLetter.groovy | 7 +++++++ 4 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 plugins/groovy/testdata/groovy/completion/PropertyWithSecondUpperLetter.groovy diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrFieldImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrFieldImpl.java index aa1dd54bab..4b5d6fb087 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrFieldImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrFieldImpl.java @@ -18,7 +18,6 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.statements; import com.intellij.lang.ASTNode; import com.intellij.navigation.ItemPresentation; import com.intellij.openapi.editor.colors.TextAttributesKey; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.search.SearchScope; @@ -138,8 +137,8 @@ public class GrFieldImpl extends GrVariableBaseImpl implements GrFi } public boolean isProperty() { - final String name = getName(); - if (!GroovyPropertyUtils.canBePropertyName(name)) return false; +// final String name = getName(); +// if (!GroovyPropertyUtils.canBePropertyName(name)) return false; final PsiClass clazz = getContainingClass(); if (clazz == null) return false; if (clazz.isInterface()) return false; @@ -153,7 +152,7 @@ public class GrFieldImpl extends GrVariableBaseImpl implements GrFi mySetter = null; if (isProperty() && !hasModifierProperty(PsiModifier.FINAL)) { - String name = "set" + StringUtil.capitalize(getName()); + String name = "set" + GroovyPropertyUtils.capitalize(getName()); final GrAccessorMethod setter = new GrAccessorMethodImpl(this, true, name); final PsiClass clazz = getContainingClass(); if (!hasContradictingMethods(setter, clazz)) { @@ -182,7 +181,7 @@ public class GrFieldImpl extends GrVariableBaseImpl implements GrFi if (isProperty()) { String name = getName(); final PsiClass clazz = getContainingClass(); - name = StringUtil.capitalize(name); + name = GroovyPropertyUtils.capitalize(name); GrAccessorMethod getter1 = new GrAccessorMethodImpl(this, false, "get" + name); if (hasContradictingMethods(getter1, clazz)) getter1 = null; @@ -304,7 +303,7 @@ public class GrFieldImpl extends GrVariableBaseImpl implements GrFi closure.accept(new GrNamedArgumentSearchVisitor(paramName, set)); } } - return namedParameters.toArray(new HashSet[0]); + return namedParameters.toArray(new HashSet[namedParameters.size()]); } public GrDocComment getGrDocComment() { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyPropertyUtils.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyPropertyUtils.java index e86e94a640..5e191f42d2 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyPropertyUtils.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyPropertyUtils.java @@ -25,6 +25,8 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod; +import java.beans.Introspector; + /** * @author ilyas */ @@ -131,10 +133,10 @@ public class GroovyPropertyUtils { @NonNls String methodName = getterMethod.getName(); if (methodName.startsWith("get") && methodName.length() > 3) { - return StringUtil.decapitalize(methodName.substring(3)); + return decapitalize(methodName.substring(3)); } else if (methodName.startsWith("is") && methodName.length() > 2 && PsiType.BOOLEAN.equals(getterMethod.getReturnType())) { - return StringUtil.decapitalize(methodName.substring(2)); + return decapitalize(methodName.substring(2)); } return methodName; } @@ -190,7 +192,20 @@ public class GroovyPropertyUtils { return Character.toUpperCase(c) == c; } - public static boolean canBePropertyName(String name) { + /*public static boolean canBePropertyName(String name) { return !(name.length() > 1 && Character.isUpperCase(name.charAt(1)) && Character.isLowerCase(name.charAt(0))); + }*/ + + public static String capitalize(String s) { + if (s.length() == 0) return s; + if (s.length() == 1) return s.toUpperCase(); + if (Character.isUpperCase(s.charAt(1))) return s; + final char[] chars = s.toCharArray(); + chars[0] = Character.toUpperCase(chars[0]); + return new String(chars); + } + + public static String decapitalize(String s) { + return Introspector.decapitalize(s); } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyCompletionTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyCompletionTest.java index 7a5446ed8d..347a8a03c5 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyCompletionTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyCompletionTest.java @@ -263,4 +263,8 @@ public class GroovyCompletionTest extends LightCodeInsightFixtureTestCase { myFixture.testCompletionVariants(getTestName(false) + ".groovy", "substring", "substring", "subSequence"); } + public void testPropertyWithSecondUpperLetter() throws Exception { + myFixture.testCompletionVariants(getTestName(false)+".groovy", "geteMail", "getePost"); + } + } diff --git a/plugins/groovy/testdata/groovy/completion/PropertyWithSecondUpperLetter.groovy b/plugins/groovy/testdata/groovy/completion/PropertyWithSecondUpperLetter.groovy new file mode 100644 index 0000000000..90def8d621 --- /dev/null +++ b/plugins/groovy/testdata/groovy/completion/PropertyWithSecondUpperLetter.groovy @@ -0,0 +1,7 @@ +class A{ + def eMail; + def ePost; +} + +def a=new A(); +a.gete \ No newline at end of file -- 2.11.4.GIT