Support for generic classes in quickfix for NOTHING_TO_OVERRIDE

This commit is contained in:
Michał Sapalski
2013-03-02 15:08:00 +01:00
committed by Natalia.Ukhorskaya
parent 642d073bc9
commit d849258757
8 changed files with 56 additions and 7 deletions
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.JetType;
import java.util.Set;
@@ -57,7 +58,7 @@ public interface ValueParameterDescriptor extends VariableDescriptor, Annotated
ValueParameterDescriptor getOriginal();
@NotNull
ValueParameterDescriptor copy(DeclarationDescriptor newOwner);
ValueParameterDescriptor copy(DeclarationDescriptor newOwner, Name newName);
/**
* Parameter p1 overrides p2 iff
@@ -111,6 +111,7 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
}
@Nullable
@Override
public JetType getVarargElementType() {
return varargElementType;
}
@@ -139,8 +140,8 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
@NotNull
@Override
public ValueParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) {
return new ValueParameterDescriptorImpl(newOwner, index, Lists.newArrayList(getAnnotations()), getName(), getType(), hasDefaultValue, varargElementType);
public ValueParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner, @NotNull Name newName) {
return new ValueParameterDescriptorImpl(newOwner, index, Lists.newArrayList(getAnnotations()), newName, getType(), declaresDefaultValue(), varargElementType);
}
@NotNull
@@ -34,11 +34,11 @@ 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;
import org.jetbrains.jet.lang.resolve.VisibilityUtil;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.actions.JetChangeFunctionSignatureAction;
@@ -187,7 +187,13 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
@NotNull ValueParameterDescriptor parameter,
@NotNull ValueParameterDescriptor superParameter
) {
return JetTypeChecker.INSTANCE.equalTypes(parameter.getType(), superParameter.getType()) ? parameter : null;
// TODO: support for generic functions
if (JetTypeChecker.INSTANCE.equalTypes(parameter.getType(), superParameter.getType())) {
return superParameter.copy(parameter.getContainingDeclaration(), parameter.getName());
}
else {
return null;
}
}
};
@@ -235,8 +241,7 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
Name name = functionDescriptor.getName();
for (ClassDescriptor superclass : DescriptorUtils.getAllSuperClasses(classDescriptor)) {
JetType type = superclass.getDefaultType();
for (JetType type : TypeUtils.getAllSupertypes(classDescriptor.getDefaultType())) {
JetScope scope = type.getMemberScope();
for (FunctionDescriptor function : scope.getFunctions(name)) {
if (!function.getKind().isReal()) continue;
@@ -0,0 +1,8 @@
// "Change function signature to 'override fun f(a: Int, x: T)'" "true"
trait A<R> {
fun f(a: Int, b: R)
}
class B<T> : A<T> {
<caret>override fun f(a: Int, x: T) {}
}
@@ -0,0 +1,8 @@
// "Change function signature to 'override fun f(y: S, x: List<Set<R>>)'" "true"
trait A<P,Q> {
fun f(a: Q, b: List<Set<P>>)
}
class B<R,S> : A<R,S> {
<caret>override fun f(y: S, x: List<Set<R>>) {}
}
@@ -0,0 +1,8 @@
// "Change function signature to 'override fun f(a: Int, x: T)'" "true"
trait A<R> {
fun f(a: Int, b: R)
}
class B<T> : A<T> {
<caret>override fun f(x: T) {}
}
@@ -0,0 +1,8 @@
// "Change function signature to 'override fun f(y: S, x: List<Set<R>>)'" "true"
trait A<P,Q> {
fun f(a: Q, b: List<Set<P>>)
}
class B<R,S> : A<R,S> {
<caret>override fun f(x: List<Set<R>>, y: S) {}
}
@@ -906,6 +906,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest("idea/testData/quickfix/override/nothingToOverride/beforeAddParameter.kt");
}
@TestMetadata("beforeAddParameterGenericClass.kt")
public void testAddParameterGenericClass() throws Exception {
doTest("idea/testData/quickfix/override/nothingToOverride/beforeAddParameterGenericClass.kt");
}
@TestMetadata("beforeAddParameterMultiple.kt")
public void testAddParameterMultiple() throws Exception {
doTest("idea/testData/quickfix/override/nothingToOverride/beforeAddParameterMultiple.kt");
@@ -1000,6 +1005,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest("idea/testData/quickfix/override/nothingToOverride/beforeRemoveParameterTwoTraits.kt");
}
@TestMetadata("beforeSwapParametersGenericClass.kt")
public void testSwapParametersGenericClass() throws Exception {
doTest("idea/testData/quickfix/override/nothingToOverride/beforeSwapParametersGenericClass.kt");
}
}
@TestMetadata("idea/testData/quickfix/override/typeMismatchOnOverride")