Parse some builtin annotations as modifiers
But still resolve them as annotations. Mostly it's needed as begin of migration path, one day they become modifiers anyway Some tests are dropped because they supposed that `annotation` should have parameter
This commit is contained in:
@@ -247,7 +247,7 @@ public class KotlinBuiltIns {
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@NotNull
|
||||
private ClassDescriptor getAnnotationClassByName(@NotNull Name simpleName) {
|
||||
public ClassDescriptor getAnnotationClassByName(@NotNull Name simpleName) {
|
||||
ClassifierDescriptor classifier = annotationPackageFragment.getMemberScope().getClassifier(simpleName,
|
||||
NoLookupLocation.FROM_BUILTINS);
|
||||
assert classifier instanceof ClassDescriptor : "Must be a class descriptor " + simpleName + ", but was " +
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.kotlin.name.FqName
|
||||
|
||||
// Please synchronize this set with JetTokens.ANNOTATION_MODIFIERS_KEYWORDS_ARRAY
|
||||
public val ANNOTATION_MODIFIERS_FQ_NAMES: Set<FqName> =
|
||||
arrayOf("data", "inline", "noinline", "tailrec", "external", "annotation.annotation").map { FqName("kotlin.$it") }.toSet()
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.renderer
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.ANNOTATION_MODIFIERS_FQ_NAMES
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
@@ -30,6 +31,7 @@ import org.jetbrains.kotlin.resolve.constants.AnnotationValue
|
||||
import org.jetbrains.kotlin.resolve.constants.ArrayValue
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.resolve.constants.KClassValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.ErrorUtils.UninferredParameterTypeConstructor
|
||||
@@ -342,7 +344,12 @@ internal class DescriptorRendererImpl(
|
||||
var hasTargetedAnnotations = false
|
||||
|
||||
val annotationsBuilder = StringBuilder {
|
||||
for ((annotation, target) in annotated.getAnnotations().getAllAnnotations()) {
|
||||
// Sort is needed just to fix some order when annotations resolved from modifiers
|
||||
// See AnnotationResolver.resolveAndAppendAnnotationsFromModifiers for clarification
|
||||
// This hack can be removed when modifiers will be resolved without annotations
|
||||
|
||||
val sortedAnnotations = annotated.getAnnotations().getAllAnnotations().sortedBy { p -> p.annotation.isBuiltinModifier() }
|
||||
for ((annotation, target) in sortedAnnotations) {
|
||||
val annotationClass = annotation.getType().getConstructor().getDeclarationDescriptor() as ClassDescriptor
|
||||
|
||||
if (!excluded.contains(DescriptorUtils.getFqNameSafe(annotationClass))) {
|
||||
@@ -367,6 +374,9 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
}
|
||||
|
||||
private fun AnnotationDescriptor.isBuiltinModifier()
|
||||
= (type.constructor.declarationDescriptor as ClassDescriptor).fqNameSafe in ANNOTATION_MODIFIERS_FQ_NAMES
|
||||
|
||||
override fun renderAnnotation(annotation: AnnotationDescriptor, target: AnnotationUseSiteTarget?): String {
|
||||
return StringBuilder {
|
||||
if (target != null) {
|
||||
|
||||
Reference in New Issue
Block a user