Fixed KT-4892 Override method generates redundant type arguments in call to super
#KT-4892 Fixed
This commit is contained in:
+13
-11
@@ -101,8 +101,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
PsiElement firstGenerated = null;
|
||||
|
||||
List<JetElement> elementsToCompact = new ArrayList<JetElement>();
|
||||
JetFile file = classOrObject.getContainingJetFile();
|
||||
for (JetElement element : generateOverridingMembers(selectedElements, file)) {
|
||||
for (JetElement element : generateOverridingMembers(selectedElements, classOrObject)) {
|
||||
PsiElement added = body.addAfter(element, afterAnchor);
|
||||
|
||||
if (firstGenerated == null) {
|
||||
@@ -179,22 +178,22 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
return whiteSpace;
|
||||
}
|
||||
|
||||
private static List<JetElement> generateOverridingMembers(List<DescriptorClassMember> selectedElements, JetFile file) {
|
||||
private static List<JetElement> generateOverridingMembers(List<DescriptorClassMember> selectedElements, JetClassOrObject classOrObject) {
|
||||
List<JetElement> overridingMembers = new ArrayList<JetElement>();
|
||||
for (DescriptorClassMember selectedElement : selectedElements) {
|
||||
DeclarationDescriptor descriptor = selectedElement.getDescriptor();
|
||||
if (descriptor instanceof SimpleFunctionDescriptor) {
|
||||
overridingMembers.add(overrideFunction(file.getProject(), (SimpleFunctionDescriptor) descriptor));
|
||||
overridingMembers.add(overrideFunction(classOrObject, (SimpleFunctionDescriptor) descriptor));
|
||||
}
|
||||
else if (descriptor instanceof PropertyDescriptor) {
|
||||
overridingMembers.add(overrideProperty(file.getProject(), (PropertyDescriptor) descriptor));
|
||||
overridingMembers.add(overrideProperty(classOrObject, (PropertyDescriptor) descriptor));
|
||||
}
|
||||
}
|
||||
return overridingMembers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JetElement overrideProperty(@NotNull Project project, @NotNull PropertyDescriptor descriptor) {
|
||||
private static JetElement overrideProperty(@NotNull JetClassOrObject classOrObject, @NotNull PropertyDescriptor descriptor) {
|
||||
PropertyDescriptor newDescriptor = (PropertyDescriptor) descriptor.copy(
|
||||
descriptor.getContainingDeclaration(),
|
||||
Modality.OPEN,
|
||||
@@ -211,11 +210,11 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
if (descriptor.isVar()) {
|
||||
body.append("\nset(value) {}");
|
||||
}
|
||||
return JetPsiFactory(project).createProperty(OVERRIDE_RENDERER.render(newDescriptor) + body);
|
||||
return JetPsiFactory(classOrObject.getProject()).createProperty(OVERRIDE_RENDERER.render(newDescriptor) + body);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JetNamedFunction overrideFunction(@NotNull Project project, @NotNull FunctionDescriptor descriptor) {
|
||||
private static JetNamedFunction overrideFunction(@NotNull JetClassOrObject classOrObject, @NotNull FunctionDescriptor descriptor) {
|
||||
FunctionDescriptor newDescriptor = descriptor.copy(
|
||||
descriptor.getContainingDeclaration(),
|
||||
Modality.OPEN,
|
||||
@@ -230,8 +229,11 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
delegationBuilder.append("throw UnsupportedOperationException()");
|
||||
}
|
||||
else {
|
||||
delegationBuilder.append("super<").append(descriptor.getContainingDeclaration().getName());
|
||||
delegationBuilder.append(">.").append(descriptor.getName()).append("(");
|
||||
delegationBuilder.append("super");
|
||||
if (classOrObject.getDelegationSpecifiers().size() > 1) {
|
||||
delegationBuilder.append("<").append(descriptor.getContainingDeclaration().getName()).append(">");
|
||||
}
|
||||
delegationBuilder.append(".").append(descriptor.getName()).append("(");
|
||||
}
|
||||
boolean first = true;
|
||||
if (!isAbstractFun) {
|
||||
@@ -250,7 +252,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
boolean returnsNotUnit = returnType != null && !builtIns.getUnitType().equals(returnType);
|
||||
String body = "{" + (returnsNotUnit && !isAbstractFun ? "return " : "") + delegationBuilder.toString() + "}";
|
||||
|
||||
return JetPsiFactory(project).createFunction(OVERRIDE_RENDERER.render(newDescriptor) + body);
|
||||
return JetPsiFactory(classOrObject.getProject()).createFunction(OVERRIDE_RENDERER.render(newDescriptor) + body);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -6,25 +6,25 @@ open class Base<A, B, C>() {
|
||||
|
||||
class C : Base<String, C, Unit>() {
|
||||
override fun bar(value: () -> Unit): (String) -> Unit {
|
||||
<selection><caret>return super<Base>.bar(value)</selection>
|
||||
<selection><caret>return super.bar(value)</selection>
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return super<Base>.equals(other)
|
||||
return super.equals(other)
|
||||
}
|
||||
|
||||
override fun foo(value: C): C {
|
||||
return super<Base>.foo(value)
|
||||
return super.foo(value)
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return super<Base>.hashCode()
|
||||
return super.hashCode()
|
||||
}
|
||||
|
||||
override val method: (String?) -> String
|
||||
get() = ?
|
||||
|
||||
override fun toString(): String {
|
||||
return super<Base>.toString()
|
||||
return super.toString()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class C(t :T) : T by t {
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return super<T>.equals(other)
|
||||
return super.equals(other)
|
||||
}
|
||||
|
||||
override fun foo() {
|
||||
@@ -17,11 +17,11 @@ class C(t :T) : T by t {
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return super<T>.hashCode()
|
||||
return super.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return super<T>.toString()
|
||||
return super.toString()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -4,6 +4,6 @@ import foo.Intf
|
||||
|
||||
class Impl(): Intf() {
|
||||
override fun getFooBar(): String? {
|
||||
<selection><caret>return super<Intf>.getFooBar()</selection>
|
||||
<selection><caret>return super.getFooBar()</selection>
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,6 +4,6 @@ import foo.Intf
|
||||
|
||||
class Impl(): Intf() {
|
||||
override fun getFooBar(): String? {
|
||||
<selection><caret>return super<Intf>.getFooBar()</selection>
|
||||
<selection><caret>return super.getFooBar()</selection>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,22 +5,22 @@ trait A {
|
||||
|
||||
class C : A {
|
||||
override fun bar(): String {
|
||||
<selection><caret>return super<A>.bar()</selection>
|
||||
<selection><caret>return super.bar()</selection>
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return super<A>.equals(other)
|
||||
return super.equals(other)
|
||||
}
|
||||
|
||||
override fun foo(value: String): Int {
|
||||
return super<A>.foo(value)
|
||||
return super.foo(value)
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return super<A>.hashCode()
|
||||
return super.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return super<A>.toString()
|
||||
return super.toString()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
open class A {
|
||||
open fun foo() {}
|
||||
}
|
||||
|
||||
trait B {
|
||||
fun bar()
|
||||
}
|
||||
|
||||
class C : A(), B {
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
open class A {
|
||||
open fun foo() {}
|
||||
}
|
||||
|
||||
trait B {
|
||||
fun bar()
|
||||
}
|
||||
|
||||
class C : A(), B {
|
||||
override fun bar() {
|
||||
<selection><caret>throw UnsupportedOperationException()</selection>
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return super<A>.equals(other)
|
||||
}
|
||||
|
||||
override fun foo() {
|
||||
super<A>.foo()
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return super<A>.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return super<A>.toString()
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,15 @@ trait Some {
|
||||
|
||||
class Other {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
<selection><caret>return super<Any>.equals(other)</selection>
|
||||
<selection><caret>return super.equals(other)</selection>
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return super<Any>.hashCode()
|
||||
return super.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return super<Any>.toString()
|
||||
return super.toString()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -8,15 +8,15 @@ class Other {
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
<selection><caret>return super<Any>.equals(other)</selection>
|
||||
<selection><caret>return super.equals(other)</selection>
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return super<Any>.hashCode()
|
||||
return super.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return super<Any>.toString()
|
||||
return super.toString()
|
||||
}
|
||||
|
||||
fun otherTest() {
|
||||
|
||||
@@ -4,15 +4,15 @@ trait Some {
|
||||
|
||||
class Other {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
<selection><caret>return super<Any>.equals(other)</selection>
|
||||
<selection><caret>return super.equals(other)</selection>
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return super<Any>.hashCode()
|
||||
return super.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return super<Any>.toString()
|
||||
return super.toString()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -4,6 +4,6 @@ trait A<T> {
|
||||
|
||||
class C : A<C> {
|
||||
override fun foo(value: C) {
|
||||
<selection><caret>super<A>.foo(value)</selection>
|
||||
<selection><caret>super.foo(value)</selection>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,6 @@ import foo.A
|
||||
|
||||
class C : A() {
|
||||
override fun getAnswer(array: Array<out String>?, number: Int, value: Any?): Int {
|
||||
<selection><caret>return super<A>.getAnswer(array, number, value)</selection>
|
||||
<selection><caret>return super.getAnswer(array, number, value)</selection>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ trait A {
|
||||
|
||||
class C : A {
|
||||
override fun foo(value: String): Int {
|
||||
<selection><caret>return super<A>.foo(value)</selection>
|
||||
<selection><caret>return super.foo(value)</selection>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,19 +10,19 @@ class C : A() {
|
||||
get() = <selection><caret>0</selection>
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return super<A>.equals(other)
|
||||
return super.equals(other)
|
||||
}
|
||||
|
||||
override fun foo(value: Int) {
|
||||
super<A>.foo(value)
|
||||
super.foo(value)
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return super<A>.hashCode()
|
||||
return super.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return super<A>.toString()
|
||||
return super.toString()
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -2,6 +2,6 @@ package foo
|
||||
|
||||
class Impl: B() {
|
||||
override fun foo(r: Runnable?) {
|
||||
<selection><caret>super<B>.foo(r)</selection>
|
||||
<selection><caret>super.foo(r)</selection>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ trait A {
|
||||
|
||||
class C : A {
|
||||
override fun foo(value: String) {
|
||||
<selection><caret>super<A>.foo(value)</selection>
|
||||
<selection><caret>super.foo(value)</selection>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,6 @@ package foo
|
||||
|
||||
class Impl : Bar() {
|
||||
override fun f(): Any? {
|
||||
<selection><caret>return super<Bar>.f()</selection>
|
||||
<selection><caret>return super.f()</selection>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@ public open class B() : A() {
|
||||
|
||||
public open class C() : B() {
|
||||
override fun foo() {
|
||||
<selection><caret>super<B>.foo()</selection>
|
||||
<selection><caret>super.foo()</selection>
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@ import dependency.D
|
||||
|
||||
class C: D<Int>() {
|
||||
override fun id(t: Int): Int {
|
||||
<selection><caret>return super<D>.id(t)</selection>
|
||||
<selection><caret>return super.id(t)</selection>
|
||||
}
|
||||
}
|
||||
@@ -189,4 +189,8 @@ public final class OverrideImplementTest extends AbstractOverrideImplementTest {
|
||||
public void testPropagationKJK() {
|
||||
doDirectoryTest(new OverrideMethodsHandler());
|
||||
}
|
||||
|
||||
public void testMultipleSupers() {
|
||||
doMultiOverrideFileTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user