Create special type for missing dependencies when resolving annotations

#KT-10748 Fixed
This commit is contained in:
Denis Zharkov
2016-01-22 14:25:14 +03:00
parent 76f60294a8
commit d87b13931d
11 changed files with 136 additions and 10 deletions
@@ -16,9 +16,11 @@
package org.jetbrains.kotlin.load.java.lazy.descriptors
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.isSpecialAnnotation
@@ -34,6 +36,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.resolve.constants.ConstantValueFactory
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
@@ -56,7 +59,7 @@ class LazyJavaAnnotationDescriptor(
val fqName = fqName() ?: return@createLazyValue ErrorUtils.createErrorType("No fqName: $javaAnnotation")
val annotationClass = JavaToKotlinClassMap.INSTANCE.mapJavaToKotlin(fqName)
?: javaAnnotation.resolve()?.let { javaClass -> c.components.moduleClassResolver.resolveClass(javaClass) }
annotationClass?.getDefaultType() ?: ErrorUtils.createErrorType(fqName.asString())
annotationClass?.defaultType ?: createTypeForMissingDependencies(fqName)
}
private val source = c.components.sourceElementFactory.source(javaAnnotation)
@@ -156,4 +159,16 @@ class LazyJavaAnnotationDescriptor(
override fun toString(): String {
return DescriptorRenderer.FQ_NAMES_IN_TYPES.renderAnnotation(this)
}
private fun createTypeForMissingDependencies(fqName: FqName) =
ErrorUtils.createErrorTypeWithCustomConstructor(
"[Missing annotation class: $fqName]",
ClassDescriptorImpl(
EmptyPackageFragmentDescriptor(c.module, fqName.parent()), fqName.shortName(), Modality.FINAL,
ClassKind.ANNOTATION_CLASS, listOf(c.module.builtIns.anyType), SourceElement.NO_SOURCE,
"[Missing annotation class: $fqName]"
).apply {
initialize(MemberScope.Empty, emptySet(), null)
}.typeConstructor
)
}
@@ -50,13 +50,25 @@ public class ClassDescriptorImpl extends ClassDescriptorBase {
@NotNull ClassKind kind,
@NotNull Collection<KotlinType> supertypes,
@NotNull SourceElement source
) {
this(containingDeclaration, name, modality, kind, supertypes, source, name.asString());
}
public ClassDescriptorImpl(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull Name name,
@NotNull Modality modality,
@NotNull ClassKind kind,
@NotNull Collection<KotlinType> supertypes,
@NotNull SourceElement source,
@NotNull String debugName
) {
super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name, source);
this.modality = modality;
this.kind = kind;
this.typeConstructor = TypeConstructorImpl.createForClass(this, Annotations.Companion.getEMPTY(), false, getName().asString(),
Collections.<TypeParameterDescriptor>emptyList(), supertypes);
this.typeConstructor = TypeConstructorImpl.createForClass(this, Annotations.Companion.getEMPTY(), false, debugName,
Collections.<TypeParameterDescriptor>emptyList(), supertypes);
}
public final void initialize(
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2016 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.descriptors.impl
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.scopes.MemberScope
class EmptyPackageFragmentDescriptor(module: ModuleDescriptor, fqName: FqName) : PackageFragmentDescriptorImpl(module, fqName) {
override fun getMemberScope() = MemberScope.Empty
}