mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
check inheritance for classes in local scopes to check that metho overrides another method (IDEA-161863)
This commit is contained in:
+2
-1
@@ -98,7 +98,8 @@ public class JavaOverridingMethodsSearcher implements QueryExecutor<PsiMethod, O
|
||||
public void visitClass(PsiClass candidate) {
|
||||
ProgressManager.checkCanceled();
|
||||
if (!success[0]) return;
|
||||
PsiMethod overridingMethod = candidate == methodContainingClass ? null : findOverridingMethod(project, candidate, method, methodContainingClass);
|
||||
PsiMethod overridingMethod = candidate.isInheritor(methodContainingClass, true)
|
||||
? findOverridingMethod(project, candidate, method, methodContainingClass) : null;
|
||||
if (overridingMethod != null && !consumer.process(overridingMethod)) {
|
||||
success[0] = false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class Foo{
|
||||
Bar bar;
|
||||
|
||||
void doSomething() {
|
||||
bar.doSom<caret>ething();
|
||||
}
|
||||
|
||||
class Bar {
|
||||
public void doSomething() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class Foo{
|
||||
Bar bar;
|
||||
|
||||
void doSomething() {
|
||||
bar.newDoSomething();
|
||||
}
|
||||
|
||||
class Bar {
|
||||
public void newDoSomething() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,15 @@ package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.TargetElementUtil;
|
||||
import com.intellij.codeInsight.template.TemplateManager;
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateState;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.rename.JavaNameSuggestionProvider;
|
||||
import com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler;
|
||||
@@ -88,6 +97,36 @@ public class RenameMembersInplaceTest extends LightCodeInsightTestCase {
|
||||
doTestInplaceRename("bar");
|
||||
}
|
||||
|
||||
public void testSameNamedMethodsInOneFile() throws Exception {
|
||||
configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
|
||||
final PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.getInstance().getAllAccepted());
|
||||
assertNotNull(element);
|
||||
|
||||
Editor editor = getEditor();
|
||||
Project project = editor.getProject();
|
||||
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
|
||||
new MemberInplaceRenameHandler().doRename(element, editor, DataManager.getInstance().getDataContext(editor.getComponent()));
|
||||
TemplateState state = TemplateManagerImpl.getTemplateState(editor);
|
||||
assert state != null;
|
||||
assertEquals(2, state.getSegmentsCount());
|
||||
final TextRange range = state.getCurrentVariableRange();
|
||||
assert range != null;
|
||||
final Editor finalEditor = editor;
|
||||
new WriteCommandAction.Simple(project) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
finalEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), "newDoSomething");
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
state = TemplateManagerImpl.getTemplateState(editor);
|
||||
assert state != null;
|
||||
state.gotoEnd(false);
|
||||
|
||||
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
public void testNameSuggestion() throws Exception {
|
||||
configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user