[groovy] tweak isEquivalentTo() in accessors and light variables
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 31 Oct 2016 14:58:59 +0000 (17:58 +0300)
committerDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 31 Oct 2016 15:31:30 +0000 (18:31 +0300)
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrAccessorMethodImpl.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightVariable.java

index 8f479706c7a89deaaa6b4c523fc8a42095eec2c9..f7ca8067b650a5060f1ca62a9d366aa74b6c1393 100644 (file)
@@ -33,6 +33,8 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAc
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
 import org.jetbrains.plugins.groovy.lang.psi.util.GrTraitUtil;
 
+import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils.GET_PREFIX;
+
 /**
  * @author ven
  */
@@ -127,8 +129,14 @@ public class GrAccessorMethodImpl extends LightMethodBuilder implements GrAccess
     if (another == this) return true;
     if (!(another instanceof GrAccessorMethod)) return false;
 
-    if (!((GrAccessorMethod)another).getName().equals(getName())) return false;
-    return getManager().areElementsEquivalent(myProperty, ((GrAccessorMethod)another).getProperty());
+    GrAccessorMethod anotherAccessor = (GrAccessorMethod)another;
+    if (isSetter()) {
+      if (!anotherAccessor.isSetter()) return false;
+    }
+    else {
+      if (!getName().startsWith(GET_PREFIX) == anotherAccessor.getName().startsWith(GET_PREFIX)) return false;
+    }
+    return getManager().areElementsEquivalent(myProperty, anotherAccessor.getProperty());
   }
 
   @NotNull
index cf871ff52e026ebb6a21949a54219362633d454f..e2c86883130fd1439db565cbacf2684084fe1752 100644 (file)
@@ -111,6 +111,9 @@ public class GrLightVariable extends GrImplicitVariableImpl implements Navigatab
 
   @Override
   public boolean isEquivalentTo(PsiElement another) {
+    if (another instanceof GrLightVariable) {
+      return myDeclarations.equals(((GrLightVariable)another).getDeclarations());
+    }
     return myDeclarations.contains(another) || super.isEquivalentTo(another);
   }