don't show 3 identical groovy property usages (IDEA-50789), and don't ask to search...
authorpeter <peter.gromov@jetbrains.com>
Sun, 14 Feb 2010 21:26:46 +0000 (14 21:26 +0000)
committerpeter <peter.gromov@jetbrains.com>
Sun, 14 Feb 2010 21:26:46 +0000 (14 21:26 +0000)
java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java
plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolvePropertyTest.groovy

index 970a339..752d467 100644 (file)
@@ -172,7 +172,7 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{
         PsiMethod setter = PropertyUtil.
           findPropertySetterWithType(propertyName, field.hasModifierProperty(PsiModifier.STATIC), field.getType(),
                                      ContainerUtil.iterate(containingClass.getMethods()));
-        if (getter != null || setter != null) {
+        if (getter != null && getter.isPhysical() || setter != null && setter.isPhysical()) {
           if (Messages.showDialog(FindBundle.message("find.field.accessors.prompt", field.getName()),
                                   FindBundle.message("find.field.accessors.title"),
                                   new String[]{CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText()}, 0,
index 20f4c69..945e4e7 100644 (file)
@@ -571,7 +571,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl implements
     if (element instanceof PsiMethod && GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod) element)) {
       final PsiElement target = resolve();
       if (element instanceof GrAccessorMethod && getManager().areElementsEquivalent(((GrAccessorMethod)element).getProperty(), target)) {
-        return true;
+        return false;
       }
 
       return getManager().areElementsEquivalent(element, target);
index 2eee432..1c09dda 100644 (file)
@@ -212,7 +212,7 @@ public class ResolvePropertyTest extends GroovyResolveTestCase {
   public void testUnderscoredField() throws Exception {
     PsiReference ref = configureByFile("underscoredField/UnderscoredField.groovy");
     final GrField field = assertInstanceOf(ref.resolve(), GrField.class);
-    assertTrue(ref.isReferenceTo(field.getGetters()[0]));
+    assertFalse(ref.isReferenceTo(field.getGetters()[0]));
     assertTrue(ref.isReferenceTo(field));
   }
 
@@ -260,7 +260,7 @@ public class ResolvePropertyTest extends GroovyResolveTestCase {
 
   public void testIDEADEV40403() {
     myFixture.configureByFile("IDEADEV40403/A.groovy");
-    def reference = myFixture.file.findReferenceAt(myFixture.editor.caretModel.offset);
+    def reference = findReference()
     def resolved = reference.resolve()
     assertInstanceOf(resolved, PsiMethod.class);
     def clazz = resolved.containingClass
@@ -269,11 +269,27 @@ public class ResolvePropertyTest extends GroovyResolveTestCase {
 
   public void testBooleanGetterPropertyAccess() {
     myFixture.configureByText("a.groovy", "print([].em<caret>pty)");
-    def ref = myFixture.file.findReferenceAt(myFixture.editor.caretModel.offset)
+    def ref = findReference()
     def resolved = ref.resolve()
     assertInstanceOf resolved, PsiMethod
   }
 
+  def findReference() { myFixture.file.findReferenceAt(myFixture.editor.caretModel.offset) }
+
+  public void testTriplePropertyUsages() throws Exception {
+    myFixture.configureByText "a.groovy", """
+class Foo {
+  def bar
+  def zoo = <caret>bar
+}
+"""
+    def ref = findReference()
+    GrField target = assertInstanceOf(ref.resolve(), GrField)
+    assertTrue ref.isReferenceTo(target)
+    assertFalse ref.isReferenceTo(target.getters[0])
+    assertFalse ref.isReferenceTo(target.setter)
+  }
+
   private void doTest(String fileName) throws Exception {
     PsiReference ref = configureByFile(fileName);
     PsiElement resolved = ref.resolve();