Drop MissingDependencyErrorClass and related code

No longer needed because of the proper support for missing classes in
deserialization (see NotFoundClasses.kt)
This commit is contained in:
Alexander Udalov
2016-03-15 17:33:08 +03:00
parent db5e00bcc0
commit 873cf439de
8 changed files with 16 additions and 180 deletions
@@ -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<TypeParameterDescriptor> {
@@ -66,10 +67,6 @@ class PossiblyInnerType(
}
fun KotlinType.buildPossiblyInnerType(): PossiblyInnerType? {
if (constructor.declarationDescriptor is MissingDependencyErrorClass) {
return getCapability<PossiblyInnerTypeCapability>()?.possiblyInnerType
}
return buildPossiblyInnerType(constructor.declarationDescriptor as? ClassDescriptor, 0)
}
@@ -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<Name>) = 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()
}
@@ -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 <T : TypeCapability> getCapability(capabilityClass: Class<T>): 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?
}
@@ -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
}
@@ -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<ProtoBuf.Type.Argument> =
argumentList + outerType(c.typeTable)?.collectAllArguments().orEmpty()
private fun List<ProtoBuf.Type.Argument>.deserialize(): List<TypeProjection> =
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
}
@@ -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) {
@@ -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)
}
}
@@ -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<PackageFragmentDescriptor> {
return listOf(PackageFragmentWithMissingDependencies(fqName, moduleDescriptor))
}
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName> {
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("<ERROR RETURN TYPE>")
initialize(MemberScope.Empty, setOf(emptyConstructor), emptyConstructor)
}
override fun substitute(substitutor: TypeSubstitutor) = this
override fun getUnsubstitutedMemberScope() = scope
override fun getMemberScope(typeArguments: List<TypeProjection?>) = scope
override fun getMemberScope(typeSubstitution: TypeSubstitution) = scope
}