Refactoring. Convert Annotated to kotlin.

This commit is contained in:
Stanislav Erokhin
2016-05-19 19:00:51 +03:00
parent 450ea78b1d
commit 74bddcfb70
22 changed files with 47 additions and 78 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* 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.
@@ -26,14 +26,10 @@ interface WrappedAnnotated : Annotated {
val originalAnnotated: Annotated
}
class AnnotatedWithFakeAnnotations(override val originalAnnotated: Annotated, private val actual: Annotations) : WrappedAnnotated {
override fun getAnnotations() = actual
}
class AnnotatedWithFakeAnnotations(override val originalAnnotated: Annotated, override val annotations: Annotations) : WrappedAnnotated
class AnnotatedWithOnlyTargetedAnnotations(original: Annotated) : Annotated {
private val annotations: Annotations = UseSiteTargetedAnnotations(original.annotations)
override fun getAnnotations() = annotations
override val annotations: Annotations = UseSiteTargetedAnnotations(original.annotations)
private class UseSiteTargetedAnnotations(private val additionalAnnotations: Annotations) : Annotations {
override fun isEmpty() = true
@@ -179,7 +179,7 @@ class FunctionDescriptorResolver(
functionDescriptor.isExternal = function.hasModifier(KtTokens.EXTERNAL_KEYWORD)
functionDescriptor.isInline = function.hasModifier(KtTokens.INLINE_KEYWORD)
functionDescriptor.isTailrec = function.hasModifier(KtTokens.TAILREC_KEYWORD)
receiverType?.let { ForceResolveUtil.forceResolveAllContents(it.getAnnotations()) }
receiverType?.let { ForceResolveUtil.forceResolveAllContents(it.annotations) }
for (valueParameterDescriptor in valueParameterDescriptors) {
ForceResolveUtil.forceResolveAllContents(valueParameterDescriptor.type.annotations)
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* 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.
@@ -202,7 +202,7 @@ open class FileScopeProviderImpl(
override fun getSource() = sourceElement
override fun getOriginal() = this
override fun getAnnotations() = Annotations.EMPTY
override val annotations: Annotations get() = Annotations.EMPTY
override fun substitute(substitutor: TypeSubstitutor) = this
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D): R {
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAllTo
import org.jetbrains.kotlin.codegen.GenerationUtils
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.jvm.compiler.ExpectedLoadErrorsUtil
import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil
@@ -214,8 +215,9 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
override fun getOriginal() = throw UnsupportedOperationException()
override fun substitute(substitutor: TypeSubstitutor) = throw UnsupportedOperationException()
override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>?) = throw UnsupportedOperationException()
override fun getAnnotations() = throw UnsupportedOperationException()
override fun getName() = throw UnsupportedOperationException()
override val annotations: Annotations
get() = throw UnsupportedOperationException()
override val fragments: Nothing
get() = throw UnsupportedOperationException()
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* 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.
@@ -26,7 +26,10 @@ import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.load.java.components.JavaResolverCache
import org.jetbrains.kotlin.load.java.components.TypeUsage
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
import org.jetbrains.kotlin.load.java.lazy.*
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
import org.jetbrains.kotlin.load.java.lazy.child
import org.jetbrains.kotlin.load.java.lazy.replaceComponents
import org.jetbrains.kotlin.load.java.lazy.resolveAnnotations
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
import org.jetbrains.kotlin.load.java.structure.JavaClass
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType
@@ -40,6 +43,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import org.jetbrains.kotlin.resolve.scopes.InnerClassesScopeWrapper
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.serialization.deserialization.NotFoundClasses
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.toReadOnlyList
@@ -106,8 +110,7 @@ class LazyJavaClassDescriptor(
override fun getConstructors() = unsubstitutedMemberScope.constructors()
private val annotations = c.storageManager.createLazyValue { c.resolveAnnotations(jClass) }
override fun getAnnotations() = annotations()
override val annotations by c.storageManager.createLazyValue { c.resolveAnnotations(jClass) }
private val functionTypeForSamInterface = c.storageManager.createNullableLazyValue {
c.components.samConversionResolver.resolveFunctionTypeIfSamInterface(this)
@@ -200,7 +203,7 @@ class LazyJavaClassDescriptor(
private fun getPurelyImplementsFqNameFromAnnotation(): FqName? {
val annotation =
this@LazyJavaClassDescriptor.getAnnotations().findAnnotation(JvmAnnotationNames.PURELY_IMPLEMENTS_ANNOTATION)
this@LazyJavaClassDescriptor.annotations.findAnnotation(JvmAnnotationNames.PURELY_IMPLEMENTS_ANNOTATION)
?: return null
val fqNameString = (annotation.allValueArguments.values.singleOrNull() as? StringValue)?.value ?: return null
@@ -212,7 +215,7 @@ class LazyJavaClassDescriptor(
override val supertypeLoopChecker: SupertypeLoopChecker
get() = c.components.supertypeLoopChecker
override fun getAnnotations() = Annotations.EMPTY
override val annotations: Annotations get() = Annotations.EMPTY
override fun isFinal(): Boolean = isFinalClass
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* 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.
@@ -243,7 +243,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
val propertyDescriptor = createPropertyDescriptor(field)
propertyDescriptor.initialize(null, null)
val propertyType = getPropertyType(field, propertyDescriptor.getAnnotations())
val propertyType = getPropertyType(field, propertyDescriptor.annotations)
propertyDescriptor.setType(propertyType, listOf(), getDispatchReceiverParameter(), null as KotlinType?)
@@ -42,9 +42,7 @@ class LazyJavaTypeParameterDescriptor(
index,
SourceElement.NO_SOURCE, c.components.supertypeLoopChecker
) {
private val annotations = LazyJavaAnnotations(c, javaTypeParameter)
override fun getAnnotations() = annotations
override val annotations = LazyJavaAnnotations(c, javaTypeParameter)
override fun resolveUpperBounds(): List<KotlinType> {
val bounds = javaTypeParameter.upperBounds
@@ -98,7 +98,7 @@ class LazyJavaTypeResolver(
private val javaType: JavaClassifierType,
private val attr: JavaTypeAttributes
) : AbstractLazyType(c.storageManager) {
private val annotations = CompositeAnnotations(listOf(LazyJavaAnnotations(c, javaType), attr.typeAnnotations))
override val annotations = CompositeAnnotations(listOf(LazyJavaAnnotations(c, javaType), attr.typeAnnotations))
private val classifier = c.storageManager.createNullableLazyValue { javaType.classifier }
@@ -278,8 +278,6 @@ class LazyJavaTypeResolver(
}
override val isMarkedNullable: Boolean get() = nullable()
override fun getAnnotations() = annotations
}
object FlexibleJavaClassifierTypeFactory : FlexibleTypeFactory {
@@ -116,7 +116,7 @@ private fun KotlinType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
if (!wereChanges) return Result(this, subtreeSize, wereChanges = false)
val newAnnotations = listOf(
getAnnotations(),
annotations,
enhancedMutabilityAnnotations,
enhancedNullabilityAnnotations
).filterNotNull().compositeAnnotationsOrSingle()
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* 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.
@@ -101,7 +101,7 @@ class FunctionClassDescriptor(
override fun isCompanionObject() = false
override fun isInner() = false
override fun isData() = false
override fun getAnnotations() = Annotations.EMPTY
override val annotations: Annotations get() = Annotations.EMPTY
override fun getSource() = SourceElement.NO_SOURCE
override fun getDeclaredTypeParameters() = parameters
@@ -143,7 +143,7 @@ class FunctionClassDescriptor(
override fun getDeclarationDescriptor() = this@FunctionClassDescriptor
override fun isDenotable() = true
override fun isFinal() = false
override fun getAnnotations() = Annotations.EMPTY
override val annotations: Annotations get() = Annotations.EMPTY
override fun toString() = declarationDescriptor.toString()
@@ -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.descriptors.annotations;
import org.jetbrains.annotations.NotNull;
public interface Annotated {
@NotNull
Annotations getAnnotations();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* 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.
@@ -20,6 +20,10 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.DescriptorUtils
interface Annotated {
val annotations: Annotations
}
interface Annotations : Iterable<AnnotationDescriptor> {
fun isEmpty(): Boolean
@@ -49,7 +49,7 @@ class CapturedTypeConstructor(
override fun getDeclarationDescriptor() = null
override fun getAnnotations() = Annotations.EMPTY
override val annotations: Annotations get() = Annotations.EMPTY
override fun toString() = "CapturedTypeConstructor($typeProjection)"
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* 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.
@@ -55,7 +55,7 @@ class IntegerValueTypeConstructor(
override fun getDeclarationDescriptor() = null
override fun getAnnotations() = Annotations.EMPTY
override val annotations: Annotations get() = Annotations.EMPTY
fun getValue(): Long = value
@@ -54,7 +54,7 @@ abstract class AbstractLazyType(storageManager: StorageManager) : AbstractKotlin
override val isError: Boolean get() = constructor.declarationDescriptor?.let { d -> ErrorUtils.isError(d) } ?: false
override fun getAnnotations() = Annotations.EMPTY
override val annotations: Annotations get() = Annotations.EMPTY
override fun toString() = when {
!typeConstructor.isComputed() -> "[Not-computed]"
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* 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.
@@ -65,7 +65,7 @@ class FunctionPlaceholderTypeConstructor(
return errorTypeConstructor.declarationDescriptor
}
override fun getAnnotations(): Annotations {
override val annotations: Annotations get(): Annotations {
return errorTypeConstructor.annotations
}
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
open class KotlinTypeImpl
private constructor(
private val annotations: Annotations,
override val annotations: Annotations,
override val constructor: TypeConstructor,
override val isMarkedNullable: Boolean,
override val arguments: List<TypeProjection>,
@@ -76,7 +76,5 @@ private constructor(
}
}
override fun getAnnotations() = annotations
override val isError: Boolean get() = false
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* 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.
@@ -90,7 +90,7 @@ fun KotlinType.replaceAnnotations(newAnnotations: Annotations): KotlinType {
return object : DelegatingType() {
override fun getDelegate() = this@replaceAnnotations
override fun getAnnotations() = newAnnotations
override val annotations = newAnnotations
}
}
@@ -42,7 +42,7 @@ class DeserializedType(
private fun ProtoBuf.Type.collectAllArguments(): List<ProtoBuf.Type.Argument> =
argumentList + outerType(c.typeTable)?.collectAllArguments().orEmpty()
private val annotations = DeserializedAnnotationsWithPossibleTargets(c.storageManager) {
override val annotations = DeserializedAnnotationsWithPossibleTargets(c.storageManager) {
c.components.annotationAndConstantLoader
.loadTypeAnnotations(typeProto, c.nameResolver)
.map { AnnotationWithTarget(it, null) } + additionalAnnotations.getAllAnnotations()
@@ -56,8 +56,6 @@ class DeserializedType(
return descriptor != null && ErrorUtils.isError(descriptor)
}
override fun getAnnotations(): Annotations = annotations
override val capabilities: TypeCapabilities get() = typeCapabilities()
private val typeCapabilities = c.storageManager.createLazyValue {
@@ -86,7 +86,7 @@ class NotFoundClasses(private val storageManager: StorageManager, private val mo
override fun isCompanionObject() = false
override fun isData() = false
override fun getAnnotations() = Annotations.EMPTY
override val annotations: Annotations get() = Annotations.EMPTY
override fun getUnsubstitutedMemberScope() = MemberScope.Empty
override fun getStaticScope() = MemberScope.Empty
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* 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.
@@ -72,7 +72,7 @@ class DeserializedClassDescriptor(
(containingDeclaration as? DeserializedClassDescriptor)?.thisAsProtoContainer
)
private val annotations =
override val annotations =
if (!Flags.HAS_ANNOTATIONS.get(classProto.flags)) {
Annotations.EMPTY
}
@@ -94,8 +94,6 @@ class DeserializedClassDescriptor(
override fun isData() = Flags.IS_DATA.get(classProto.flags)
override fun getAnnotations() = annotations
override fun getUnsubstitutedMemberScope(): MemberScope = memberScope
override fun getStaticScope() = staticScope
@@ -178,7 +176,7 @@ class DeserializedClassDescriptor(
override fun getDeclarationDescriptor() = this@DeserializedClassDescriptor
override fun getAnnotations(): Annotations = Annotations.EMPTY // TODO
override val annotations: Annotations get() = Annotations.EMPTY // TODO
override fun toString() = getName().toString()
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* 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.
@@ -36,14 +36,12 @@ class DeserializedTypeParameterDescriptor(
c.storageManager, c.containingDeclaration, c.nameResolver.getName(proto.name),
Deserialization.variance(proto.variance), proto.reified, index, SourceElement.NO_SOURCE, SupertypeLoopChecker.EMPTY
) {
private val annotations = DeserializedAnnotationsWithPossibleTargets(c.storageManager) {
override val annotations = DeserializedAnnotationsWithPossibleTargets(c.storageManager) {
c.components.annotationAndConstantLoader
.loadTypeParameterAnnotations(proto, c.nameResolver)
.map { AnnotationWithTarget(it, null) }
}
override fun getAnnotations(): Annotations = annotations
override fun resolveUpperBounds(): List<KotlinType> {
val upperBounds = proto.upperBounds(c.typeTable)
if (upperBounds.isEmpty()) {