mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract: don't reject super types based on calling of final methods - they could be called on inheritors without problems (IDEA-149121)
This commit is contained in:
@@ -1230,9 +1230,7 @@ public class ExpectedTypesProvider {
|
||||
final PsiClassType type =
|
||||
substitutor == null ? facade.getElementFactory().createType(aClass) : facade.getElementFactory().createType(aClass, substitutor);
|
||||
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC) ||
|
||||
method.hasModifierProperty(PsiModifier.FINAL) ||
|
||||
method.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC) || method.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
types.add(createInfoImpl(type, ExpectedTypeInfo.TYPE_STRICTLY, type, TailType.DOT));
|
||||
} else if (method.findSuperMethods().length == 0) {
|
||||
types.add(createInfoImpl(type, ExpectedTypeInfo.TYPE_OR_SUBTYPE, type, TailType.DOT));
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class A {
|
||||
public final void foo() {}
|
||||
}
|
||||
class B extends A {}
|
||||
class C {
|
||||
void f(B b) {
|
||||
B v = b;
|
||||
v.foo();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
public final void foo() {}
|
||||
}
|
||||
class B extends A {}
|
||||
class C {
|
||||
void f(B b) {
|
||||
<selection>b</selection>.foo();
|
||||
}
|
||||
}
|
||||
@@ -521,6 +521,25 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
public void testTypesHierarchyBasedOnCalledMethod() {
|
||||
doTest(new MockIntroduceVariableHandler("v", true, false, false, "B") {
|
||||
@Override
|
||||
public IntroduceVariableSettings getSettings(Project project, Editor editor,
|
||||
PsiExpression expr, PsiExpression[] occurrences,
|
||||
TypeSelectorManagerImpl typeSelectorManager,
|
||||
boolean declareFinalIfAll,
|
||||
boolean anyAssignmentLHS,
|
||||
InputValidator validator,
|
||||
PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) {
|
||||
final PsiType[] types = typeSelectorManager.getTypesForAll();
|
||||
assertTrue(types[0].getPresentableText(), types[0].getPresentableText().equals("B"));
|
||||
assertTrue(types[1].getPresentableText(), types[1].getPresentableText().equals("A"));
|
||||
return super.getSettings(project, editor, expr, occurrences, typeSelectorManager, declareFinalIfAll, anyAssignmentLHS,
|
||||
validator, anchor, replaceChoice);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void doTest(IntroduceVariableBase testMe) {
|
||||
String baseName = "/refactoring/introduceVariable/" + getTestName(false);
|
||||
configureByFile(baseName + ".java");
|
||||
|
||||
Reference in New Issue
Block a user