mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
method refs: rename methods
This commit is contained in:
+22
@@ -17,6 +17,7 @@ package com.intellij.psi.impl.source.tree.java;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
@@ -42,6 +43,7 @@ import com.intellij.psi.util.MethodSignature;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -97,6 +99,8 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
final IElementType elType = child.getElementType();
|
||||
if (elType == JavaTokenType.DOUBLE_COLON) {
|
||||
return ChildRole.DOUBLE_COLON;
|
||||
} else if (elType == JavaTokenType.IDENTIFIER) {
|
||||
return ChildRole.REFERENCE_NAME;
|
||||
}
|
||||
return ChildRole.EXPRESSION;
|
||||
}
|
||||
@@ -177,6 +181,24 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
|
||||
PsiElement oldIdentifier = findChildByRoleAsPsiElement(ChildRole.REFERENCE_NAME);
|
||||
if (oldIdentifier == null) {
|
||||
throw new IncorrectOperationException();
|
||||
}
|
||||
final String oldRefName = oldIdentifier.getText();
|
||||
if (PsiKeyword.THIS.equals(oldRefName) ||
|
||||
PsiKeyword.SUPER.equals(oldRefName) ||
|
||||
PsiKeyword.NEW.equals(oldRefName) ||
|
||||
Comparing.strEqual(oldRefName, newElementName)) {
|
||||
return this;
|
||||
}
|
||||
PsiIdentifier identifier = JavaPsiFacade.getInstance(getProject()).getElementFactory().createIdentifier(newElementName);
|
||||
oldIdentifier.replace(identifier);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PsiMethodReferenceExpression:" + getText();
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
class MyTest {
|
||||
|
||||
static class Foo {
|
||||
}
|
||||
|
||||
interface I {
|
||||
Foo m();
|
||||
}
|
||||
static Foo f<caret>oo() { return null; }
|
||||
|
||||
public static void main(String[] args) {
|
||||
I i = MyTest::foo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class MyTest {
|
||||
|
||||
static class Foo {
|
||||
}
|
||||
|
||||
interface I {
|
||||
Foo m();
|
||||
}
|
||||
static Foo bar() { return null; }
|
||||
|
||||
public static void main(String[] args) {
|
||||
I i = MyTest::bar;
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,10 @@ public class RenameMembersInplaceTest extends LightCodeInsightTestCase {
|
||||
doTestInplaceRename("Bar");
|
||||
}
|
||||
|
||||
public void testMethodWithMethodRef() throws Exception {
|
||||
doTestInplaceRename("bar");
|
||||
}
|
||||
|
||||
public void testConflictingMethodName() throws Exception {
|
||||
try {
|
||||
doTestInplaceRename("bar");
|
||||
|
||||
Reference in New Issue
Block a user