Removed KtScope.Empty and created util function emptyScope
This commit is contained in:
@@ -35,12 +35,8 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.DelegationToTraitImpl
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.org.objectweb.asm.AnnotationVisitor
|
||||
import org.jetbrains.org.objectweb.asm.FieldVisitor
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.ACC_FINAL
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.ACC_PUBLIC
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.V1_6
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.*
|
||||
import java.util.*
|
||||
|
||||
public class InterfaceImplBodyCodegen(
|
||||
@@ -69,7 +65,7 @@ public class InterfaceImplBodyCodegen(
|
||||
descriptor, Name.identifier(JvmAbi.DEFAULT_IMPLS_CLASS_NAME),
|
||||
Modality.FINAL, Collections.emptyList(), SourceElement.NO_SOURCE)
|
||||
|
||||
classDescriptorImpl.initialize(KtScope.Empty, emptySet(), null)
|
||||
classDescriptorImpl.initialize(KtScope.empty(classDescriptorImpl), emptySet(), null)
|
||||
return classDescriptorImpl
|
||||
}
|
||||
|
||||
|
||||
@@ -161,13 +161,13 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
@Override
|
||||
@NotNull
|
||||
public KtScope getUnsubstitutedMemberScope() {
|
||||
return KtScope.Empty.INSTANCE$; // used for getDefaultType
|
||||
return KtScope.Companion.empty(this); // used for getDefaultType
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public KtScope getStaticScope() {
|
||||
return KtScope.Empty.INSTANCE$;
|
||||
return KtScope.Companion.empty(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
supertypes,
|
||||
KotlinSourceElementKt.toSourceElement(element)
|
||||
);
|
||||
classDescriptor.initialize(KtScope.Empty.INSTANCE$, Collections.<ConstructorDescriptor>emptySet(), null);
|
||||
classDescriptor.initialize(KtScope.Companion.empty(classDescriptor), Collections.<ConstructorDescriptor>emptySet(), null);
|
||||
|
||||
bindingTrace.record(CLASS_FOR_CALLABLE, callableDescriptor, classDescriptor);
|
||||
return classDescriptor;
|
||||
|
||||
@@ -212,7 +212,7 @@ public class CodegenBinding {
|
||||
new ClassDescriptorImpl(descriptor, Name.special("<script-" + simpleName + ">"), Modality.FINAL,
|
||||
Collections.singleton(DescriptorUtilsKt.getBuiltIns(descriptor).getAnyType()),
|
||||
KotlinSourceElementKt.toSourceElement(script));
|
||||
classDescriptor.initialize(KtScope.Empty.INSTANCE$, Collections.<ConstructorDescriptor>emptySet(), null);
|
||||
classDescriptor.initialize(KtScope.Companion.empty(classDescriptor), Collections.<ConstructorDescriptor>emptySet(), null);
|
||||
|
||||
recordClosure(trace, classDescriptor, null, asmType, fileClassesManager);
|
||||
|
||||
|
||||
+3
-3
@@ -99,7 +99,7 @@ public class IncrementalPackageFragmentProvider(
|
||||
|
||||
val memberScope: NotNullLazyValue<KtScope> = storageManager.createLazyValue {
|
||||
if (fqName !in fqNamesToLoad) {
|
||||
KtScope.Empty
|
||||
KtScope.empty(this)
|
||||
}
|
||||
else {
|
||||
val moduleMapping = incrementalCache.getModuleMappingData()?.let { ModuleMapping.create(it) }
|
||||
@@ -128,7 +128,7 @@ public class IncrementalPackageFragmentProvider(
|
||||
}
|
||||
|
||||
if (scopes.isEmpty()) {
|
||||
KtScope.Empty
|
||||
KtScope.empty(this)
|
||||
}
|
||||
else {
|
||||
ChainedScope(this, "Member scope for incremental compilation: union of package parts data", *scopes.toTypedArray())
|
||||
@@ -151,7 +151,7 @@ public class IncrementalPackageFragmentProvider(
|
||||
val memberScope = storageManager.createLazyValue {
|
||||
val partsData = partsNames.map { incrementalCache.getPackagePartData(it) }.filterNotNull()
|
||||
if (partsData.isEmpty())
|
||||
KtScope.Empty
|
||||
KtScope.empty(this)
|
||||
else {
|
||||
val scopes = partsData.map { IncrementalPackageScope(JvmProtoBufUtil.readPackageDataFrom(it.data, it.strings)) }
|
||||
ChainedScope(this,
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ class PropagationHeuristics {
|
||||
arrayTypeFromSuper.getConstructor(),
|
||||
arrayTypeFromSuper.isMarkedNullable(),
|
||||
Arrays.asList(new TypeProjectionImpl(Variance.OUT_VARIANCE, elementTypeInSuper)),
|
||||
KtScope.Empty.INSTANCE$);
|
||||
KtScope.Companion.empty(elementType.getMemberScope().getContainingDeclaration()));
|
||||
|
||||
data.reportError("Return type is not a subtype of overridden method. " +
|
||||
"To fix it, add annotation with Kotlin signature to super method with type "
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ public class MutablePackageFragmentDescriptor extends PackageFragmentDescriptorI
|
||||
public MutablePackageFragmentDescriptor(@NotNull ModuleDescriptor module, @NotNull FqName fqName) {
|
||||
super(module, fqName);
|
||||
|
||||
scope = new SimpleKtScope(this, "Members of " + fqName + " in " + module);
|
||||
scope = KtScope.Companion.empty(module);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+2
-2
@@ -165,7 +165,7 @@ public class ConstraintSystemImpl : ConstraintSystem {
|
||||
|
||||
val TypeParameterDescriptor.correspondingType: KotlinType
|
||||
get() = cachedTypeForVariable.getOrPut(this) {
|
||||
KotlinTypeImpl.create(Annotations.EMPTY, this.getTypeConstructor(), false, listOf(), KtScope.Empty)
|
||||
KotlinTypeImpl.create(Annotations.EMPTY, this.getTypeConstructor(), false, listOf(), KtScope.empty(this))
|
||||
}
|
||||
|
||||
fun KotlinType.isProper() = !TypeUtils.containsSpecialType(this) {
|
||||
@@ -573,7 +573,7 @@ public fun createTypeSubstitutor(conversion: (TypeParameterDescriptor) -> TypePa
|
||||
if (descriptor !is TypeParameterDescriptor) return null
|
||||
val typeParameterDescriptor = conversion(descriptor) ?: return null
|
||||
|
||||
val type = KotlinTypeImpl.create(Annotations.EMPTY, typeParameterDescriptor.getTypeConstructor(), false, listOf(), KtScope.Empty)
|
||||
val type = KotlinTypeImpl.create(Annotations.EMPTY, typeParameterDescriptor.getTypeConstructor(), false, listOf(), KtScope.empty(typeParameterDescriptor))
|
||||
return TypeProjectionImpl(type)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -104,7 +104,7 @@ class ClassifierQualifier(
|
||||
|
||||
override val scope: KtScope get() {
|
||||
if (classifier !is ClassDescriptor) {
|
||||
return KtScope.Empty
|
||||
return KtScope.empty(classifier)
|
||||
}
|
||||
|
||||
val scopes = ArrayList<KtScope>(3)
|
||||
@@ -125,7 +125,7 @@ class ClassifierQualifier(
|
||||
|
||||
override fun getNestedClassesAndPackageMembersScope(): KtScope {
|
||||
if (classifier !is ClassDescriptor) {
|
||||
return KtScope.Empty
|
||||
return KtScope.empty(classifier)
|
||||
}
|
||||
|
||||
val scopes = ArrayList<KtScope>(2)
|
||||
|
||||
+10
-2
@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.erro
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.Configuration
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import java.io.File
|
||||
import java.net.URLClassLoader
|
||||
@@ -210,8 +211,11 @@ public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdi
|
||||
get() = throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
private class ScopeWithClassifiers(classifiers: List<ClassifierDescriptor>, ownerDescriptor: DeclarationDescriptor)
|
||||
: SimpleKtScope(ownerDescriptor, "runtime descriptor loader test") {
|
||||
private class ScopeWithClassifiers(
|
||||
classifiers: List<ClassifierDescriptor>,
|
||||
val ownerDescriptor: DeclarationDescriptor
|
||||
) : KtScopeImpl() {
|
||||
override fun getContainingDeclaration() = ownerDescriptor
|
||||
|
||||
private val classifierMap = HashMap<Name, ClassifierDescriptor>()
|
||||
val redeclarationHandler = RedeclarationHandler.THROW_EXCEPTION
|
||||
@@ -227,6 +231,10 @@ public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdi
|
||||
override fun getClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = classifierMap[name]
|
||||
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = classifierMap.values
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println("runtime descriptor loader test")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public class ConstraintSystemTestData(
|
||||
val number = matcher.group(1)!!
|
||||
return KotlinTypeImpl.create(
|
||||
Annotations.EMPTY, IntegerValueTypeConstructor(number.toLong(), functionFoo.builtIns), false, listOf(),
|
||||
KtScope.Empty
|
||||
KtScope.empty(functionFoo)
|
||||
)
|
||||
}
|
||||
return typeResolver.resolveType(
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ public class LazyJavaPackageScope(
|
||||
c.components.deserializedDescriptorResolver.readData(binaryClass, DeserializedDescriptorResolver.KOTLIN_PACKAGE_FACADE)
|
||||
}
|
||||
|
||||
KtScope.Empty
|
||||
KtScope.empty(packageFragment)
|
||||
}
|
||||
else {
|
||||
c.components.deserializedDescriptorResolver.createKotlinPackageScope(packageFragment, containingDeclaration.kotlinBinaryClasses)
|
||||
|
||||
+2
-2
@@ -42,7 +42,7 @@ class BuiltInClassesAreSerializableOnJvm(
|
||||
|
||||
private fun createMockJavaIoSerializableType(): KotlinType {
|
||||
val mockJavaIoPackageFragment = object : PackageFragmentDescriptorImpl(moduleDescriptor, FqName("java.io")) {
|
||||
override fun getMemberScope() = KtScope.Empty
|
||||
override fun getMemberScope() = KtScope.empty(this)
|
||||
}
|
||||
|
||||
//NOTE: can't reference anyType right away, because this is sometimes called when JvmBuiltIns are initializing
|
||||
@@ -56,7 +56,7 @@ class BuiltInClassesAreSerializableOnJvm(
|
||||
mockJavaIoPackageFragment, Name.identifier("Serializable"), Modality.ABSTRACT, superTypes, SourceElement.NO_SOURCE
|
||||
)
|
||||
|
||||
mockSerializableClass.initialize(KtScope.Empty, emptySet(), null)
|
||||
mockSerializableClass.initialize(KtScope.empty(mockSerializableClass), emptySet(), null)
|
||||
return mockSerializableClass.defaultType
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ public final class DeserializedDescriptorResolver {
|
||||
}
|
||||
}
|
||||
if (list.isEmpty()) {
|
||||
return KtScope.Empty.INSTANCE$;
|
||||
return KtScope.Companion.empty(descriptor);
|
||||
}
|
||||
return new ChainedScope(descriptor, "Member scope for union of package parts data", list.toArray(new KtScope[list.size()]));
|
||||
}
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class LazyPackageViewDescriptorImpl(
|
||||
|
||||
override val memberScope: KtScope = LazyScopeAdapter(storageManager.createLazyValue {
|
||||
if (fragments.isEmpty()) {
|
||||
KtScope.Empty
|
||||
KtScope.empty(this)
|
||||
}
|
||||
else {
|
||||
val scopes = fragments.map { it.getMemberScope() } + SubpackagesScope(module, fqName)
|
||||
|
||||
@@ -50,19 +50,19 @@ public interface KtScope {
|
||||
*/
|
||||
public fun printScopeStructure(p: Printer)
|
||||
|
||||
public object Empty : KtScopeImpl() {
|
||||
override fun getContainingDeclaration(): DeclarationDescriptor {
|
||||
throw UnsupportedOperationException("Don't take containing declaration of the Empty scope")
|
||||
}
|
||||
|
||||
override fun toString() = "Empty"
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println("Empty")
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
public fun empty(ownerDescriptor: DeclarationDescriptor): KtScope {
|
||||
return object : KtScopeImpl() {
|
||||
override fun getContainingDeclaration() = ownerDescriptor
|
||||
|
||||
override fun toString() = "Empty scope with owner: $ownerDescriptor"
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println(toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public val ALL_NAME_FILTER: (Name) -> Boolean = { true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,12 +35,4 @@ abstract class KtScopeImpl : KtScope {
|
||||
|
||||
// This method should not be implemented here by default: every scope class has its unique structure pattern
|
||||
abstract override fun printScopeStructure(p: Printer)
|
||||
}
|
||||
|
||||
open class SimpleKtScope(val ownerDescriptor: DeclarationDescriptor, val debugName: String): KtScopeImpl() {
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println(javaClass.getSimpleName(), ": ", debugName, " for ", ownerDescriptor, " {")
|
||||
}
|
||||
|
||||
override fun getContainingDeclaration() = ownerDescriptor
|
||||
}
|
||||
+1
-1
@@ -74,7 +74,7 @@ private class MissingDependencyErrorClassDescriptor(
|
||||
val emptyConstructor = ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true, SourceElement.NO_SOURCE)
|
||||
emptyConstructor.initialize(listOf(), listOf(), Visibilities.DEFAULT_VISIBILITY)
|
||||
emptyConstructor.setReturnType(createErrorType("<ERROR RETURN TYPE>"))
|
||||
initialize(KtScope.Empty, setOf(emptyConstructor), emptyConstructor)
|
||||
initialize(KtScope.empty(this), setOf(emptyConstructor), emptyConstructor)
|
||||
}
|
||||
|
||||
override fun substitute(substitutor: TypeSubstitutor) = this
|
||||
|
||||
Reference in New Issue
Block a user