Search in all superclasses in quickfix for NOTHING_TO_OVERRIDE.
This commit is contained in:
committed by
Andrey Breslav
parent
0e96e83154
commit
68cd832831
@@ -31,6 +31,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorUtil;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
@@ -75,7 +76,7 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getFunctionSignatureString(@NotNull FunctionDescriptor functionSignature, boolean shortTypeNames) {
|
||||
private static String getFunctionSignatureString(@NotNull FunctionDescriptor functionSignature, boolean shortTypeNames) {
|
||||
return CodeInsightUtils.createFunctionSignatureStringFromDescriptor(
|
||||
functionSignature, shortTypeNames);
|
||||
}
|
||||
@@ -87,7 +88,7 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull final Project project, @NotNull final Editor editor, PsiFile file)
|
||||
protected void invoke(@NotNull final Project project, @NotNull final Editor editor, JetFile file)
|
||||
throws IncorrectOperationException {
|
||||
CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {
|
||||
@Override
|
||||
@@ -106,7 +107,7 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
|
||||
* Computes all the signatures a 'functionElement' could be changed to in order to remove NOTHING_TO_OVERRIDE error.
|
||||
*/
|
||||
@NotNull
|
||||
private List<FunctionDescriptor> computePossibleSignatures(JetNamedFunction functionElement) {
|
||||
private static List<FunctionDescriptor> computePossibleSignatures(JetNamedFunction functionElement) {
|
||||
BindingContext context = KotlinCacheManagerUtil.getDeclarationsFromProject(functionElement).getBindingContext();
|
||||
FunctionDescriptor functionDescriptor = context.get(BindingContext.FUNCTION, functionElement);
|
||||
if (functionDescriptor == null) return Lists.newArrayList();
|
||||
@@ -234,7 +235,7 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||
|
||||
Name name = functionDescriptor.getName();
|
||||
for (ClassDescriptor superclass : DescriptorUtils.getSuperclassDescriptors(classDescriptor)) {
|
||||
for (ClassDescriptor superclass : DescriptorUtils.getAllSuperClasses(classDescriptor)) {
|
||||
JetType type = superclass.getDefaultType();
|
||||
JetScope scope = type.getMemberScope();
|
||||
for (FunctionDescriptor function : scope.getFunctions(name)) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
trait A {
|
||||
fun f(a: Int)
|
||||
}
|
||||
|
||||
trait B : A {
|
||||
}
|
||||
|
||||
class C : B {
|
||||
override fun f(a: Int) {}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
open class A {
|
||||
open fun f(a: Int) {}
|
||||
}
|
||||
|
||||
open class B : A() {
|
||||
}
|
||||
|
||||
class C : B() {
|
||||
<caret>override fun f(a: Int) {}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
trait A {
|
||||
fun f(a: Int)
|
||||
}
|
||||
|
||||
trait B : A {
|
||||
}
|
||||
|
||||
class C : B {
|
||||
<caret>override fun f() {}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
open class A {
|
||||
open fun f(a: Int) {}
|
||||
}
|
||||
|
||||
open class B : A() {
|
||||
}
|
||||
|
||||
class C : B() {
|
||||
<caret>override fun f() {}
|
||||
}
|
||||
@@ -16,14 +16,17 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.jet.plugin.quickfix.AbstractQuickFixTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@@ -848,6 +851,16 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeAddParameterPreserveVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeAddParameterTwoSupertraits.kt")
|
||||
public void testAddParameterTwoSupertraits() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeAddParameterTwoSupertraits.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeAddParameterTwoSupertypes.kt")
|
||||
public void testAddParameterTwoSupertypes() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeAddParameterTwoSupertypes.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInNothingToOverride() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/override/nothingToOverride"), Pattern.compile("^before(\\w+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user