Quickfix to correct signature of method with 'override' to not include 'override' in signature text

This commit is contained in:
Valentin Kipyatkov
2014-10-04 01:41:10 +04:00
parent 317607db70
commit 5ae756addb
44 changed files with 54 additions and 46 deletions
@@ -50,9 +50,8 @@ import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
public class JetChangeFunctionSignatureAction implements QuestionAction {
public static final DescriptorRenderer SIGNATURE_RENDERER = new DescriptorRendererBuilder()
.setWithDefinedIn(false)
.setModifiers(DescriptorRenderer.Modifier.OVERRIDE)
.setModifiers()
.setShortNames(true)
.setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OVERRIDE)
.setUnitReturnType(false).build();
private final Project project;
@@ -16,6 +16,8 @@
package org.jetbrains.jet.plugin.quickfix;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Queues;
@@ -112,13 +114,20 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
FunctionDescriptor functionDescriptor = context.get(BindingContext.FUNCTION, functionElement);
if (functionDescriptor == null) return Lists.newArrayList();
List<FunctionDescriptor> superFunctions = getPossibleSuperFunctionsDescriptors(functionDescriptor);
Map<String, FunctionDescriptor> possibleSignatures = Maps.newHashMap();
final Map<String, FunctionDescriptor> possibleSignatures = Maps.newHashMap();
for (FunctionDescriptor superFunction : superFunctions) {
if (!superFunction.getKind().isReal()) continue;
FunctionDescriptor signature = changeSignatureToMatch(functionDescriptor, superFunction);
possibleSignatures.put(getFunctionSignatureString(signature), signature);
}
return Lists.newArrayList(possibleSignatures.values());
List<String> keys = new ArrayList<String>(possibleSignatures.keySet());
Collections.sort(keys);
return new ArrayList<FunctionDescriptor>(Collections2.transform(keys, new Function<String, FunctionDescriptor>() {
@Override
public FunctionDescriptor apply(String key) {
return possibleSignatures.get(key);
}
}));
}
/**
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
trait A {
fun f(a: Int)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int, x: T)'" "true"
// "Change function signature to 'fun f(a: Int, x: T)'" "true"
trait A<R> {
fun f(a: Int, b: R)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
trait A {
fun f(a: Int)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
trait A {
fun f(a: Int)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
open class A {
open fun f(a: Int) {}
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
open class A {
open fun f(a: Int) {}
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
abstract class A {
abstract fun f(a: Int)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
trait A {
fun f(a: Int)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(x: Int, t: String, z: Double)'" "true"
// "Change function signature to 'fun f(x: Int, t: String, z: Double)'" "true"
open class A {
open fun f(x: Int, y: String, z: Double) {}
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(y: Int, x: String)'" "true"
// "Change function signature to 'fun f(y: Int, x: String)'" "true"
open class A {
open fun f(a: Int, b: String) {}
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f()'" "true"
// "Change function signature to 'fun f()'" "true"
open class A {
open fun f() {}
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int): Int'" "true"
// "Change function signature to 'fun f(a: Int): Int'" "true"
open class A {
open fun f(a: Int): Int {
return 0
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
trait A {
fun f(a: Int)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int): Int'" "true"
// "Change function signature to 'fun f(a: Int): Int'" "true"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>kotlin.Int</td></tr><tr><td>Found:</td><td>kotlin.String</td></tr></table></html>
open class A {
open fun f(a: Int): Int = 0
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
annotation class annon
open class A {
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun next(p0: Int): Int'" "true"
// "Change function signature to 'fun next(p0: Int): Int'" "true"
import java.util.Random
class MyRandom : Random() {
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f()'" "true"
// "Change function signature to 'fun f()'" "true"
trait A {
fun f()
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f()'" "true"
// "Change function signature to 'fun f()'" "true"
trait A {
fun f()
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(y: S, x: List<Set<R>>)'" "true"
// "Change function signature to 'fun f(y: S, x: List<Set<R>>)'" "true"
trait A<P,Q> {
fun f(a: Q, b: List<Set<P>>)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
trait A {
fun f(a: Int)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int, x: T)'" "true"
// "Change function signature to 'fun f(a: Int, x: T)'" "true"
trait A<R> {
fun f(a: Int, b: R)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
trait A {
fun f(a: Int)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
trait A {
fun f(a: Int)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
open class A {
open fun f(a: Int) {}
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
open class A {
open fun f(a: Int) {}
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
abstract class A {
abstract fun f(a: Int)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
trait A {
fun f(a: Int)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(x: Int, t: String, z: Double)'" "true"
// "Change function signature to 'fun f(x: Int, t: String, z: Double)'" "true"
open class A {
open fun f(x: Int, y: String, z: Double) {}
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(y: Int, x: String)'" "true"
// "Change function signature to 'fun f(y: Int, x: String)'" "true"
open class A {
open fun f(a: Int, b: String) {}
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f()'" "true"
// "Change function signature to 'fun f()'" "true"
open class A {
open fun f() {}
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int): Int'" "true"
// "Change function signature to 'fun f(a: Int): Int'" "true"
open class A {
open fun f(a: Int): Int {
return 0
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
trait A {
fun f(a: Int)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int): Int'" "true"
// "Change function signature to 'fun f(a: Int): Int'" "true"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>kotlin.Int</td></tr><tr><td>Found:</td><td>kotlin.String</td></tr></table></html>
open class A {
open fun f(a: Int): Int = 0
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: Int)'" "true"
// "Change function signature to 'fun f(a: Int)'" "true"
annotation class annon
open class A {
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun next(p0: Int): Int'" "true"
// "Change function signature to 'fun next(p0: Int): Int'" "true"
import java.util.Random
class MyRandom : Random() {
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f()'" "true"
// "Change function signature to 'fun f()'" "true"
trait A {
fun f()
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f()'" "true"
// "Change function signature to 'fun f()'" "true"
trait A {
fun f()
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(y: S, x: List<Set<R>>)'" "true"
// "Change function signature to 'fun f(y: S, x: List<Set<R>>)'" "true"
trait A<P,Q> {
fun f(a: Q, b: List<Set<P>>)
}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: A)'" "true"
// "Change function signature to 'fun f(a: A)'" "true"
// ERROR: 'f' overrides nothing
import a.B
import a.A
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: A)'" "true"
// "Change function signature to 'fun f(a: A)'" "true"
// ERROR: 'f' overrides nothing
import a.B
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: A)'" "true"
// "Change function signature to 'fun f(a: A)'" "true"
// ERROR: 'f' overrides nothing
import a.B
class A {}
@@ -1,4 +1,4 @@
// "Change function signature to 'override fun f(a: A)'" "true"
// "Change function signature to 'fun f(a: A)'" "true"
// ERROR: 'f' overrides nothing
import a.B
class A {}