don't suggest to rename all the 'Parameter' words in the projects when renaming groov...
authorpeter <peter.gromov@jetbrains.com>
Fri, 5 Mar 2010 22:42:33 +0000 (22:42 +0000)
committerpeter <peter.gromov@jetbrains.com>
Fri, 5 Mar 2010 22:43:04 +0000 (22:43 +0000)
platform/lang-impl/src/com/intellij/refactoring/util/DefaultNonCodeSearchElementDescriptionProvider.java
platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java
platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java
plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/rename/RenameTest.groovy [moved from plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/rename/RenameTest.java with 70% similarity]

index 530b5ebcc722eb21038d46a06753e61a29295d6f..030ac3bf45cbb4016e3dd0222e867a164f856297 100644 (file)
 
 package com.intellij.refactoring.util;
 
+import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.psi.*;
 import com.intellij.psi.impl.file.PsiDirectoryFactory;
-import com.intellij.psi.meta.PsiMetaOwner;
 import com.intellij.psi.meta.PsiMetaData;
-import com.intellij.openapi.diagnostic.Logger;
-import org.jetbrains.annotations.Nullable;
+import com.intellij.psi.meta.PsiMetaOwner;
 import org.jetbrains.annotations.NotNull;
 
 /**
@@ -45,7 +44,6 @@ public class DefaultNonCodeSearchElementDescriptionProvider implements ElementDe
       return ((PsiDirectory) element).getName();
     }
 
-    if (ncdLocation.isNonJava()) return null;
     if (element instanceof PsiMetaOwner) {
       final PsiMetaOwner psiMetaOwner = (PsiMetaOwner)element;
       final PsiMetaData metaData = psiMetaOwner.getMetaData();
index a7a603c8a6ea83da74790452929ed01eaabb91c0..d606027917ed242f630827eaa78c264c760e3e13 100644 (file)
@@ -333,4 +333,9 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture {
   void allowTreeAccessForFile(VirtualFile file);
 
   void allowTreeAccessForAllFiles();
+
+  void renameElement(PsiElement element,
+                             String newName,
+                             boolean searchInComments,
+                             boolean searchTextOccurrences) throws Exception;
 }
index d0f5efb3aba4c0fd912f0fe39efc0982e3ff7bff..12a52ff7399c9fd98bebe1705c6ee05bb0e67262 100644 (file)
@@ -525,10 +525,19 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
   }
 
   public void renameElement(final PsiElement element, final String newName) throws Exception {
+    final boolean searchInComments = false;
+    final boolean searchTextOccurrences = false;
+    renameElement(element, newName, searchInComments, searchTextOccurrences);
+  }
+
+  public void renameElement(final PsiElement element,
+                             final String newName,
+                             final boolean searchInComments,
+                             final boolean searchTextOccurrences) throws Exception {
     new WriteCommandAction.Simple(myProjectFixture.getProject()) {
       protected void run() throws Exception {
         final PsiElement substitution = RenamePsiElementProcessor.forElement(element).substituteElementToRename(element, myEditor);
-        new RenameProcessor(myProjectFixture.getProject(), substitution, newName, false, false).run();
+        new RenameProcessor(myProjectFixture.getProject(), substitution, newName, searchInComments, searchTextOccurrences).run();
      }
     }.execute().throwException();
   }
similarity index 70%
rename from plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/rename/RenameTest.java
rename to plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/rename/RenameTest.groovy
index a96288f454f74254b3120f04c4c48a4f3bbe4085..d6a343d82a241da0f1f2c85be135e2f711edeb4f 100644 (file)
@@ -1,18 +1,16 @@
 package org.jetbrains.plugins.groovy.refactoring.rename;
 
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiMethod;
-import com.intellij.psi.PsiReference;
-import com.intellij.psi.impl.source.PostprocessReformattingAspect;
-import com.intellij.refactoring.rename.RenameProcessor;
-import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
-import org.jetbrains.plugins.groovy.GroovyFileType;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod;
-import org.jetbrains.plugins.groovy.util.TestUtils;
-
-import java.util.List;
+import com.intellij.openapi.util.text.StringUtil
+import com.intellij.psi.PsiElement
+import com.intellij.psi.PsiMethod
+import com.intellij.psi.PsiReference
+import com.intellij.psi.impl.source.PostprocessReformattingAspect
+import com.intellij.refactoring.rename.RenameProcessor
+import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
+import org.jetbrains.plugins.groovy.GroovyFileType
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod
+import org.jetbrains.plugins.groovy.util.TestUtils
 
 /**
  * @author ven
@@ -25,6 +23,29 @@ public class RenameTest extends LightCodeInsightFixtureTestCase {
   public void testTo_setter() throws Throwable { doTest(); }
   public void testScriptMethod() throws Throwable { doTest(); }
 
+  public void testParameterIsNotAUsageOfGroovyParameter() throws Exception {
+    myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """
+def foo(f) {
+  // Parameter
+  println 'Parameter' // also
+  return <caret>f
+}
+""")
+    def txt = "Just the Parameter word, which shouldn't be renamed"
+    def txtFile = myFixture.addFileToProject("a.txt", txt)
+
+    def parameter = myFixture.file.findReferenceAt(myFixture.editor.caretModel.offset).resolve()
+    myFixture.renameElement(parameter, "newName", true, true)
+    myFixture.checkResult """
+def foo(newName) {
+  // Parameter
+  println 'Parameter' // also
+  return <caret>newName
+}
+"""
+    assertEquals txt, txtFile.text
+  }
+
   public void doTest() throws Throwable {
     final String testFile = getTestName(true).replace('$', '/') + ".test";
     final List<String> list = TestUtils.readInput(TestUtils.getAbsoluteTestDataPath() + "groovy/refactoring/rename/" + testFile);