Avoid generation of redundant toArray stubs
#KT-13698 In Progress
This commit is contained in:
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.descriptors.*;
|
|||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||||
|
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
@@ -430,9 +431,16 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
private void generateToArray() {
|
private void generateToArray() {
|
||||||
if (descriptor.getKind() == ClassKind.INTERFACE) return;
|
if (descriptor.getKind() == ClassKind.INTERFACE) return;
|
||||||
|
|
||||||
KotlinBuiltIns builtIns = DescriptorUtilsKt.getBuiltIns(descriptor);
|
final KotlinBuiltIns builtIns = DescriptorUtilsKt.getBuiltIns(descriptor);
|
||||||
if (!isSubclass(descriptor, builtIns.getCollection())) return;
|
if (!isSubclass(descriptor, builtIns.getCollection())) return;
|
||||||
|
|
||||||
|
if (CollectionsKt.any(DescriptorUtilsKt.getAllSuperclassesWithoutAny(descriptor), new Function1<ClassDescriptor, Boolean>() {
|
||||||
|
@Override
|
||||||
|
public Boolean invoke(ClassDescriptor classDescriptor) {
|
||||||
|
return !(classDescriptor instanceof JavaClassDescriptor) && isSubclass(classDescriptor, builtIns.getCollection());
|
||||||
|
}
|
||||||
|
})) return;
|
||||||
|
|
||||||
Collection<SimpleFunctionDescriptor> functions = descriptor.getDefaultType().getMemberScope().getContributedFunctions(
|
Collection<SimpleFunctionDescriptor> functions = descriptor.getDefaultType().getMemberScope().getContributedFunctions(
|
||||||
Name.identifier("toArray"), NoLookupLocation.FROM_BACKEND
|
Name.identifier("toArray"), NoLookupLocation.FROM_BACKEND
|
||||||
);
|
);
|
||||||
|
|||||||
-2
@@ -30,8 +30,6 @@ public final class test/C {
|
|||||||
public method remove(p0: int): java.lang.Object
|
public method remove(p0: int): java.lang.Object
|
||||||
public method set(p0: int, p1: java.lang.Object): java.lang.Object
|
public method set(p0: int, p1: java.lang.Object): java.lang.Object
|
||||||
public @org.jetbrains.annotations.NotNull method subList(p0: int, p1: int): java.util.List
|
public @org.jetbrains.annotations.NotNull method subList(p0: int, p1: int): java.util.List
|
||||||
public method toArray(): java.lang.Object[]
|
|
||||||
public method toArray(p0: java.lang.Object[]): java.lang.Object[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
|
|||||||
-4
@@ -20,8 +20,6 @@ public class A {
|
|||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public class B {
|
public class B {
|
||||||
public method <init>(): void
|
public method <init>(): void
|
||||||
public method toArray(): java.lang.Object[]
|
|
||||||
public method toArray(p0: java.lang.Object[]): java.lang.Object[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
@@ -37,6 +35,4 @@ public final class C {
|
|||||||
public method remove(p0: int): java.lang.Object
|
public method remove(p0: int): java.lang.Object
|
||||||
public method set(p0: int, p1: java.lang.Object): java.lang.Object
|
public method set(p0: int, p1: java.lang.Object): java.lang.Object
|
||||||
public @org.jetbrains.annotations.NotNull method subList(p0: int, p1: int): java.util.List
|
public @org.jetbrains.annotations.NotNull method subList(p0: int, p1: int): java.util.List
|
||||||
public method toArray(): java.lang.Object[]
|
|
||||||
public method toArray(p0: java.lang.Object[]): java.lang.Object[]
|
|
||||||
}
|
}
|
||||||
|
|||||||
-4
@@ -22,8 +22,6 @@ public class B {
|
|||||||
public method <init>(): void
|
public method <init>(): void
|
||||||
public method contains(p0: java.lang.CharSequence): boolean
|
public method contains(p0: java.lang.CharSequence): boolean
|
||||||
public final method contains(p0: java.lang.Object): boolean
|
public final method contains(p0: java.lang.Object): boolean
|
||||||
public method toArray(): java.lang.Object[]
|
|
||||||
public method toArray(p0: java.lang.Object[]): java.lang.Object[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
@@ -45,6 +43,4 @@ public final class C {
|
|||||||
public method set(p0: int, p1: java.lang.CharSequence): java.lang.CharSequence
|
public method set(p0: int, p1: java.lang.CharSequence): java.lang.CharSequence
|
||||||
public synthetic method set(p0: int, p1: java.lang.Object): java.lang.Object
|
public synthetic method set(p0: int, p1: java.lang.Object): java.lang.Object
|
||||||
public @org.jetbrains.annotations.NotNull method subList(p0: int, p1: int): java.util.List
|
public @org.jetbrains.annotations.NotNull method subList(p0: int, p1: int): java.util.List
|
||||||
public method toArray(): java.lang.Object[]
|
|
||||||
public method toArray(p0: java.lang.Object[]): java.lang.Object[]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// FILE: test/JavaClass.java
|
||||||
|
package test;
|
||||||
|
|
||||||
|
public abstract class JavaClass<T> implements A<T> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
package test
|
||||||
|
|
||||||
|
interface A<T> : Collection<T>
|
||||||
|
|
||||||
|
// There must be toArray methods in B
|
||||||
|
abstract class B<E> : JavaClass<E>()
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
@kotlin.Metadata
|
||||||
|
public interface test/A
|
||||||
|
|
||||||
|
@kotlin.Metadata
|
||||||
|
public abstract class test/B {
|
||||||
|
public method <init>(): void
|
||||||
|
public method add(p0: java.lang.Object): boolean
|
||||||
|
public method addAll(p0: java.util.Collection): boolean
|
||||||
|
public method clear(): void
|
||||||
|
public abstract method contains(p0: java.lang.Object): boolean
|
||||||
|
public abstract method getSize(): int
|
||||||
|
public method iterator(): java.util.Iterator
|
||||||
|
public method remove(p0: java.lang.Object): boolean
|
||||||
|
public method removeAll(p0: java.util.Collection): boolean
|
||||||
|
public method retainAll(p0: java.util.Collection): boolean
|
||||||
|
public final method size(): int
|
||||||
|
public method toArray(): java.lang.Object[]
|
||||||
|
public method toArray(p0: java.lang.Object[]): java.lang.Object[]
|
||||||
|
}
|
||||||
-4
@@ -42,8 +42,6 @@ public final class A1 {
|
|||||||
public method remove(p0: java.lang.String): boolean
|
public method remove(p0: java.lang.String): boolean
|
||||||
public synthetic method removeAt(p0: int): java.lang.Object
|
public synthetic method removeAt(p0: int): java.lang.Object
|
||||||
public @org.jetbrains.annotations.NotNull method removeAt(p0: int): java.lang.String
|
public @org.jetbrains.annotations.NotNull method removeAt(p0: int): java.lang.String
|
||||||
public method toArray(): java.lang.Object[]
|
|
||||||
public method toArray(p0: java.lang.Object[]): java.lang.Object[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
@@ -59,6 +57,4 @@ public final class A2 {
|
|||||||
public final method remove(p0: java.lang.Object): boolean
|
public final method remove(p0: java.lang.Object): boolean
|
||||||
public method remove(p0: java.lang.String): boolean
|
public method remove(p0: java.lang.String): boolean
|
||||||
public method removeAt(p0: int): java.lang.String
|
public method removeAt(p0: int): java.lang.String
|
||||||
public method toArray(): java.lang.Object[]
|
|
||||||
public method toArray(p0: java.lang.Object[]): java.lang.Object[]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,12 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noToArrayInJava.kt")
|
||||||
|
public void testNoToArrayInJava() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/noToArrayInJava.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("samAdapterAndInlinedOne.kt")
|
@TestMetadata("samAdapterAndInlinedOne.kt")
|
||||||
public void testSamAdapterAndInlinedOne() throws Exception {
|
public void testSamAdapterAndInlinedOne() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/samAdapterAndInlinedOne.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/samAdapterAndInlinedOne.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user