Skip to content

Commit

Permalink
[J2KT] Render annotation methods as properties in Kotlin, as this is …
Browse files Browse the repository at this point in the history
…how annotation methods in Java are represented in Kotlin. The follow-up CL will cover conversion from Java annotation interfaces to Kotlin annotation classes.

PiperOrigin-RevId: 713622442
  • Loading branch information
Googler authored and copybara-github committed Jan 9, 2025
1 parent 2a5febb commit f951605
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public interface Origin {
abstract KtInfo getKtInfo();

public boolean isKtProperty() {
return isField() || getKtInfo().isProperty();
return isField()
|| getKtInfo().isProperty()
|| getEnclosingTypeDescriptor().getTypeDeclaration().isAnnotation();
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ enum SomeEnum {
}

// Note that this inherits the single abstract method defined in its implicit parent
// java.lang.Annotation. If this interface was not an annotation interface, it would meet the
// requirements to be a functional interface.
// java.lang.annotation.Annotation. If this interface was not an annotation interface, it would
// meet the requirements to be a functional interface.
@interface Zoo {}

static void test(Foo foo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,58 +42,58 @@ open class Main {
val booleanConstant: Boolean = Main.Foo.BOOLEAN_CONSTANT
val intConstant: Int = Main.Foo.INT_CONSTANT
val stringConstant: String? = Main.Foo.STRING_CONSTANT
val booleanValue: Boolean = foo!!.booleanValue()
val intValue: Int = foo!!.intValue()
val stringValue: String? = foo!!.stringValue()
val classValue: Class<*>? = foo!!.classValue()
val enumValue: Main.SomeEnum? = foo!!.enumValue()
val annotationValue: Main.Zoo? = foo!!.annotationValue()
val booleanArray: BooleanArray? = foo!!.booleanArray()
val intArray: IntArray? = foo!!.intArray()
val stringArray: Array<String?>? = foo!!.stringArray() as Array<String?>?
val classArray: Array<Class<*>?>? = foo!!.classArray() as Array<Class<*>?>?
val enumArray: Array<Main.SomeEnum?>? = foo!!.enumArray() as Array<Main.SomeEnum?>?
val annotationArray: Array<Main.Zoo?>? = foo!!.annotationArray() as Array<Main.Zoo?>?
val booleanValue: Boolean = foo!!.booleanValue
val intValue: Int = foo!!.intValue
val stringValue: String? = foo!!.stringValue
val classValue: Class<*>? = foo!!.classValue
val enumValue: Main.SomeEnum? = foo!!.enumValue
val annotationValue: Main.Zoo? = foo!!.annotationValue
val booleanArray: BooleanArray? = foo!!.booleanArray
val intArray: IntArray? = foo!!.intArray
val stringArray: Array<String?>? = foo!!.stringArray as Array<String?>?
val classArray: Array<Class<*>?>? = foo!!.classArray as Array<Class<*>?>?
val enumArray: Array<Main.SomeEnum?>? = foo!!.enumArray as Array<Main.SomeEnum?>?
val annotationArray: Array<Main.Zoo?>? = foo!!.annotationArray as Array<Main.Zoo?>?
}
}

@ObjCName("J2ktAnnotationMain_Foo", exact = true)
interface Foo: Annotation {
@ObjCName("booleanValue")
fun booleanValue(): Boolean
val booleanValue: Boolean

@ObjCName("intValue")
fun intValue(): Int
val intValue: Int

@ObjCName("stringValue")
fun stringValue(): String
val stringValue: String

@ObjCName("classValue")
fun classValue(): Class<*>
val classValue: Class<*>

@ObjCName("enumValue")
fun enumValue(): Main.SomeEnum
val enumValue: Main.SomeEnum

@ObjCName("annotationValue")
fun annotationValue(): Main.Zoo
val annotationValue: Main.Zoo

@ObjCName("booleanArray")
fun booleanArray(): BooleanArray
val booleanArray: BooleanArray

@ObjCName("intArray")
fun intArray(): IntArray
val intArray: IntArray

@ObjCName("stringArray")
fun stringArray(): Array<String>
val stringArray: Array<String>

@ObjCName("classArray")
fun classArray(): Array<Class<*>>
val classArray: Array<Class<*>>

@ObjCName("enumArray")
fun enumArray(): Array<Main.SomeEnum>
val enumArray: Array<Main.SomeEnum>

@ObjCName("annotationArray")
fun annotationArray(): Array<Main.Zoo>
val annotationArray: Array<Main.Zoo>

@ObjCName("J2ktAnnotationMain_FooCompanion", exact = true)
companion object {
Expand Down

0 comments on commit f951605

Please sign in to comment.