mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 19:02:13 +07:00
check every usage for correct identifier in rename
This commit is contained in:
@@ -54,7 +54,7 @@ public class RenameUtil {
|
||||
|
||||
@NotNull
|
||||
public static UsageInfo[] findUsages(final PsiElement element,
|
||||
String newName,
|
||||
final String newName,
|
||||
boolean searchInStringsAndComments,
|
||||
boolean searchForTextOccurrences,
|
||||
Map<? extends PsiElement, String> allRenames) {
|
||||
@@ -65,7 +65,7 @@ public class RenameUtil {
|
||||
RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(element);
|
||||
|
||||
Collection<PsiReference> refs = processor.findReferences(element);
|
||||
for (PsiReference ref : refs) {
|
||||
for (final PsiReference ref : refs) {
|
||||
if (ref == null) {
|
||||
LOG.error("null reference from processor " + processor);
|
||||
continue;
|
||||
@@ -74,6 +74,14 @@ public class RenameUtil {
|
||||
result.add(new MoveRenameUsageInfo(referenceElement, ref, ref.getRangeInElement().getStartOffset(),
|
||||
ref.getRangeInElement().getEndOffset(), element,
|
||||
ref.resolve() == null));
|
||||
if (!isValidName(element.getProject(), ref.getElement(), newName)) {
|
||||
result.add(new UnresolvableCollisionUsageInfo(ref.getElement(), element) {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return RefactoringBundle.message("0.is.not.an.identifier", newName, ref.getElement().getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
processor.findCollisions(element, newName, allRenames, result);
|
||||
|
||||
@@ -743,4 +743,5 @@ change.signature.leave.blank.default.value=Leave &blank
|
||||
change.signature.feel.lucky=Feel &lucky
|
||||
change.signature.use.selected.value=Use selected &value
|
||||
|
||||
search.for.references=Search for re&ferences
|
||||
search.for.references=Search for re&ferences
|
||||
0.is.not.an.identifier=<b><code>{0}</code></b> is not a correct identifier to use in <b><code>{1}</code></b>
|
||||
+22
-1
@@ -7,6 +7,7 @@ import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiReference
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor.ConflictsInTestsException
|
||||
import com.intellij.refactoring.rename.RenameProcessor
|
||||
import com.intellij.refactoring.rename.RenameUtil
|
||||
import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler
|
||||
@@ -212,7 +213,7 @@ class SomeBean {
|
||||
""", file.text
|
||||
}
|
||||
|
||||
public void doTest() throws Throwable {
|
||||
public void doTest() {
|
||||
final String testFile = getTestName(true).replace('$', '/') + ".test";
|
||||
final List<String> list = TestUtils.readInput(TestUtils.getAbsoluteTestDataPath() + "groovy/refactoring/rename/" + testFile);
|
||||
|
||||
@@ -402,6 +403,26 @@ foo = 4"""
|
||||
assert "gpp", myFixture.file.virtualFile.extension
|
||||
}
|
||||
|
||||
public void testRenameJavaUsageFail() {
|
||||
myFixture.addFileToProject "Bar.java", """
|
||||
class Bar {
|
||||
void bar() {
|
||||
new Foo().foo();
|
||||
}
|
||||
}"""
|
||||
myFixture.configureByText "Foo.groovy", """
|
||||
class Foo {
|
||||
def foo() {}
|
||||
}"""
|
||||
try {
|
||||
myFixture.renameElement myFixture.findClass("Foo").getMethods()[0], "'newName'"
|
||||
} catch (ConflictsInTestsException e) {
|
||||
assertEquals "<b><code>'newName'</code></b> is not a correct identifier to use in <b><code>new Foo().foo</code></b>", e.getMessage()
|
||||
return;
|
||||
}
|
||||
assertTrue false
|
||||
}
|
||||
|
||||
private def doInplaceRenameTest() {
|
||||
String prefix = TestUtils.getTestDataPath() + "groovy/refactoring/rename/" + getTestName(false)
|
||||
myFixture.configureByFile prefix + ".groovy";
|
||||
|
||||
Reference in New Issue
Block a user