From fd8a71879741d53a0e336a11f434c7d190c69aa6 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 21 Oct 2015 21:17:42 +0300 Subject: [PATCH] Get rid of duplicating annotations FQ names usages E.g. JETBRAINS_NOT_NULL_ANNOTATION were used both in NULLABLE_ANNOTATIONS and for ANNOTATIONS_COPIED_TO_TYPES --- .../AbstractJvmRuntimeDescriptorLoaderTest.kt | 3 +- .../kotlin/load/java/JvmAnnotationNames.java | 9 ---- .../kotlin/load/java/JvmAnnotationNames.kt | 41 +++++++++++++++++++ .../java/lazy/types/LazyJavaTypeResolver.kt | 1 + .../java/typeEnhancement/typeQualifiers.kt | 18 +------- .../stubBuilder/TypeClsStubBuilder.kt | 4 +- 6 files changed, 47 insertions(+), 29 deletions(-) create mode 100644 core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.kt diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt index 48b8785cefd..7eaea8a4b33 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.jvm.compiler.ExpectedLoadErrorsUtil import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil +import org.jetbrains.kotlin.load.java.ANNOTATIONS_COPIED_TO_TYPES import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KOTLIN_LOCAL_CLASS import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor @@ -65,7 +66,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() { withDefinedIn = false excludedAnnotationClasses = (listOf( FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME) - ) + JvmAnnotationNames.ANNOTATIONS_COPIED_TO_TYPES).toSet() + ) + ANNOTATIONS_COPIED_TO_TYPES).toSet() overrideRenderingPolicy = OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE parameterNameRenderingPolicy = ParameterNameRenderingPolicy.NONE includePropertyConstant = false diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java index 1dc53008c0b..e26707fd59a 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java @@ -62,15 +62,6 @@ public final class JvmAnnotationNames { public static final FqName ENHANCED_NULLABILITY_ANNOTATION = new FqName("kotlin.jvm.internal.EnhancedNullability"); public static final FqName ENHANCED_MUTABILITY_ANNOTATION = new FqName("kotlin.jvm.internal.EnhancedMutability"); - // When these annotations appear on a declaration, they are copied to the _type_ of the declaration, becoming type annotations - // See also DescriptorRendererOptions#excludedTypeAnnotationClasses - public static final Set ANNOTATIONS_COPIED_TO_TYPES = SetsKt.setOf( - JETBRAINS_READONLY_ANNOTATION, - JETBRAINS_MUTABLE_ANNOTATION, - JETBRAINS_NOT_NULL_ANNOTATION, - JETBRAINS_NULLABLE_ANNOTATION - ); - private static final Set SPECIAL_ANNOTATIONS = new HashSet(); private static final Set NULLABILITY_ANNOTATIONS = new HashSet(); private static final Set SPECIAL_META_ANNOTATIONS = new HashSet(); diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.kt new file mode 100644 index 00000000000..5e2edae26a0 --- /dev/null +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.kt @@ -0,0 +1,41 @@ +/* + * 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.load.java + +import org.jetbrains.kotlin.name.FqName + +val NULLABLE_ANNOTATIONS = listOf( + JvmAnnotationNames.JETBRAINS_NULLABLE_ANNOTATION +) + +val NOT_NULL_ANNOTATIONS = listOf( + JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION +) + +val READ_ONLY_ANNOTATIONS = listOf( + JvmAnnotationNames.JETBRAINS_READONLY_ANNOTATION +) + +val MUTABLE_ANNOTATIONS = listOf( + JvmAnnotationNames.JETBRAINS_MUTABLE_ANNOTATION +) + +// When these annotations appear on a declaration, they are copied to the _type_ of the declaration, becoming type annotations +// See also DescriptorRendererOptions#excludedTypeAnnotationClasses +val ANNOTATIONS_COPIED_TO_TYPES: Set = listOf( + NULLABLE_ANNOTATIONS, NOT_NULL_ANNOTATIONS, READ_ONLY_ANNOTATIONS, MUTABLE_ANNOTATIONS +).flatMap { it }.toSet() diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt index 6a2bccdfce0..c7686959cc2 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.CompositeAnnotations import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations +import org.jetbrains.kotlin.load.java.ANNOTATIONS_COPIED_TO_TYPES import org.jetbrains.kotlin.load.java.JvmAnnotationNames.* import org.jetbrains.kotlin.load.java.components.TypeUsage import org.jetbrains.kotlin.load.java.components.TypeUsage.* diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeQualifiers.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeQualifiers.kt index 32508c68a7d..41144882688 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeQualifiers.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeQualifiers.kt @@ -17,7 +17,7 @@ package org.jetbrains.kotlin.load.java.typeEnhancement import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.load.java.JvmAnnotationNames +import org.jetbrains.kotlin.load.java.* import org.jetbrains.kotlin.load.java.typeEnhancement.MutabilityQualifier.MUTABLE import org.jetbrains.kotlin.load.java.typeEnhancement.MutabilityQualifier.READ_ONLY import org.jetbrains.kotlin.load.java.typeEnhancement.NullabilityQualifier.NOT_NULL @@ -35,27 +35,11 @@ enum class NullabilityQualifier { NOT_NULL } -private val NULLABLE_ANNOTATIONS = listOf( - JvmAnnotationNames.JETBRAINS_NULLABLE_ANNOTATION -) - -private val NOT_NULL_ANNOTATIONS = listOf( - JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION -) - enum class MutabilityQualifier { READ_ONLY, MUTABLE } -private val READ_ONLY_ANNOTATIONS = listOf( - JvmAnnotationNames.JETBRAINS_READONLY_ANNOTATION -) - -private val MUTABLE_ANNOTATIONS = listOf( - JvmAnnotationNames.JETBRAINS_MUTABLE_ANNOTATION -) - class JavaTypeQualifiers( val nullability: NullabilityQualifier?, val mutability: MutabilityQualifier? diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt index 9b9ed08c7b7..39f07e88072 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt @@ -22,7 +22,7 @@ import com.intellij.psi.stubs.StubElement import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtTokens -import org.jetbrains.kotlin.load.java.JvmAnnotationNames +import org.jetbrains.kotlin.load.java.ANNOTATIONS_COPIED_TO_TYPES import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name @@ -47,7 +47,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) { val annotations = c.components.annotationLoader.loadTypeAnnotations(type, c.nameResolver).filterNot { val isTopLevelClass = !it.isNestedClass - isTopLevelClass && it.asSingleFqName() in JvmAnnotationNames.ANNOTATIONS_COPIED_TO_TYPES + isTopLevelClass && it.asSingleFqName() in ANNOTATIONS_COPIED_TO_TYPES } val effectiveParent =