From 873cf439dea270db0a13d3f81593c13235460117 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 15 Mar 2016 17:33:08 +0300 Subject: [PATCH] Drop MissingDependencyErrorClass and related code No longer needed because of the proper support for missing classes in deserialization (see NotFoundClasses.kt) --- .../kotlin/descriptors/typeParameterUtils.kt | 9 +- .../kotlin/renderer/DescriptorRendererImpl.kt | 4 - .../kotlin/types/TypeCapabilities.kt | 10 +-- .../error/MissingDependencyErrorClass.kt | 24 ----- .../deserialization/DeserializedType.kt | 49 +++-------- .../textBuilder/DecompiledTextFactory.kt | 4 - .../DeserializerForDecompilerBase.kt | 9 +- .../textBuilder/missingDependencies.kt | 87 ------------------- 8 files changed, 16 insertions(+), 180 deletions(-) delete mode 100644 core/descriptors/src/org/jetbrains/kotlin/types/error/MissingDependencyErrorClass.kt delete mode 100644 idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/missingDependencies.kt diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/typeParameterUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/typeParameterUtils.kt index 35a05bb5fbb..3ff3d598894 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/typeParameterUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/typeParameterUtils.kt @@ -18,8 +18,9 @@ package org.jetbrains.kotlin.descriptors import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.descriptorUtil.parents -import org.jetbrains.kotlin.types.* -import org.jetbrains.kotlin.types.error.MissingDependencyErrorClass +import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.TypeProjection import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull fun ClassDescriptor.computeConstructorTypeParameters(): List { @@ -66,10 +67,6 @@ class PossiblyInnerType( } fun KotlinType.buildPossiblyInnerType(): PossiblyInnerType? { - if (constructor.declarationDescriptor is MissingDependencyErrorClass) { - return getCapability()?.possiblyInnerType - } - return buildPossiblyInnerType(constructor.declarationDescriptor as? ClassDescriptor, 0) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt index 6081fa9594b..5f60e70fa20 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt @@ -34,7 +34,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.ErrorUtils.UninferredParameterTypeConstructor import org.jetbrains.kotlin.types.TypeUtils.CANT_INFER_FUNCTION_PARAM_TYPE -import org.jetbrains.kotlin.types.error.MissingDependencyErrorClass import org.jetbrains.kotlin.types.typeUtil.builtIns import java.util.* @@ -116,9 +115,6 @@ internal class DescriptorRendererImpl( private fun renderFqName(pathSegments: List) = escape(org.jetbrains.kotlin.renderer.renderFqName(pathSegments)) override fun renderClassifierName(klass: ClassifierDescriptor): String { - if (klass is MissingDependencyErrorClass) { - return klass.fullFqName.asString() - } if (ErrorUtils.isError(klass)) { return klass.typeConstructor.toString() } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeCapabilities.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeCapabilities.kt index 1c962ed17b9..8a2af3cb9b7 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeCapabilities.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeCapabilities.kt @@ -16,8 +16,6 @@ package org.jetbrains.kotlin.types -import org.jetbrains.kotlin.descriptors.PossiblyInnerType - interface TypeCapability interface TypeCapabilities { @@ -35,6 +33,7 @@ class CompositeTypeCapabilities(private val first: TypeCapabilities, private val class SingletonTypeCapabilities(private val clazz: Class<*>, private val typeCapability: TypeCapability) : TypeCapabilities { override fun getCapability(capabilityClass: Class): T? { + @Suppress("UNCHECKED_CAST") if (capabilityClass == clazz) return typeCapability as T return null } @@ -64,9 +63,6 @@ interface Specificity : TypeCapability { fun KotlinType.getSpecificityRelationTo(otherType: KotlinType) = this.getCapability(Specificity::class.java)?.getSpecificityRelationTo(otherType) ?: Specificity.Relation.DONT_KNOW -fun oneMoreSpecificThanAnother(a: KotlinType, b: KotlinType) = - a.getSpecificityRelationTo(b) != Specificity.Relation.DONT_KNOW || b.getSpecificityRelationTo(a) != Specificity.Relation.DONT_KNOW - // To facilitate laziness, any KotlinType implementation may inherit from this trait, // even if it turns out that the type an instance represents is not actually a type variable // (i.e. it is not derived from a type parameter), see isTypeVariable @@ -106,7 +102,3 @@ interface CustomSubstitutionCapability : TypeCapability { val substitution: TypeSubstitution? val substitutionToComposeWith: TypeSubstitution? } - -interface PossiblyInnerTypeCapability : TypeCapability { - val possiblyInnerType: PossiblyInnerType? -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/MissingDependencyErrorClass.kt b/core/descriptors/src/org/jetbrains/kotlin/types/error/MissingDependencyErrorClass.kt deleted file mode 100644 index 7a7470178b9..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/types/error/MissingDependencyErrorClass.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.types.error - -import org.jetbrains.kotlin.name.FqName - -// marker for DescriptorRenderer to treat specially in decompiler mode -interface MissingDependencyErrorClass { - val fullFqName: FqName -} diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedType.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedType.kt index 9f7676b7cd9..359bd24f08b 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedType.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedType.kt @@ -16,13 +16,13 @@ package org.jetbrains.kotlin.serialization.deserialization -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.PossiblyInnerType import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotationsWithPossibleTargets -import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.AbstractLazyType +import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.LazyType import org.jetbrains.kotlin.utils.toReadOnlyList class DeserializedType( @@ -30,21 +30,17 @@ class DeserializedType( private val typeProto: ProtoBuf.Type, private val additionalAnnotations: Annotations = Annotations.EMPTY ) : AbstractLazyType(c.storageManager), LazyType { - private val typeDeserializer: TypeDeserializer get() = c.typeDeserializer + override fun computeTypeConstructor() = c.typeDeserializer.typeConstructor(typeProto) - override fun computeTypeConstructor() = typeDeserializer.typeConstructor(typeProto) - - override fun computeArguments() = typeProto.collectAllArguments().deserialize() + override fun computeArguments() = + typeProto.collectAllArguments().mapIndexed { + index, proto -> + c.typeDeserializer.typeArgument(constructor.parameters.getOrNull(index), proto) + }.toReadOnlyList() private fun ProtoBuf.Type.collectAllArguments(): List = argumentList + outerType(c.typeTable)?.collectAllArguments().orEmpty() - private fun List.deserialize(): List = - mapIndexed { - index, proto -> - typeDeserializer.typeArgument(constructor.parameters.getOrNull(index), proto) - }.toReadOnlyList() - private val annotations = DeserializedAnnotationsWithPossibleTargets(c.storageManager) { c.components.annotationAndConstantLoader .loadTypeAnnotations(typeProto, c.nameResolver) @@ -62,30 +58,7 @@ class DeserializedType( override fun getCapabilities() = typeCapabilities() - private val typeCapabilities = c.storageManager.createLazyValue { computeCapabilities() } - - private fun computeCapabilities(): TypeCapabilities { - val capabilities = c.components.typeCapabilitiesLoader.loadCapabilities(typeProto) - - return computePossiblyInnerType()?.let { it: PossiblyInnerType -> - CompositeTypeCapabilities( - SingletonTypeCapabilities( - PossiblyInnerTypeCapability::class.java, - PossiblyInnerTypeCapabilityImpl(it)), - capabilities) - } ?: capabilities + private val typeCapabilities = c.storageManager.createLazyValue { + c.components.typeCapabilitiesLoader.loadCapabilities(typeProto) } - - private fun computePossiblyInnerType(): PossiblyInnerType? { - if (!typeProto.hasClassName()) return null - - val outerType = typeProto.outerType(c.typeTable)?.let { DeserializedType(c, it).computePossiblyInnerType() } - - return PossiblyInnerType( - constructor.declarationDescriptor as ClassDescriptor, - typeProto.argumentList.deserialize(), - outerType) - } - - private class PossiblyInnerTypeCapabilityImpl(override val possiblyInnerType: PossiblyInnerType?) : PossiblyInnerTypeCapability } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextFactory.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextFactory.kt index 934a58f3980..36a585c5802 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextFactory.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextFactory.kt @@ -26,7 +26,6 @@ import org.jetbrains.kotlin.renderer.ExcludedTypeAnnotations import org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike import org.jetbrains.kotlin.resolve.descriptorUtil.secondaryConstructors -import org.jetbrains.kotlin.types.error.MissingDependencyErrorClass import org.jetbrains.kotlin.types.isFlexible import java.util.* @@ -75,9 +74,6 @@ fun buildDecompiledText( } fun appendDescriptor(descriptor: DeclarationDescriptor, indent: String, lastEnumEntry: Boolean? = null) { - if (descriptor is MissingDependencyErrorClass) { - throw IllegalStateException("${descriptor.javaClass.simpleName} cannot be rendered. FqName: ${descriptor.fullFqName}") - } val startOffset = builder.length if (isEnumEntry(descriptor)) { for (annotation in descriptor.annotations) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DeserializerForDecompilerBase.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DeserializerForDecompilerBase.kt index 16eac0c093e..8a991fc94b0 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DeserializerForDecompilerBase.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DeserializerForDecompilerBase.kt @@ -64,14 +64,7 @@ abstract class DeserializerForDecompilerBase( init { moduleDescriptor.initialize(packageFragmentProvider) - val moduleContainingMissingDependencies = createDummyModule("module containing missing dependencies for decompiled sources") - moduleContainingMissingDependencies.setDependencies(moduleContainingMissingDependencies) - moduleContainingMissingDependencies.initialize( - PackageFragmentProviderForMissingDependencies(moduleContainingMissingDependencies) - ) - moduleDescriptor.setDependencies( - moduleDescriptor, targetPlatform.builtIns.builtInsModule, moduleContainingMissingDependencies - ) + moduleDescriptor.setDependencies(moduleDescriptor, targetPlatform.builtIns.builtInsModule) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/missingDependencies.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/missingDependencies.kt deleted file mode 100644 index dcda4c13fc9..00000000000 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/missingDependencies.kt +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.decompiler.textBuilder - -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl -import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl -import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl -import org.jetbrains.kotlin.incremental.components.LookupLocation -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns -import org.jetbrains.kotlin.resolve.scopes.MemberScope -import org.jetbrains.kotlin.resolve.scopes.MemberScopeImpl -import org.jetbrains.kotlin.types.ErrorUtils.createErrorType -import org.jetbrains.kotlin.types.TypeProjection -import org.jetbrains.kotlin.types.TypeSubstitution -import org.jetbrains.kotlin.types.TypeSubstitutor -import org.jetbrains.kotlin.types.error.MissingDependencyErrorClass -import org.jetbrains.kotlin.utils.Printer - -private class PackageFragmentWithMissingDependencies(fqName: FqName, moduleDescriptor: ModuleDescriptor) : - PackageFragmentDescriptorImpl(moduleDescriptor, fqName) { - override fun getMemberScope(): MemberScope { - return ScopeWithMissingDependencies(fqName, this) - } -} - -private class ScopeWithMissingDependencies(val fqName: FqName, val ownerDescriptor: DeclarationDescriptor) : MemberScopeImpl() { - - override fun printScopeStructure(p: Printer) { - p.println("Special scope for decompiler, containing class with any name") - } - - override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? { - return MissingDependencyErrorClassDescriptor(ownerDescriptor, fqName.child(name)) - } -} - -internal class PackageFragmentProviderForMissingDependencies(val moduleDescriptor: ModuleDescriptor) : PackageFragmentProvider { - override fun getPackageFragments(fqName: FqName): List { - return listOf(PackageFragmentWithMissingDependencies(fqName, moduleDescriptor)) - } - override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection { - throw UnsupportedOperationException("This method is not supposed to be called.") - } -} - -private class MissingDependencyErrorClassDescriptor( - containing: DeclarationDescriptor, - override val fullFqName: FqName -) : MissingDependencyErrorClass, ClassDescriptorImpl( - containing, fullFqName.shortName(), Modality.OPEN, ClassKind.CLASS, listOf(containing.builtIns.nullableAnyType), - SourceElement.NO_SOURCE -) { - - private val scope = ScopeWithMissingDependencies(fullFqName, this) - - init { - val emptyConstructor = ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true, SourceElement.NO_SOURCE) - emptyConstructor.initialize(listOf(), Visibilities.DEFAULT_VISIBILITY) - emptyConstructor.returnType = createErrorType("") - initialize(MemberScope.Empty, setOf(emptyConstructor), emptyConstructor) - } - - override fun substitute(substitutor: TypeSubstitutor) = this - - override fun getUnsubstitutedMemberScope() = scope - - override fun getMemberScope(typeArguments: List) = scope - override fun getMemberScope(typeSubstitution: TypeSubstitution) = scope -}