Skip to content

Commit 864e273

Browse files
udalovSpace Team
authored andcommitted
Kotlinp: do not use hasAnnotations on Km declarations
#KT-75290
1 parent 3e9cf44 commit 864e273

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

libraries/tools/kotlinp/klib/src/org/jetbrains/kotlin/kotlinp/klib/KlibKotlinp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class KlibKotlinp(
7171
clazz.klibEnumEntries.forEach { enumEntry ->
7272
appendLine()
7373
appendSignature { enumEntrySignature(enumEntry) }
74-
appendAnnotations(hasAnnotations = null, enumEntry.annotations)
74+
appendAnnotations(enumEntry.annotations)
7575
appendLine(enumEntry.name, ",")
7676
}
7777
}

libraries/tools/kotlinp/src/org/jetbrains/kotlin/kotlinp/Kotlinp.kt

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
package org.jetbrains.kotlin.kotlinp
77

8-
import kotlin.metadata.*
98
import kotlin.contracts.ExperimentalContracts
9+
import kotlin.metadata.*
1010

1111
abstract class Kotlinp(protected val settings: Settings) {
1212
fun renderAnnotation(annotation: KmAnnotation, printer: Printer): Unit = with(printer) {
@@ -64,13 +64,11 @@ abstract class Kotlinp(protected val settings: Settings) {
6464
}
6565
}
6666

67-
protected fun Printer.appendAnnotations(hasAnnotations: Boolean?, annotations: List<KmAnnotation>, onePerLine: Boolean = true) {
68-
if (hasAnnotations != false) {
69-
annotations.forEach { annotation ->
70-
append("@")
71-
renderAnnotation(annotation, this)
72-
if (onePerLine) appendLine() else append(" ")
73-
}
67+
protected fun Printer.appendAnnotations(annotations: List<KmAnnotation>, onePerLine: Boolean = true) {
68+
annotations.forEach { annotation ->
69+
append("@")
70+
renderAnnotation(annotation, this)
71+
if (onePerLine) appendLine() else append(" ")
7472
}
7573
}
7674

@@ -79,7 +77,7 @@ abstract class Kotlinp(protected val settings: Settings) {
7977
appendOrigin(clazz)
8078
appendVersionRequirements(clazz.versionRequirements)
8179
appendSignatures(clazz)
82-
appendAnnotations(clazz.hasAnnotations, getAnnotations(clazz))
80+
appendAnnotations(getAnnotations(clazz))
8381
appendContextReceiverTypes(clazz.contextReceiverTypes)
8482
append(VISIBILITY_MAP[clazz.visibility])
8583
append(MODALITY_MAP[clazz.modality])
@@ -139,7 +137,7 @@ abstract class Kotlinp(protected val settings: Settings) {
139137
appendLine()
140138
appendVersionRequirements(constructor.versionRequirements)
141139
appendSignatures(constructor)
142-
appendAnnotations(constructor.hasAnnotations, getAnnotations(constructor))
140+
appendAnnotations(getAnnotations(constructor))
143141
renderConstructorModifiers(constructor, printer)
144142
append("constructor")
145143
appendValueParameters(constructor.valueParameters)
@@ -160,7 +158,7 @@ abstract class Kotlinp(protected val settings: Settings) {
160158
appendOrigin(function)
161159
appendVersionRequirements(function.versionRequirements)
162160
appendSignatures(function)
163-
appendAnnotations(function.hasAnnotations, getAnnotations(function))
161+
appendAnnotations(getAnnotations(function))
164162
appendContextReceiverTypes(function.contextReceiverTypes)
165163
renderFunctionModifiers(function, printer)
166164
append("fun ")
@@ -294,7 +292,7 @@ abstract class Kotlinp(protected val settings: Settings) {
294292
appendVersionRequirements(property.versionRequirements)
295293
appendSignatures(property)
296294
appendCustomAttributes(property)
297-
appendAnnotations(property.hasAnnotations, getAnnotations(property))
295+
appendAnnotations(getAnnotations(property))
298296
appendContextReceiverTypes(property.contextReceiverTypes)
299297
renderPropertyModifiers(property, printer)
300298
append(if (property.isVar) "var " else "val ")
@@ -308,12 +306,12 @@ abstract class Kotlinp(protected val settings: Settings) {
308306
appendLine()
309307
withIndent {
310308
appendGetterSignatures(property)
311-
appendAnnotations(property.getter.hasAnnotations, getGetterAnnotations(property))
309+
appendAnnotations(getGetterAnnotations(property))
312310
renderPropertyAccessorModifiers(property.getter, printer)
313311
appendLine("get")
314312
property.setter?.let { setter ->
315313
appendSetterSignatures(property)
316-
appendAnnotations(setter.hasAnnotations, getSetterAnnotations(property))
314+
appendAnnotations(getSetterAnnotations(property))
317315
renderPropertyAccessorModifiers(setter, printer)
318316
append("set")
319317
property.setterParameter?.let {
@@ -351,7 +349,7 @@ abstract class Kotlinp(protected val settings: Settings) {
351349
appendLine()
352350
appendVersionRequirements(typeAlias.versionRequirements)
353351
appendSignatures(typeAlias)
354-
appendAnnotations(typeAlias.hasAnnotations, typeAlias.annotations)
352+
appendAnnotations(typeAlias.annotations)
355353
append(VISIBILITY_MAP[typeAlias.visibility], "typealias ", typeAlias.name)
356354
appendTypeParameters(typeAlias.typeParameters)
357355
append(" = ").appendType(typeAlias.underlyingType)
@@ -361,7 +359,7 @@ abstract class Kotlinp(protected val settings: Settings) {
361359

362360
fun renderTypeParameter(typeParameter: KmTypeParameter, printer: Printer): Unit = with(printer) {
363361
appendFlags(typeParameter.isReified to "reified")
364-
appendAnnotations(hasAnnotations = null, getAnnotations(typeParameter), onePerLine = false)
362+
appendAnnotations(getAnnotations(typeParameter), onePerLine = false)
365363
if (typeParameter.variance != KmVariance.INVARIANT) {
366364
append(typeParameter.variance.name.lowercase()).append(" ")
367365
}
@@ -388,7 +386,7 @@ abstract class Kotlinp(protected val settings: Settings) {
388386
val platformTypeUpperBound = type.flexibleTypeUpperBound?.let { renderFlexibleTypeUpperBound(it) }
389387

390388
printer += printString {
391-
appendAnnotations(hasAnnotations = null, getAnnotations(type), onePerLine = false)
389+
appendAnnotations(getAnnotations(type), onePerLine = false)
392390
appendFlags(
393391
isRaw(type) to "/* raw */",
394392
type.isSuspend to "suspend"
@@ -442,7 +440,7 @@ abstract class Kotlinp(protected val settings: Settings) {
442440
}
443441

444442
fun renderValueParameter(valueParameter: KmValueParameter, printer: Printer): Unit = with(printer) {
445-
appendAnnotations(valueParameter.hasAnnotations, getAnnotations(valueParameter), onePerLine = false)
443+
appendAnnotations(getAnnotations(valueParameter), onePerLine = false)
446444
appendFlags(
447445
valueParameter.isCrossinline to "crossinline",
448446
valueParameter.isNoinline to "noinline"

native/native.tests/testData/CInterop/experimental/cases/enum/contents.gold.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ library {
7171
public final const val FOUR: kotlin/UInt /* = dependency/E2^ */ /* = 4u */
7272
public final get
7373

74+
@kotlinx/cinterop/ExperimentalForeignApi
7475
public typealias E2 = kotlin/UInt /* = kotlin/UInt */
7576

77+
@kotlinx/cinterop/ExperimentalForeignApi
7678
public typealias E2Var = kotlinx/cinterop/UIntVarOf<dependency/E2^> /* = kotlinx/cinterop/UIntVarOf<kotlin/UInt /* = dependency/E2^ */> */
7779
}
7880
}

native/native.tests/testData/CInterop/experimental/cases/objctypedef/contents.gold.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ library {
3333

3434
package {
3535

36+
@kotlinx/cinterop/ExperimentalForeignApi
3637
public typealias MyClassRef = dependency/MyClass? /* = dependency/MyClass? */
3738

39+
@kotlinx/cinterop/ExperimentalForeignApi
3840
public typealias MyClassRefVar = kotlinx/cinterop/ObjCObjectVar<dependency/MyClassRef^> /* = kotlinx/cinterop/ObjCObjectVar<dependency/MyClass? /* = dependency/MyClassRef^ */> */
3941

42+
@kotlinx/cinterop/ExperimentalForeignApi
4043
public typealias MyId = kotlin/Any? /* = kotlin/Any? */
4144

45+
@kotlinx/cinterop/ExperimentalForeignApi
4246
public typealias MyIdVar = kotlinx/cinterop/ObjCObjectVar<dependency/MyId^> /* = kotlinx/cinterop/ObjCObjectVar<kotlin/Any? /* = dependency/MyId^ */> */
4347
}
4448
}

native/native.tests/testData/CInterop/experimental/cases/typedef/contents.gold.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,22 @@ library {
2727

2828
package {
2929

30+
@kotlinx/cinterop/ExperimentalForeignApi
3031
public typealias MyInt = kotlin/Int /* = kotlin/Int */
3132

33+
@kotlinx/cinterop/ExperimentalForeignApi
3234
public typealias MyIntVar = kotlinx/cinterop/IntVarOf<dependency/MyInt^> /* = kotlinx/cinterop/IntVarOf<kotlin/Int /* = dependency/MyInt^ */> */
3335

36+
@kotlinx/cinterop/ExperimentalForeignApi
3437
public typealias MyPointer = kotlinx/cinterop/COpaquePointer^ /* = kotlinx/cinterop/CPointer<out kotlinx/cinterop/CPointed> /* = kotlinx/cinterop/COpaquePointer^ */ */
3538

39+
@kotlinx/cinterop/ExperimentalForeignApi
3640
public typealias MyPointerVar = kotlinx/cinterop/CPointerVarOf<dependency/MyPointer^> /* = kotlinx/cinterop/CPointerVarOf<kotlinx/cinterop/CPointer<out kotlinx/cinterop/CPointed> /* = dependency/MyPointer^ */> */
3741

42+
@kotlinx/cinterop/ExperimentalForeignApi
3843
public typealias MyS = cnames/structs/S /* = cnames/structs/S */
3944

45+
@kotlinx/cinterop/ExperimentalForeignApi
4046
public typealias MyT = dependency/T /* = dependency/T */
4147
}
4248
}

0 commit comments

Comments
 (0)