From b7ead75947afcb034a8a27074cea856f7b71808b Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 30 May 2017 15:43:24 +0300 Subject: [PATCH] Minor. Move BinaryJavaModifierListOwner -> MapBasedJavaAnnotationOwner --- .../impl/classFiles/BinaryJavaClass.kt | 2 +- .../java/structure/impl/classFiles/Methods.kt | 2 +- .../java/structure/impl/classFiles/Other.kt | 4 ++-- .../structure/impl/classFiles/commonMixins.kt | 17 ++--------------- .../kotlin/load/java/structure/javaElements.kt | 12 +++++++++++- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt index ef4fbce7dcf..e945b2a3fc4 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt @@ -38,7 +38,7 @@ class BinaryJavaClass( override var access: Int = 0, override val outerClass: JavaClass?, classContent: ByteArray? = null -) : ClassVisitor(ASM_API_VERSION_FOR_CLASS_READING), VirtualFileBoundJavaClass, BinaryJavaModifierListOwner, BinaryJavaAnnotationOwner { +) : ClassVisitor(ASM_API_VERSION_FOR_CLASS_READING), VirtualFileBoundJavaClass, BinaryJavaModifierListOwner, MapBasedJavaAnnotationOwner { lateinit var myInternalName: String override val annotations: MutableCollection = mutableListOf() diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Methods.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Methods.kt index c0cdff99966..cc2065e0040 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Methods.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Methods.kt @@ -33,7 +33,7 @@ abstract class BinaryJavaMethodBase( val valueParameters: List, val typeParameters: List, override val name: Name -) : JavaMember, BinaryJavaAnnotationOwner, BinaryJavaModifierListOwner { +) : JavaMember, MapBasedJavaAnnotationOwner, BinaryJavaModifierListOwner { override val annotationsByFqName by buildLazyValueForMap() override val annotations: Collection = mutableListOf() diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Other.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Other.kt index 713d630e95b..83e92c78438 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Other.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Other.kt @@ -30,7 +30,7 @@ class BinaryJavaField( override val isEnumEntry: Boolean, override val type: JavaType, override val initializerValue: Any? -) : JavaField, BinaryJavaAnnotationOwner, BinaryJavaModifierListOwner { +) : JavaField, MapBasedJavaAnnotationOwner, BinaryJavaModifierListOwner { override val annotations: MutableCollection = ContainerUtil.newSmartList() override val annotationsByFqName by buildLazyValueForMap() @@ -53,7 +53,7 @@ class BinaryJavaValueParameter( override val name: Name?, override val type: JavaType, override val isVararg: Boolean -) : JavaValueParameter, BinaryJavaAnnotationOwner { +) : JavaValueParameter, MapBasedJavaAnnotationOwner { override val annotations: MutableCollection = ContainerUtil.newSmartList() override val annotationsByFqName by buildLazyValueForMap() } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/commonMixins.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/commonMixins.kt index b5e8baa1d7f..53818be036a 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/commonMixins.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/commonMixins.kt @@ -19,22 +19,13 @@ package org.jetbrains.kotlin.load.java.structure.impl.classFiles import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.load.java.JavaVisibilities -import org.jetbrains.kotlin.load.java.structure.JavaAnnotation -import org.jetbrains.kotlin.load.java.structure.JavaAnnotationOwner import org.jetbrains.kotlin.load.java.structure.JavaModifierListOwner -import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.load.java.structure.MapBasedJavaAnnotationOwner import org.jetbrains.org.objectweb.asm.Opcodes internal val ASM_API_VERSION_FOR_CLASS_READING = Opcodes.ASM5 -internal interface BinaryJavaAnnotationOwner : JavaAnnotationOwner { - val annotationsByFqName: Map - override fun findAnnotation(fqName: FqName) = annotationsByFqName[fqName] - override val isDeprecatedInJavaDoc: Boolean - get() = false -} - -internal interface BinaryJavaModifierListOwner : JavaModifierListOwner, BinaryJavaAnnotationOwner { +internal interface BinaryJavaModifierListOwner : JavaModifierListOwner, MapBasedJavaAnnotationOwner { val access: Int fun isSet(flag: Int) = access.isSet(flag) @@ -54,8 +45,4 @@ internal interface BinaryJavaModifierListOwner : JavaModifierListOwner, BinaryJa override val isDeprecatedInJavaDoc get() = isSet(Opcodes.ACC_DEPRECATED) } -internal fun JavaAnnotationOwner.buildLazyValueForMap() = lazy { - annotations.filter { it.classId != null }.associateBy({ it.classId!!.asSingleFqName() }, { it }) -} - internal fun Int.isSet(flag: Int) = this and flag != 0 diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/structure/javaElements.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/structure/javaElements.kt index bfd16f90fed..66acc744689 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/structure/javaElements.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/structure/javaElements.kt @@ -52,7 +52,17 @@ interface JavaAnnotation : JavaElement { fun resolve(): JavaClass? } -interface JavaPackage : JavaElement { +interface MapBasedJavaAnnotationOwner : JavaAnnotationOwner { + val annotationsByFqName: Map + override fun findAnnotation(fqName: FqName) = annotationsByFqName[fqName] + override val isDeprecatedInJavaDoc: Boolean + get() = false +} + +fun JavaAnnotationOwner.buildLazyValueForMap() = lazy { + annotations.associateBy { it.classId?.asSingleFqName() } +} + val fqName: FqName val subPackages: Collection