[groovy] get rid of `GrReferenceElement.handleElementRenameSimple(String newElementName)`
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 31 Oct 2016 14:24:33 +0000 (17:24 +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/codeInspection/utils/JavaStylePropertiesUtil.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/GrReferenceElement.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrReferenceElementImpl.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightClassReferenceElement.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightVariable.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrCodeReferenceElementImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/other/GrAliasImportIntention.java
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedMethodProcessor.java
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGrFieldProcessor.java

index 2d6d58a64c42717c20e4eea555bfa3285cb0d963..69c33817023e8c31aebb0e04743f399e923dd984 100644 (file)
@@ -70,7 +70,7 @@ public class JavaStylePropertiesUtil {
 
     GrReferenceExpression lvalueRef = (GrReferenceExpression)assignment.getLValue();
     lvalueRef.setQualifier(refExpr.getQualifier());
-    lvalueRef.handleElementRenameSimple(name);
+    lvalueRef.handleElementRename(name);
     assignment.getRValue().replaceWithExpression(value, true);
 
     return assignment;
index 9f4fd20116e3c877efb268a43a5ed0b820a2ac4b..d2e19cc8d50e302252760d54549318ac44acc74b 100644 (file)
@@ -18,7 +18,6 @@ package org.jetbrains.plugins.groovy.lang.psi;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiPolyVariantReference;
 import com.intellij.psi.PsiType;
-import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
@@ -56,6 +55,4 @@ public interface GrReferenceElement<Q extends PsiElement> extends GroovyPsiEleme
 
   @NotNull
   String getClassNameText();
-
-  PsiElement handleElementRenameSimple(String newElementName) throws IncorrectOperationException;
 }
index f89bb9586fadffa05d8ee34d721f37f5c8f994ab..d2e334de6575f25b85628b36d72c906fd61d6399 100644 (file)
@@ -76,7 +76,7 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
   }
 
   @Override
-  public PsiElement handleElementRenameSimple(String newElementName) throws IncorrectOperationException {
+  public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
     PsiElement nameElement = getReferenceNameElement();
     if (nameElement != null) {
       ASTNode node = nameElement.getNode();
@@ -95,11 +95,6 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
     return this;
   }
 
-  @Override
-  public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
-    return handleElementRenameSimple(newElementName);
-  }
-
   @Override
   public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
     if (isReferenceTo(element)) return this;
@@ -111,7 +106,7 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
       if (!preserveQualification || qualifiedName == null) {
         final String newName = ((PsiClass)element).getName();
         setQualifier(null);
-        final GrReferenceElementImpl newElement = ((GrReferenceElementImpl)handleElementRenameSimple(newName));
+        final GrReferenceElementImpl newElement = ((GrReferenceElementImpl)handleElementRename(newName));
 
         if (newElement.isReferenceTo(element) || qualifiedName == null || JavaPsiFacade.getInstance(getProject()).findClass(qualifiedName, getResolveScope()) == null) {
           return newElement;
index 947da2bbeba6f586d87a461e56f9c7f3adac94c2..a954d027048ada868823ec56250a58c6f00761c3 100644 (file)
@@ -149,6 +149,17 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
 
   @Override
   public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
+    if (!PsiUtil.isValidReferenceName(newElementName)) {
+      final PsiElement old = getReferenceNameElement();
+      if (old == null) throw new IncorrectOperationException("ref has no name element");
+
+      PsiElement element = GroovyPsiElementFactory.getInstance(getProject()).createStringLiteralForReference(newElementName);
+      old.replace(element);
+      return this;
+    }
+
+    if (PsiUtil.isThisOrSuperRef(this)) return this;
+
     final GroovyResolveResult result = advancedResolve();
     if (result.isInvokedOnProperty()) {
       final String name = GroovyPropertyUtils.getPropertyNameByAccessorName(newElementName);
@@ -156,9 +167,8 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
         newElementName = name;
       }
     }
-    if (PsiUtil.isThisOrSuperRef(this)) return this;
 
-    return handleElementRenameSimple(newElementName);
+    return super.handleElementRename(newElementName);
   }
 
   @Override
@@ -181,20 +191,6 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
     return ((GrReferenceExpressionImpl)qualifier).isFullyQualified();
   }
 
-  @Override
-  public PsiElement handleElementRenameSimple(String newElementName) throws IncorrectOperationException {
-    if (!PsiUtil.isValidReferenceName(newElementName)) {
-      final PsiElement old = getReferenceNameElement();
-      if (old == null) throw new IncorrectOperationException("ref has no name element");
-
-      PsiElement element = GroovyPsiElementFactory.getInstance(getProject()).createStringLiteralForReference(newElementName);
-      old.replace(element);
-      return this;
-    }
-
-    return super.handleElementRenameSimple(newElementName);
-  }
-
   public String toString() {
     return "Reference expression";
   }
index bed38c1b570dfa5cb50897b6085b999bfdd92fa2..9973b27e7cc94d212b2c8935f008ba2f6f3f08fe 100644 (file)
@@ -81,11 +81,6 @@ public class GrLightClassReferenceElement extends LightElement implements GrCode
     return myClassName;
   }
 
-  @Override
-  public PsiElement handleElementRenameSimple(String newElementName) throws IncorrectOperationException {
-    throw new UnsupportedOperationException();
-  }
-
   @Override
   public GrCodeReferenceElement getQualifier() {
     return null;
index 14a951eff6b26d7cfbb8d508452e2d980b03f491..cf871ff52e026ebb6a21949a54219362633d454f 100644 (file)
@@ -142,7 +142,7 @@ public class GrLightVariable extends GrImplicitVariableImpl implements Navigatab
         ((LeafElement)textToken).replaceWithText(name);
       }
       else if (declaration instanceof GrReferenceExpression) {
-        ((GrReferenceExpression)declaration).handleElementRenameSimple(name);
+        ((GrReferenceExpression)declaration).handleElementRename(name);
       }
     }
 
index 2b59b5536f5f810ac0783a4b1730680e3ca517b0..d7de4533db786d08932f19077a2de90fda4de6eb 100644 (file)
@@ -67,9 +67,9 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
   }
 
   @Override
-  public PsiElement handleElementRenameSimple(String newElementName) throws IncorrectOperationException {
+  public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
     if (StringUtil.isJavaIdentifier(newElementName)) {
-      return super.handleElementRenameSimple(newElementName);
+      return super.handleElementRename(newElementName);
     }
     else {
       throw new IncorrectOperationException("Cannot rename reference to '" + newElementName + "'");
index 0b4e3c3a335906f6e2af44439e9eb3d09be56442..c27b3589ea1edbab6709fcf645536463de41bd2f 100644 (file)
@@ -213,28 +213,28 @@ public class GrAliasImportIntention extends Intention {
             if (refName == null) return;
 
             if (memberName.equals(refName)) {
-              ref.handleElementRenameSimple(name);
+              ref.handleElementRename(name);
             }
             else if (refName.equals(GroovyPropertyUtils.getPropertyNameByAccessorName(memberName))) {
               final String newPropName = GroovyPropertyUtils.getPropertyNameByAccessorName(name);
               if (newPropName != null) {
-                ref.handleElementRenameSimple(newPropName);
+                ref.handleElementRename(newPropName);
               }
               else {
-                ref.handleElementRenameSimple(name);
+                ref.handleElementRename(name);
               }
             }
             else if (refName.equals(GroovyPropertyUtils.getGetterNameBoolean(memberName))) {
               final String getterName = GroovyPropertyUtils.getGetterNameBoolean(name);
-              ref.handleElementRenameSimple(getterName);
+              ref.handleElementRename(getterName);
             }
             else if (refName.equals(GroovyPropertyUtils.getGetterNameNonBoolean(memberName))) {
               final String getterName = GroovyPropertyUtils.getGetterNameNonBoolean(name);
-              ref.handleElementRenameSimple(getterName);
+              ref.handleElementRename(getterName);
             }
             else if (refName.equals(GroovyPropertyUtils.getSetterName(memberName))) {
               final String getterName = GroovyPropertyUtils.getSetterName(name);
-              ref.handleElementRenameSimple(getterName);
+              ref.handleElementRename(getterName);
             }
           }
         }
index 38850a43c58788e2bb2eaf2d20ab7e62bc1bc9c6..4013e644f5d43100ee7ecfbf157d1f18fe8f323c 100644 (file)
@@ -29,7 +29,6 @@ import com.intellij.refactoring.rename.RenameUtil;
 import com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo;
 import com.intellij.usageView.UsageInfo;
 import com.intellij.util.IncorrectOperationException;
-import com.intellij.util.Processor;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
@@ -131,7 +130,7 @@ public class RenameAliasImportedMethodProcessor extends RenameJavaMethodProcesso
       for (UsageInfo usage : propertyAccess) {
         final PsiReference ref = usage.getReference();
         if (ref != null) {
-          ((GrReferenceExpression)ref).handleElementRenameSimple(propertyName);
+          ((GrReferenceExpression)ref).handleElementRename(propertyName);
         }
       }
     }
index 7193fd8fb348e02491b1e85585f27fe8f193e52f..dc3b9c42320b5131236aec1b1c9f95a6c14ab444 100644 (file)
@@ -211,7 +211,8 @@ public class RenameGrFieldProcessor extends RenameJavaVariableProcessor {
                              boolean shouldCheckForCorrectResolve,
                              PsiManager manager) {
     final PsiReference ref = info.getReference();
-    final PsiElement renamed = ((GrReferenceExpression)ref).handleElementRenameSimple(nameToUse);
+    assert ref != null;
+    final PsiElement renamed = ref.handleElementRename(nameToUse);
     PsiElement newly_resolved = ref.resolve();
     if (shouldCheckForCorrectResolve) {
       if (element instanceof GrAccessorMethod && newly_resolved instanceof GrAccessorMethod) {