From 693f0611b31968982b72b3bdee9f71dbe468e9e0 Mon Sep 17 00:00:00 2001 From: J2ObjC Team Date: Mon, 14 Sep 2026 15:21:34 -0700 Subject: [PATCH] BEGIN_PUBLIC Allow @ObjectiveCKmpMethod on record components. END_PUBLIC PiperOrigin-RevId: 981392425 --- .../annotations/ObjectiveCKmpMethod.java | 2 +- .../ObjectiveCKmpMethodTranslatorTest.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/annotations/src/main/java/com/google/j2objc/annotations/ObjectiveCKmpMethod.java b/annotations/src/main/java/com/google/j2objc/annotations/ObjectiveCKmpMethod.java index 9153d5d011..5147d0551f 100644 --- a/annotations/src/main/java/com/google/j2objc/annotations/ObjectiveCKmpMethod.java +++ b/annotations/src/main/java/com/google/j2objc/annotations/ObjectiveCKmpMethod.java @@ -67,7 +67,7 @@ * not found, it will fallback to a method that matches {@code List}. */ @Documented -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) +@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.RECORD_COMPONENT}) @Retention(RetentionPolicy.CLASS) public @interface ObjectiveCKmpMethod { /** diff --git a/translator/src/test/java/com/google/devtools/j2objc/translate/ObjectiveCKmpMethodTranslatorTest.java b/translator/src/test/java/com/google/devtools/j2objc/translate/ObjectiveCKmpMethodTranslatorTest.java index 7fe88cff33..bc4c33a1f8 100644 --- a/translator/src/test/java/com/google/devtools/j2objc/translate/ObjectiveCKmpMethodTranslatorTest.java +++ b/translator/src/test/java/com/google/devtools/j2objc/translate/ObjectiveCKmpMethodTranslatorTest.java @@ -2143,5 +2143,29 @@ public void verifyList(List>> list) {} } """); } + + public void testRecordComponentAnnotation() throws IOException { + addSourceFile( + """ + import com.google.j2objc.annotations.ObjectiveCKmpMethod; + import java.util.List; + + public record TestRecord( + @ObjectiveCKmpMethod(selector = "itemsAsList", adapter = Adapter.class) + List items) {} + """, + "TestRecord.java"); + String header = translateSourceFile("TestRecord", "TestRecord.h"); + assertInTranslation(header, "- (NSArray *)itemsAsList;"); + + String impl = translateSourceFile("TestRecord", "TestRecord.m"); + assertInTranslation( + impl, + """ + - (NSArray *)itemsAsList { + return (NSArray *) [Adapter fromJavaUtilListWithJavaUtilList:[self items]]; + } + """); + } }