No need to scan base classes
This commit is contained in:
+15
-20
@@ -30,10 +30,7 @@ import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.types.DescriptorSubstitutor
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.JetType
|
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
|
||||||
import org.jetbrains.kotlin.types.Variance
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isBoolean
|
import org.jetbrains.kotlin.types.typeUtil.isBoolean
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||||
@@ -167,9 +164,9 @@ class JavaSyntheticExtensionsScope(storageManager: StorageManager) : JetScope by
|
|||||||
|
|
||||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<JetType>, name: Name): Collection<PropertyDescriptor> {
|
override fun getSyntheticExtensionProperties(receiverTypes: Collection<JetType>, name: Name): Collection<PropertyDescriptor> {
|
||||||
var result: SmartList<PropertyDescriptor>? = null
|
var result: SmartList<PropertyDescriptor>? = null
|
||||||
val processedTypes: MutableSet<JetType>? = if (receiverTypes.size() > 1) HashSet<JetType>() else null
|
val processedTypes: MutableSet<TypeConstructor>? = if (receiverTypes.size() > 1) HashSet<TypeConstructor>() else null
|
||||||
for (type in receiverTypes) {
|
for (type in receiverTypes) {
|
||||||
result = collectSyntheticPropertiesByName(result, type.makeNotNullable(), name, processedTypes)
|
result = collectSyntheticPropertiesByName(result, type.constructor, name, processedTypes)
|
||||||
}
|
}
|
||||||
return when {
|
return when {
|
||||||
result == null -> emptyList()
|
result == null -> emptyList()
|
||||||
@@ -178,37 +175,34 @@ class JavaSyntheticExtensionsScope(storageManager: StorageManager) : JetScope by
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun collectSyntheticPropertiesByName(result: SmartList<PropertyDescriptor>?, type: JetType, name: Name, processedTypes: MutableSet<JetType>?): SmartList<PropertyDescriptor>? {
|
private fun collectSyntheticPropertiesByName(result: SmartList<PropertyDescriptor>?, type: TypeConstructor, name: Name, processedTypes: MutableSet<TypeConstructor>?): SmartList<PropertyDescriptor>? {
|
||||||
if (processedTypes != null && !processedTypes.add(type)) return result
|
if (processedTypes != null && !processedTypes.add(type)) return result
|
||||||
|
|
||||||
@suppress("NAME_SHADOWING")
|
@suppress("NAME_SHADOWING")
|
||||||
var result = result
|
var result = result
|
||||||
|
|
||||||
val typeConstructor = type.getConstructor()
|
val classifier = type.declarationDescriptor
|
||||||
val classifier = typeConstructor.getDeclarationDescriptor()
|
|
||||||
if (classifier is ClassDescriptor) {
|
if (classifier is ClassDescriptor) {
|
||||||
result = result.add(syntheticPropertyInClass(Pair(classifier, name)))
|
result = result.add(syntheticPropertyInClass(Pair(classifier, name)))
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
typeConstructor.getSupertypes().forEach { result = collectSyntheticPropertiesByName(result, it, name, processedTypes) }
|
type.supertypes.forEach { result = collectSyntheticPropertiesByName(result, it.constructor, name, processedTypes) }
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<JetType>): Collection<PropertyDescriptor> {
|
override fun getSyntheticExtensionProperties(receiverTypes: Collection<JetType>): Collection<PropertyDescriptor> {
|
||||||
val result = ArrayList<PropertyDescriptor>()
|
val result = ArrayList<PropertyDescriptor>()
|
||||||
val processedTypes = HashSet<JetType>()
|
val processedTypes = HashSet<TypeConstructor>()
|
||||||
receiverTypes.forEach {
|
receiverTypes.forEach { result.collectSyntheticProperties(it.constructor, processedTypes) }
|
||||||
result.collectSyntheticProperties(it.makeNotNullable(), processedTypes)
|
|
||||||
}
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun MutableList<PropertyDescriptor>.collectSyntheticProperties(type: JetType, processedTypes: MutableSet<JetType>) {
|
private fun MutableList<PropertyDescriptor>.collectSyntheticProperties(type: TypeConstructor, processedTypes: MutableSet<TypeConstructor>) {
|
||||||
if (!processedTypes.add(type)) return
|
if (!processedTypes.add(type)) return
|
||||||
|
|
||||||
val typeConstructor = type.getConstructor()
|
val classifier = type.declarationDescriptor
|
||||||
val classifier = typeConstructor.getDeclarationDescriptor()
|
|
||||||
if (classifier is ClassDescriptor) {
|
if (classifier is ClassDescriptor) {
|
||||||
for (descriptor in classifier.getUnsubstitutedMemberScope().getDescriptors(DescriptorKindFilter.FUNCTIONS)) {
|
for (descriptor in classifier.getUnsubstitutedMemberScope().getDescriptors(DescriptorKindFilter.FUNCTIONS)) {
|
||||||
if (descriptor is FunctionDescriptor) {
|
if (descriptor is FunctionDescriptor) {
|
||||||
@@ -217,8 +211,9 @@ class JavaSyntheticExtensionsScope(storageManager: StorageManager) : JetScope by
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
typeConstructor.getSupertypes().forEach { collectSyntheticProperties(it, processedTypes) }
|
type.supertypes.forEach { collectSyntheticProperties(it.constructor, processedTypes) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SmartList<PropertyDescriptor>?.add(property: PropertyDescriptor?): SmartList<PropertyDescriptor>? {
|
private fun SmartList<PropertyDescriptor>?.add(property: PropertyDescriptor?): SmartList<PropertyDescriptor>? {
|
||||||
|
|||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
// FILE: KotlinFile.kt
|
||||||
|
|
||||||
|
fun <T: B> foo(t: T) {
|
||||||
|
t.setSomething(t.getSomething() + 1)
|
||||||
|
t.something++
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: A.java
|
||||||
|
public interface A {
|
||||||
|
int getSomething();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: B.java
|
||||||
|
public interface B extends A {
|
||||||
|
void setSomething(int value);
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public /*synthesized*/ fun A(/*0*/ function: () -> kotlin.Int): A
|
||||||
|
internal fun </*0*/ T : B> foo(/*0*/ t: T): kotlin.Unit
|
||||||
|
|
||||||
|
public interface A {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public abstract fun getSomething(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface B : A {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public abstract override /*1*/ /*fake_override*/ fun getSomething(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public abstract fun setSomething(/*0*/ value: kotlin.Int): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -14153,6 +14153,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/syntheticExtensions/SmartCastImplicitReceiver.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/syntheticExtensions/SmartCastImplicitReceiver.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("TypeParameterReceiver.kt")
|
||||||
|
public void testTypeParameterReceiver() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/syntheticExtensions/TypeParameterReceiver.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/thisAndSuper")
|
@TestMetadata("compiler/testData/diagnostics/tests/thisAndSuper")
|
||||||
|
|||||||
Reference in New Issue
Block a user