diff --git a/compiler/tests/org/jetbrains/kotlin/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java b/compiler/tests/org/jetbrains/kotlin/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java index 2e74b482b22..f0f0326368c 100644 --- a/compiler/tests/org/jetbrains/kotlin/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java +++ b/compiler/tests/org/jetbrains/kotlin/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java @@ -139,7 +139,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix } }, " "); - String expectedAnnotationWithTarget = "@" + AnnotationUseSiteTarget.FILE.getRenderName() + ":" + expectedAnnotation; + String expectedAnnotationWithTarget = "@" + AnnotationUseSiteTarget.FILE.getRenderName() + ":" + expectedAnnotation.substring(1); assertEquals(expectedAnnotationWithTarget, actualAnnotation); } diff --git a/compiler/tests/org/jetbrains/kotlin/resolve/annotation/AnnotationDescriptorResolveTest.java b/compiler/tests/org/jetbrains/kotlin/resolve/annotation/AnnotationDescriptorResolveTest.java index 58202a730fe..d6ee3fe83c8 100644 --- a/compiler/tests/org/jetbrains/kotlin/resolve/annotation/AnnotationDescriptorResolveTest.java +++ b/compiler/tests/org/jetbrains/kotlin/resolve/annotation/AnnotationDescriptorResolveTest.java @@ -21,73 +21,73 @@ import java.io.IOException; public class AnnotationDescriptorResolveTest extends AbstractAnnotationDescriptorResolveTest { public void testIntAnnotation() throws IOException { String content = getContent("AnnInt(1)"); - String expectedAnnotation = "AnnInt(a = 1)"; + String expectedAnnotation = "@AnnInt(a = 1)"; doTest(content, expectedAnnotation); } public void testStringAnnotation() throws IOException { String content = getContent("AnnString(\"test\")"); - String expectedAnnotation = "AnnString(a = \"test\")"; + String expectedAnnotation = "@AnnString(a = \"test\")"; doTest(content, expectedAnnotation); } public void testEnumAnnotation() throws IOException { String content = getContent("AnnEnum(MyEnum.A)"); - String expectedAnnotation = "AnnEnum(a = MyEnum.A)"; + String expectedAnnotation = "@AnnEnum(a = MyEnum.A)"; doTest(content, expectedAnnotation); } public void testQualifiedEnumAnnotation() throws IOException { String content = getContent("AnnEnum(MyEnum.A)"); - String expectedAnnotation = "AnnEnum(a = MyEnum.A)"; + String expectedAnnotation = "@AnnEnum(a = MyEnum.A)"; doTest(content, expectedAnnotation); } public void testUnqualifiedEnumAnnotation() throws IOException { String content = getContent("AnnEnum(A)"); - String expectedAnnotation = "AnnEnum(a = MyEnum.A)"; + String expectedAnnotation = "@AnnEnum(a = MyEnum.A)"; doTest(content, expectedAnnotation); } public void testIntArrayAnnotation() throws IOException { String content = getContent("AnnIntArray(intArray(1, 2))"); - String expectedAnnotation = "AnnIntArray(a = {1, 2})"; + String expectedAnnotation = "@AnnIntArray(a = {1, 2})"; doTest(content, expectedAnnotation); } public void testIntArrayVarargAnnotation() throws IOException { String content = getContent("AnnIntVararg(1, 2)"); - String expectedAnnotation = "AnnIntVararg(a = {1, 2})"; + String expectedAnnotation = "@AnnIntVararg(a = {1, 2})"; doTest(content, expectedAnnotation); } public void testStringArrayVarargAnnotation() throws IOException { String content = getContent("AnnStringVararg(\"a\", \"b\")"); - String expectedAnnotation = "AnnStringVararg(a = {\"a\", \"b\"})"; + String expectedAnnotation = "@AnnStringVararg(a = {\"a\", \"b\"})"; doTest(content, expectedAnnotation); } public void testStringArrayAnnotation() throws IOException { String content = getContent("AnnStringArray(array(\"a\"))"); - String expectedAnnotation = "AnnStringArray(a = {\"a\"})"; + String expectedAnnotation = "@AnnStringArray(a = {\"a\"})"; doTest(content, expectedAnnotation); } public void testEnumArrayAnnotation() throws IOException { String content = getContent("AnnArrayOfEnum(array(MyEnum.A))"); - String expectedAnnotation = "AnnArrayOfEnum(a = {MyEnum.A})"; + String expectedAnnotation = "@AnnArrayOfEnum(a = {MyEnum.A})"; doTest(content, expectedAnnotation); } public void testAnnotationAnnotation() throws Exception { String content = getContent("AnnAnn(AnnInt(1))"); - String expectedAnnotation = "AnnAnn(a = AnnInt(a = 1))"; + String expectedAnnotation = "@AnnAnn(a = AnnInt(a = 1))"; doTest(content, expectedAnnotation); } public void testJavaClassAnnotation() throws Exception { String content = getContent("AnnClass(MyClass::class)"); - String expectedAnnotation = "AnnClass(a = MyClass::class)"; + String expectedAnnotation = "@AnnClass(a = MyClass::class)"; doTest(content, expectedAnnotation); } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt index 9fc8be4d233..8dfb9ae5393 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt @@ -341,7 +341,6 @@ internal class DescriptorRendererImpl( if (DescriptorRendererModifier.ANNOTATIONS !in modifiers) return val excluded = if (annotated is JetType) excludedTypeAnnotationClasses else excludedAnnotationClasses - var hasTargetedAnnotations = false val annotationsBuilder = StringBuilder { // Sort is needed just to fix some order when annotations resolved from modifiers @@ -353,25 +352,12 @@ internal class DescriptorRendererImpl( val annotationClass = annotation.getType().getConstructor().getDeclarationDescriptor() as ClassDescriptor if (!excluded.contains(DescriptorUtils.getFqNameSafe(annotationClass))) { - if (target != null && !hasTargetedAnnotations) { - hasTargetedAnnotations = true - } append(renderAnnotation(annotation, target)).append(" ") } } } - if (!needBrackets || hasTargetedAnnotations) { - builder.append(annotationsBuilder) - } - else if (annotationsBuilder.length() > 0) { - // remove last whitespace - annotationsBuilder.setLength(annotationsBuilder.length() - 1) - - builder.append("@[") - builder.append(annotationsBuilder) - builder.append("] ") - } + builder.append(annotationsBuilder) } private fun AnnotationDescriptor.isBuiltinModifier() @@ -379,8 +365,9 @@ internal class DescriptorRendererImpl( override fun renderAnnotation(annotation: AnnotationDescriptor, target: AnnotationUseSiteTarget?): String { return StringBuilder { + append('@') if (target != null) { - append("@" + target.renderName + ":") + append(target.renderName + ":") } append(renderType(annotation.getType())) if (verbose) { @@ -411,7 +398,7 @@ internal class DescriptorRendererImpl( private fun renderConstant(value: ConstantValue<*>): String { return when (value) { is ArrayValue -> value.value.map { renderConstant(it) }.joinToString(", ", "{", "}") - is AnnotationValue -> renderAnnotation(value.value) + is AnnotationValue -> renderAnnotation(value.value).removePrefix("@") is KClassValue -> renderType(value.value) + "::class" else -> value.toString() } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/CallableClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/CallableClsStubBuilder.kt index 68a9b7cf3dd..d431b05b8f3 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/CallableClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/CallableClsStubBuilder.kt @@ -104,7 +104,7 @@ private class CallableClsStubBuilder( val kind = callableProto.annotatedCallableKind val annotationIds = c.components.annotationLoader.loadCallableAnnotations(protoContainer, callableProto, c.nameResolver, kind) - createTargetedAnnotationStubs(annotationIds, modifierListStubImpl, needWrappingAnnotationEntries = isPrimaryConstructor) + createTargetedAnnotationStubs(annotationIds, modifierListStubImpl) } private fun doCreateCallableStub(): StubElement { 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 38b1391d660..11030057220 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 @@ -94,7 +94,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) { } private fun createTypeAnnotationStubs(parent: KotlinStubBaseImpl<*>, annotations: List) { - createAnnotationStubs(annotations, parent, needWrappingAnnotationEntries = true) + createAnnotationStubs(annotations, parent) } private fun createTypeArgumentListStub(typeStub: KotlinUserTypeStub, typeArgumentProtoList: List) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt index f47121f17cc..c290b1ec0ea 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt @@ -216,25 +216,20 @@ fun createModifierListStub( ) } -fun createAnnotationStubs(annotationIds: List, parent: KotlinStubBaseImpl<*>, needWrappingAnnotationEntries: Boolean = false) { - return createTargetedAnnotationStubs(annotationIds.map { ClassIdWithTarget(it, null) }, parent, needWrappingAnnotationEntries) +fun createAnnotationStubs(annotationIds: List, parent: KotlinStubBaseImpl<*>) { + return createTargetedAnnotationStubs(annotationIds.map { ClassIdWithTarget(it, null) }, parent) } fun createTargetedAnnotationStubs( annotationIds: List, - parent: KotlinStubBaseImpl<*>, - needWrappingAnnotationEntries: Boolean = false + parent: KotlinStubBaseImpl<*> ) { if (annotationIds.isEmpty()) return - val entriesParent = - if (needWrappingAnnotationEntries) KotlinPlaceHolderStubImpl(parent, JetStubElementTypes.ANNOTATION) - else parent - annotationIds.forEach { annotation -> val (annotationClassId, target) = annotation val annotationEntryStubImpl = KotlinAnnotationEntryStubImpl( - entriesParent, + parent, shortName = annotationClassId.getShortClassName().ref(), hasValueArguments = false ) diff --git a/idea/testData/decompiler/decompiledText/Annotations.expected.kt b/idea/testData/decompiler/decompiledText/Annotations.expected.kt index 1de98c93b17..158ff467670 100644 --- a/idea/testData/decompiler/decompiledText/Annotations.expected.kt +++ b/idea/testData/decompiler/decompiledText/Annotations.expected.kt @@ -3,8 +3,8 @@ package test -dependency.A dependency.B dependency.C kotlin.data public final class Annotations public constructor() { - dependency.A dependency.B dependency.C kotlin.inline public final val p: @[dependency.B] kotlin.Int /* compiled code */ +@dependency.A @dependency.B @dependency.C @kotlin.data public final class Annotations public constructor() { + @dependency.A @dependency.B @dependency.C @kotlin.inline public final val p: @dependency.B kotlin.Int /* compiled code */ - dependency.A dependency.B dependency.C kotlin.inline public final fun f(dependency.A dependency.B dependency.C kotlin.Deprecated i: @[dependency.A] kotlin.Int): kotlin.Unit { /* compiled code */ } + @dependency.A @dependency.B @dependency.C @kotlin.inline public final fun f(@dependency.A @dependency.B @dependency.C @kotlin.Deprecated i: @dependency.A kotlin.Int): kotlin.Unit { /* compiled code */ } } \ No newline at end of file diff --git a/idea/testData/decompiler/decompiledText/AnnotationsOnPrimaryCtr.expected.kt b/idea/testData/decompiler/decompiledText/AnnotationsOnPrimaryCtr.expected.kt index e6a910aafe3..bad82d0d729 100644 --- a/idea/testData/decompiler/decompiledText/AnnotationsOnPrimaryCtr.expected.kt +++ b/idea/testData/decompiler/decompiledText/AnnotationsOnPrimaryCtr.expected.kt @@ -3,5 +3,5 @@ package test -public final class AnnotationsOnPrimaryCtr @[dependency.A dependency.B dependency.C] private constructor() { +public final class AnnotationsOnPrimaryCtr @dependency.A @dependency.B @dependency.C private constructor() { } \ No newline at end of file diff --git a/idea/testData/decompiler/decompiledText/SecondaryConstructors.expected.kt b/idea/testData/decompiler/decompiledText/SecondaryConstructors.expected.kt index d0e8e6f7c6b..a47d372275a 100644 --- a/idea/testData/decompiler/decompiledText/SecondaryConstructors.expected.kt +++ b/idea/testData/decompiler/decompiledText/SecondaryConstructors.expected.kt @@ -4,7 +4,7 @@ package test public final class SecondaryConstructors public constructor(x: kotlin.Boolean) { - test.anno public constructor(x: kotlin.String) { /* compiled code */ } + @test.anno public constructor(x: kotlin.String) { /* compiled code */ } private constructor(x: kotlin.Int) { /* compiled code */ } @@ -13,7 +13,7 @@ public final class SecondaryConstructors public constructor(x: kotlin.Boolean) { } public final class Nested { - test.anno public constructor(z: kotlin.Int) { /* compiled code */ } + @test.anno public constructor(z: kotlin.Int) { /* compiled code */ } internal constructor() { /* compiled code */ } } diff --git a/idea/testData/decompiler/stubBuilder/Annotations/Annotations.txt b/idea/testData/decompiler/stubBuilder/Annotations/Annotations.txt index b42ab37275d..59ed89fe9f6 100644 --- a/idea/testData/decompiler/stubBuilder/Annotations/Annotations.txt +++ b/idea/testData/decompiler/stubBuilder/Annotations/Annotations.txt @@ -10,12 +10,11 @@ PsiJetFileStubImpl[package=] REFERENCE_EXPRESSION:[referencedName=a] PRIMARY_CONSTRUCTOR: MODIFIER_LIST:[private] - ANNOTATION: - ANNOTATION_ENTRY:[hasValueArguments=false, shortName=a] - CONSTRUCTOR_CALLEE: - TYPE_REFERENCE: - USER_TYPE:[isAbsoluteInRootPackage=false] - REFERENCE_EXPRESSION:[referencedName=a] + ANNOTATION_ENTRY:[hasValueArguments=false, shortName=a] + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=a] VALUE_PARAMETER_LIST: VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=c1] MODIFIER_LIST:[] @@ -144,33 +143,31 @@ PsiJetFileStubImpl[package=] VALUE_PARAMETER_LIST: VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=param] TYPE_REFERENCE: - ANNOTATION: - ANNOTATION_ENTRY:[hasValueArguments=false, shortName=a] - CONSTRUCTOR_CALLEE: - TYPE_REFERENCE: - USER_TYPE:[isAbsoluteInRootPackage=false] - REFERENCE_EXPRESSION:[referencedName=a] - ANNOTATION_ENTRY:[hasValueArguments=false, shortName=b] - CONSTRUCTOR_CALLEE: - TYPE_REFERENCE: - USER_TYPE:[isAbsoluteInRootPackage=false] - REFERENCE_EXPRESSION:[referencedName=b] + ANNOTATION_ENTRY:[hasValueArguments=false, shortName=a] + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=a] + ANNOTATION_ENTRY:[hasValueArguments=false, shortName=b] + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=b] USER_TYPE:[isAbsoluteInRootPackage=false] USER_TYPE:[isAbsoluteInRootPackage=false] REFERENCE_EXPRESSION:[referencedName=kotlin] REFERENCE_EXPRESSION:[referencedName=DoubleRange] TYPE_REFERENCE: - ANNOTATION: - ANNOTATION_ENTRY:[hasValueArguments=false, shortName=a] - CONSTRUCTOR_CALLEE: - TYPE_REFERENCE: - USER_TYPE:[isAbsoluteInRootPackage=false] - REFERENCE_EXPRESSION:[referencedName=a] - ANNOTATION_ENTRY:[hasValueArguments=false, shortName=b] - CONSTRUCTOR_CALLEE: - TYPE_REFERENCE: - USER_TYPE:[isAbsoluteInRootPackage=false] - REFERENCE_EXPRESSION:[referencedName=b] + ANNOTATION_ENTRY:[hasValueArguments=false, shortName=a] + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=a] + ANNOTATION_ENTRY:[hasValueArguments=false, shortName=b] + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=b] USER_TYPE:[isAbsoluteInRootPackage=false] USER_TYPE:[isAbsoluteInRootPackage=false] REFERENCE_EXPRESSION:[referencedName=kotlin] @@ -179,11 +176,10 @@ PsiJetFileStubImpl[package=] MODIFIER_LIST:[public final] PRIMARY_CONSTRUCTOR: MODIFIER_LIST:[private] - ANNOTATION: - ANNOTATION_ENTRY:[hasValueArguments=false, shortName=a] - CONSTRUCTOR_CALLEE: - TYPE_REFERENCE: - USER_TYPE:[isAbsoluteInRootPackage=false] - REFERENCE_EXPRESSION:[referencedName=a] + ANNOTATION_ENTRY:[hasValueArguments=false, shortName=a] + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=a] VALUE_PARAMETER_LIST: CLASS_BODY: diff --git a/idea/testData/editor/quickDoc/MethodFromStdLib.kt b/idea/testData/editor/quickDoc/MethodFromStdLib.kt index 8a922d47f55..a2e473d84fc 100644 --- a/idea/testData/editor/quickDoc/MethodFromStdLib.kt +++ b/idea/testData/editor/quickDoc/MethodFromStdLib.kt @@ -2,4 +2,4 @@ fun test() { listOf(1, 2, 4).filter { it > 0 } } -//INFO: inline public fun <T> Iterable<T>.filter(predicate: (T) → Boolean): List<T> defined in kotlin

Returns a list containing all elements matching the given predicate.

+//INFO: @inline public fun <T> Iterable<T>.filter(predicate: (T) → Boolean): List<T> defined in kotlin

Returns a list containing all elements matching the given predicate.