IDEA-57510 reference resolve: class vs property getter rubymine/96.1146
authorMaxim Medvedev <maxim.medvedev@jetbrains.com>
Fri, 10 Sep 2010 15:22:54 +0000 (19:22 +0400)
committerMaxim Medvedev <maxim.medvedev@jetbrains.com>
Fri, 10 Sep 2010 15:22:54 +0000 (19:22 +0400)
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrFieldImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyPropertyUtils.java
plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveClassTest.java
plugins/groovy/testdata/resolve/class/classVsPropertyGetter/ClassVsPropertyGetter.groovy [new file with mode: 0644]

index 1d219c28b0be9a22145973e1471698562c111f15..63327d3da7efdb9768d62d989fd64f11678dd62f 100644 (file)
@@ -136,6 +136,7 @@ public class GrFieldImpl extends GrVariableBaseImpl<GrFieldStub> implements GrFi
     if (clazz == null) return false;
     if (clazz.isInterface()) return false;
     final GrModifierList modifierList = getModifierList();
+    if (GroovyPropertyUtils.isPropertyName(getName())) return false;
     return modifierList == null || !modifierList.hasExplicitVisibilityModifiers();
   }
 
index c11714c394cb6ade72f6e99a9be5acf1b4749cfd..3da290f0bc0b8aa900fdebbe4830e56130940cf8 100644 (file)
@@ -269,10 +269,18 @@ public class GroovyPropertyUtils {
    * @return getter names
    */
   public static String[] suggestGettersName(@NotNull String name) {
+    if (!isPropertyName(name)) return ArrayUtil.EMPTY_STRING_ARRAY;
     return new String[]{getGetterNameBoolean(name), getGetterNameNonBoolean(name)};
   }
 
+  public static boolean isPropertyName(String name) {
+    if (name.length() == 0) return false;
+    if (Character.isUpperCase(name.charAt(0)) && (name.length() == 1 || !Character.isUpperCase(name.charAt(1)))) return false;
+    return true;
+  }
+
   public static String[] suggestSettersName(@NotNull String name) {
+    if (!isPropertyName(name)) return ArrayUtil.EMPTY_STRING_ARRAY;
     return new String[]{getSetterName(name)};
   }
 
index 7def922777125146f0c46801027cdd5b588444a7..78c3e8ebad4d2c96d95b9c212335551b04997d2e 100644 (file)
@@ -139,11 +139,15 @@ public class ResolveClassTest extends GroovyResolveTestCase {
     assertNotNull(resolved);
   }
 
-  private void doTest() throws Exception {
+  public void testClassVsPropertyGetter() {
+    doTest();
+  }
+
+  private void doTest() {
     doTest(getTestName(true) + "/" + getTestName(false) + ".groovy");
   }
 
-  private void doTest(String fileName) throws Exception {
+  private void doTest(String fileName) {
     PsiReference ref = configureByFile(fileName);
     PsiElement resolved = ref.resolve();
     assertTrue(resolved instanceof PsiClass);
diff --git a/plugins/groovy/testdata/resolve/class/classVsPropertyGetter/ClassVsPropertyGetter.groovy b/plugins/groovy/testdata/resolve/class/classVsPropertyGetter/ClassVsPropertyGetter.groovy
new file mode 100644 (file)
index 0000000..2c97db6
--- /dev/null
@@ -0,0 +1,9 @@
+class Currency {
+  static Currency newInstance() {}
+}
+
+class X {
+  def getCurrency() {
+    return Curre<ref>ncy.newInstance();
+  }
+}
\ No newline at end of file