KT-59836 [SLC] Copy type parameters from the parent interface to DefaultImpls methods
This commit is contained in:
committed by
Space Team
parent
ddb27f2b26
commit
6e6a4d6411
+2
-1
@@ -93,7 +93,8 @@ abstract class SymbolLightClassForClassLike<SType : KtClassOrObjectSymbol> prote
|
||||
}
|
||||
}
|
||||
|
||||
override fun hasTypeParameters(): Boolean = hasTypeParameters(ktModule, classOrObjectDeclaration, classOrObjectSymbolPointer)
|
||||
override fun hasTypeParameters(): Boolean =
|
||||
hasTypeParameters(ktModule, classOrObjectDeclaration, classOrObjectSymbolPointer)
|
||||
|
||||
override fun getTypeParameterList(): PsiTypeParameterList? = _typeParameterList
|
||||
|
||||
|
||||
+3
-1
@@ -122,7 +122,9 @@ internal class SymbolLightAccessorMethod private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun hasTypeParameters(): Boolean = hasTypeParameters(ktModule, containingPropertyDeclaration, containingPropertySymbolPointer)
|
||||
override fun hasTypeParameters(): Boolean =
|
||||
hasTypeParameters(ktModule, containingPropertyDeclaration, containingPropertySymbolPointer)
|
||||
|| containingClass.isDefaultImplsForInterfaceWithTypeParameters
|
||||
|
||||
override fun getTypeParameterList(): PsiTypeParameterList? = _typeParameterList
|
||||
override fun getTypeParameters(): Array<PsiTypeParameter> = _typeParameterList?.typeParameters ?: PsiTypeParameter.EMPTY_ARRAY
|
||||
|
||||
+2
-1
@@ -142,7 +142,8 @@ internal class SymbolLightAnnotationsMethod private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun propertyHasTypeParameters(): Boolean = hasTypeParameters(ktModule, containingPropertyDeclaration, containingPropertySymbolPointer)
|
||||
private fun propertyHasTypeParameters(): Boolean =
|
||||
hasTypeParameters(ktModule, containingPropertyDeclaration, containingPropertySymbolPointer)
|
||||
|
||||
private val _parametersList by lazyPub {
|
||||
SymbolLightParameterList(
|
||||
|
||||
+3
-1
@@ -70,7 +70,9 @@ internal class SymbolLightSimpleMethod(
|
||||
}
|
||||
}
|
||||
|
||||
override fun hasTypeParameters(): Boolean = hasTypeParameters(ktModule, functionDeclaration, functionSymbolPointer)
|
||||
override fun hasTypeParameters(): Boolean =
|
||||
hasTypeParameters(ktModule, functionDeclaration, functionSymbolPointer)
|
||||
|| containingClass.isDefaultImplsForInterfaceWithTypeParameters
|
||||
|
||||
override fun getTypeParameterList(): PsiTypeParameterList? = _typeParameterList
|
||||
override fun getTypeParameters(): Array<PsiTypeParameter> = _typeParameterList?.typeParameters ?: PsiTypeParameter.EMPTY_ARRAY
|
||||
|
||||
+3
-1
@@ -62,7 +62,9 @@ internal class SymbolLightTypeParameter private constructor(
|
||||
|
||||
override val givenAnnotations: List<KtLightAbstractAnnotation> get() = invalidAccess()
|
||||
|
||||
override fun copy(): PsiElement = SymbolLightTypeParameter(
|
||||
override fun copy(): PsiElement = copyTo(parent)
|
||||
|
||||
internal fun copyTo(parent: SymbolLightTypeParameterList): SymbolLightTypeParameter = SymbolLightTypeParameter(
|
||||
parent,
|
||||
index,
|
||||
typeParameterSymbolPointer,
|
||||
|
||||
+11
-2
@@ -13,8 +13,10 @@ import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.light.classes.symbol.*
|
||||
import org.jetbrains.kotlin.light.classes.symbol.basicIsEquivalentTo
|
||||
import org.jetbrains.kotlin.light.classes.symbol.compareSymbolPointers
|
||||
import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightMethodBase
|
||||
import org.jetbrains.kotlin.light.classes.symbol.toArrayIfNotEmptyOrDefault
|
||||
import org.jetbrains.kotlin.light.classes.symbol.withSymbol
|
||||
import org.jetbrains.kotlin.psi.KtTypeParameterListOwner
|
||||
@@ -42,11 +44,18 @@ internal class SymbolLightTypeParameterList(
|
||||
|
||||
private val _typeParameters: Collection<PsiTypeParameter> by lazyPub {
|
||||
symbolWithTypeParameterPointer.withSymbol(ktModule) {
|
||||
it.typeParameters.mapIndexed { index, parameter ->
|
||||
val parentInterface =
|
||||
(owner as? SymbolLightMethodBase)?.containingClass?.interfaceIfDefaultImpls
|
||||
|
||||
val fromInterface = parentInterface?.typeParameters?.mapNotNull {
|
||||
(it as? SymbolLightTypeParameter)?.copyTo(this@SymbolLightTypeParameterList)
|
||||
}.orEmpty()
|
||||
|
||||
fromInterface + it.typeParameters.mapIndexed { index, parameter ->
|
||||
SymbolLightTypeParameter(
|
||||
ktAnalysisSession = this,
|
||||
parent = this@SymbolLightTypeParameterList,
|
||||
index = index,
|
||||
index = fromInterface.size + index,
|
||||
typeParameterSymbol = parameter,
|
||||
)
|
||||
}
|
||||
|
||||
+9
@@ -31,6 +31,9 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.*
|
||||
import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassBase
|
||||
import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassForInterface
|
||||
import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassForInterfaceDefaultImpls
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.psi.KtTypeParameterListOwner
|
||||
@@ -287,6 +290,12 @@ internal fun hasTypeParameters(
|
||||
it.typeParameters.isNotEmpty()
|
||||
}
|
||||
|
||||
internal val SymbolLightClassBase.interfaceIfDefaultImpls: SymbolLightClassForInterface?
|
||||
get() = (this as? SymbolLightClassForInterfaceDefaultImpls)?.containingClass
|
||||
|
||||
internal val SymbolLightClassBase.isDefaultImplsForInterfaceWithTypeParameters: Boolean
|
||||
get() = interfaceIfDefaultImpls?.hasTypeParameters() ?: false
|
||||
|
||||
internal fun KtSymbolPointer<*>.isValid(ktModule: KtModule): Boolean = analyzeForLightClasses(ktModule) {
|
||||
restoreSymbol() != null
|
||||
}
|
||||
|
||||
+6
@@ -102,6 +102,12 @@ public class SymbolLightClassesByFqNameForLibraryTestGenerated extends AbstractS
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DataClassWithCustomImplementedMembers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DefaultImplsWithTypeParameters.kt")
|
||||
public void testDefaultImplsWithTypeParameters() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DefaultImplsWithTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DelegatedNested.kt")
|
||||
public void testDelegatedNested() throws Exception {
|
||||
|
||||
+6
@@ -102,6 +102,12 @@ public class SymbolLightClassesEqualityByFqNameForLibraryTestGenerated extends A
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DataClassWithCustomImplementedMembers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DefaultImplsWithTypeParameters.kt")
|
||||
public void testDefaultImplsWithTypeParameters() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DefaultImplsWithTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DelegatedNested.kt")
|
||||
public void testDelegatedNested() throws Exception {
|
||||
|
||||
+6
@@ -102,6 +102,12 @@ public class SymbolLightClassesParentingByFqNameForLibraryTestGenerated extends
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DataClassWithCustomImplementedMembers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DefaultImplsWithTypeParameters.kt")
|
||||
public void testDefaultImplsWithTypeParameters() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DefaultImplsWithTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DelegatedNested.kt")
|
||||
public void testDelegatedNested() throws Exception {
|
||||
|
||||
+6
@@ -102,6 +102,12 @@ public class SymbolLightClassesByFqNameForSourceTestGenerated extends AbstractSy
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DataClassWithCustomImplementedMembers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DefaultImplsWithTypeParameters.kt")
|
||||
public void testDefaultImplsWithTypeParameters() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DefaultImplsWithTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DelegatedNested.kt")
|
||||
public void testDelegatedNested() throws Exception {
|
||||
|
||||
+6
@@ -102,6 +102,12 @@ public class SymbolLightClassesEqualityByFqNameForSourceTestGenerated extends Ab
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DataClassWithCustomImplementedMembers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DefaultImplsWithTypeParameters.kt")
|
||||
public void testDefaultImplsWithTypeParameters() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DefaultImplsWithTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DelegatedNested.kt")
|
||||
public void testDelegatedNested() throws Exception {
|
||||
|
||||
+6
@@ -102,6 +102,12 @@ public class SymbolLightClassesParentingByFqNameForSourceTestGenerated extends A
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DataClassWithCustomImplementedMembers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DefaultImplsWithTypeParameters.kt")
|
||||
public void testDefaultImplsWithTypeParameters() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DefaultImplsWithTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DelegatedNested.kt")
|
||||
public void testDelegatedNested() throws Exception {
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
public abstract interface Foo /* Foo*/<X, Y> {
|
||||
public abstract <Z> void foo(X, Y, Z);// <Z> foo(X, Y, Z)
|
||||
|
||||
public abstract int getX();// getX()
|
||||
|
||||
public static final class DefaultImpls /* Foo.DefaultImpls*/ {
|
||||
public static <Z> void foo(@org.jetbrains.annotations.NotNull() Foo, X, Y, Z);// <Z> foo(Foo, X, Y, Z)
|
||||
|
||||
public static int getX(@org.jetbrains.annotations.NotNull() Foo);// getX(Foo)
|
||||
}
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
public abstract interface Foo /* Foo*/<X, Y> {
|
||||
public abstract <Z> void foo(X, Y, Z);// <Z> foo(X, Y, Z)
|
||||
|
||||
public abstract int getX();// getX()
|
||||
|
||||
public static final class DefaultImpls /* Foo.DefaultImpls*/ {
|
||||
public static <X, Y, Z> void foo(@org.jetbrains.annotations.NotNull() Foo<X, Y>, X, Y, Z);// <X, Y, Z> foo(Foo<X, Y>, X, Y, Z)
|
||||
|
||||
public static <X, Y> int getX(@org.jetbrains.annotations.NotNull() Foo<X, Y>);// <X, Y> getX(Foo<X, Y>)
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// Foo
|
||||
interface Foo<X, Y> {
|
||||
fun <Z> foo(x: X, y: Y, z: Z) {}
|
||||
|
||||
val x: Int get() = 0
|
||||
}
|
||||
compiler/testData/asJava/lightClasses/lightClassByFqName/ExtendingInterfaceWithDefaultImpls.fir.java
Vendored
+3
-3
@@ -19,10 +19,10 @@ public abstract interface C /* p.C*/<T> extends p.B {
|
||||
public static void getProp3$annotations();// getProp3$annotations()
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static java.lang.String c(@org.jetbrains.annotations.NotNull() p.C<T>);// c(p.C<T>)
|
||||
public static <T> java.lang.String c(@org.jetbrains.annotations.NotNull() p.C<T>);// <T> c(p.C<T>)
|
||||
|
||||
public static int getProp3(@org.jetbrains.annotations.NotNull() p.C<T>);// getProp3(p.C<T>)
|
||||
public static <T> int getProp3(@org.jetbrains.annotations.NotNull() p.C<T>);// <T> getProp3(p.C<T>)
|
||||
|
||||
public static void setProp3(@org.jetbrains.annotations.NotNull() p.C<T>, int);// setProp3(p.C<T>, int)
|
||||
public static <T> void setProp3(@org.jetbrains.annotations.NotNull() p.C<T>, int);// <T> setProp3(p.C<T>, int)
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -94,6 +94,11 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DataClassWithCustomImplementedMembers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("DefaultImplsWithTypeParameters.kt")
|
||||
public void testDefaultImplsWithTypeParameters() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DefaultImplsWithTypeParameters.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("DelegatedNested.kt")
|
||||
public void testDelegatedNested() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/DelegatedNested.kt");
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
interface Foo<X, Y> {
|
||||
fun <Z> foo(x: X, y: Y, z: Z) {}
|
||||
|
||||
val x: Int get() = 0
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
@kotlin.Metadata()
|
||||
public abstract interface Foo<X extends java.lang.Object, Y extends java.lang.Object> {
|
||||
|
||||
public abstract <Z extends java.lang.Object>void foo(X x, Y y, Z z);
|
||||
|
||||
public abstract int getX();
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static final class DefaultImpls {
|
||||
|
||||
public DefaultImpls() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static <X extends java.lang.Object, Y extends java.lang.Object, Z extends java.lang.Object>void foo(@org.jetbrains.annotations.NotNull()
|
||||
Foo<X, Y> $this, X x, Y y, Z z) {
|
||||
}
|
||||
|
||||
public static <X extends java.lang.Object, Y extends java.lang.Object>int getX(@org.jetbrains.annotations.NotNull()
|
||||
Foo<X, Y> $this) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -127,6 +127,12 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/defaultImpls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("defaultImplsWithTypeParameters.kt")
|
||||
public void testDefaultImplsWithTypeParameters() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/defaultImplsWithTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("defaultPackage.kt")
|
||||
public void testDefaultPackage() throws Exception {
|
||||
|
||||
+6
@@ -127,6 +127,12 @@ public class IrClassFileToSourceStubConverterTestGenerated extends AbstractIrCla
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/defaultImpls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("defaultImplsWithTypeParameters.kt")
|
||||
public void testDefaultImplsWithTypeParameters() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/defaultImplsWithTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("defaultPackage.kt")
|
||||
public void testDefaultPackage() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user