Migrate MainSwitchPreferenceUiState, DialogTextPreferenceUiState, and PreferenceCategoryUiState to Java records.

Convert the SettingsV2 preference UI states and PreferenceCategoryUiState from @AutoValue to Java records with @AutoBuilder, using @Property, @JsProperty, and @ObjectiveCKmpMethod on record components across J2CL, J2ObjC, and J2KT Native (AccountPreferenceUiState was deleted in cl/987963268).

PiperOrigin-RevId: 987064876
diff --git a/translator/src/main/java/com/google/devtools/j2objc/gen/PropertyGenerator.java b/translator/src/main/java/com/google/devtools/j2objc/gen/PropertyGenerator.java
index f11fe63..6a078f7 100644
--- a/translator/src/main/java/com/google/devtools/j2objc/gen/PropertyGenerator.java
+++ b/translator/src/main/java/com/google/devtools/j2objc/gen/PropertyGenerator.java
@@ -120,7 +120,9 @@
   private boolean processMemoryManagementAttributes(Set<String> attributes) {
     VariableDeclarationFragment firstVarNode = declaration.getFragment();
     if (typeUtil.isString(varType)) {
-      attributes.add("copy");
+      if (!PropertyAnnotation.hasMemoryManagementAttribute(attributes)) {
+        attributes.add("copy");
+      }
     } else if (ElementUtil.hasAnnotation(firstVarNode.getVariableElement(), Weak.class)) {
       if (attributes.contains("strong")) {
         ErrorUtil.error(
diff --git a/translator/src/main/java/com/google/devtools/j2objc/gen/TypeDeclarationGenerator.java b/translator/src/main/java/com/google/devtools/j2objc/gen/TypeDeclarationGenerator.java
index 556c372..b72d2b6 100644
--- a/translator/src/main/java/com/google/devtools/j2objc/gen/TypeDeclarationGenerator.java
+++ b/translator/src/main/java/com/google/devtools/j2objc/gen/TypeDeclarationGenerator.java
@@ -16,6 +16,7 @@
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.ListMultimap;
 import com.google.common.collect.Lists;
@@ -39,11 +40,13 @@
 import com.google.devtools.j2objc.util.TranslationUtil;
 import com.google.devtools.j2objc.util.TypeUtil;
 import com.google.devtools.j2objc.util.UnicodeUtils;
+import com.google.j2objc.annotations.Property;
 import java.lang.reflect.Modifier;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 import java.util.stream.Collectors;
 import javax.lang.model.element.ExecutableElement;
 import javax.lang.model.element.TypeElement;
@@ -457,12 +460,30 @@
       VariableElement var = fragment.getVariableElement();
       if (typeNode instanceof RecordDeclaration && !ElementUtil.isStatic(var)) {
         // Instance fields of a record are its components.
+        ExecutableElement accessor =
+            ElementUtil.findMethod(typeElement, var.getSimpleName().toString());
+        if (ElementUtil.hasAnnotation(var, Property.Suppress.class)
+            || (accessor != null && ElementUtil.hasAnnotation(accessor, Property.Suppress.class))) {
+          continue;
+        }
+        FieldDeclaration existingFieldDecl = (FieldDeclaration) fragment.getParent();
+        PropertyAnnotation existingAnnotation =
+            existingFieldDecl.getAnnotations().stream()
+                .filter(PropertyAnnotation.class::isInstance)
+                .map(PropertyAnnotation.class::cast)
+                .findFirst()
+                .orElse(null);
 
         // Synthesize a declaration as if it was annotated with @Property.
         FieldDeclaration componentDeclaration = new FieldDeclaration(var, null);
-        PropertyAnnotation componentAnnotation = new PropertyAnnotation();
-        componentAnnotation.getPropertyAttributes().add("readonly");
-        componentAnnotation.getPropertyAttributes().add("nonatomic");
+        PropertyAnnotation componentAnnotation =
+            existingAnnotation != null
+                ? new PropertyAnnotation(existingAnnotation)
+                : new PropertyAnnotation();
+        componentAnnotation.addAttribute("readonly");
+        if (!componentAnnotation.hasAttribute("atomic")) {
+          componentAnnotation.addAttribute("nonatomic");
+        }
         componentDeclaration.addAnnotation(componentAnnotation);
         fragment = componentDeclaration.getFragment();
       }
@@ -772,10 +793,40 @@
         ElementUtil.findSetterMethod(
             propertyName, returnType, declaringClass, ElementUtil.isStatic(methodElement));
 
+    PropertyAnnotation propertyAnnotation =
+        m.getAnnotations().stream()
+            .filter(PropertyAnnotation.class::isInstance)
+            .map(PropertyAnnotation.class::cast)
+            .findFirst()
+            .orElseGet(
+                () ->
+                    typeNode.getAnnotations().stream()
+                        .filter(PropertyAnnotation.class::isInstance)
+                        .map(PropertyAnnotation.class::cast)
+                        .findFirst()
+                        .orElse(null));
+    Set<String> customAttributes =
+        propertyAnnotation != null ? propertyAnnotation.getPropertyAttributes() : ImmutableSet.of();
+    String memoryManagementAttribute = "";
+    if (PropertyAnnotation.hasMemoryManagementAttribute(customAttributes)) {
+      for (String attr : customAttributes) {
+        if (PropertyAnnotation.hasMemoryManagementAttribute(ImmutableSet.of(attr))) {
+          if (!attr.equals("strong") || !options.useARC()) {
+            memoryManagementAttribute = attr + ", ";
+          }
+          break;
+        }
+      }
+    } else if (typeUtil.isString(returnType)) {
+      memoryManagementAttribute = "copy, ";
+    }
+
     newline();
     printf(
-        "@property (%snonatomic, %s, %s%s) %s %s;",
+        "@property (%s%s%s, %s, %s%s) %s %s;",
         ElementUtil.isStatic(methodElement) && !isKotlinCompanion ? "class, " : "",
+        memoryManagementAttribute,
+        customAttributes.contains("atomic") ? "atomic" : "nonatomic",
         "getter=" + methodName,
         setter != null ? "setter=" + nameTable.getMethodSelector(setter) : "readonly",
         shouldAddNullableAnnotation(methodElement) ? ", nullable" : "",
diff --git a/translator/src/test/java/com/google/devtools/j2objc/gen/GenerateObjCCompanionTest.java b/translator/src/test/java/com/google/devtools/j2objc/gen/GenerateObjCCompanionTest.java
index 94ce1f1..8ffad6e 100644
--- a/translator/src/test/java/com/google/devtools/j2objc/gen/GenerateObjCCompanionTest.java
+++ b/translator/src/test/java/com/google/devtools/j2objc/gen/GenerateObjCCompanionTest.java
@@ -157,9 +157,10 @@
         """;
     String header = translateSourceFile(source, "Foo", "Foo.h");
     assertInTranslation(header, "@protocol FooCompanionProtocol");
-    assertInTranslation(header, "@property (nonatomic, getter=getBar, readonly) NSString * bar;");
     assertInTranslation(
-        header, "@property (class, nonatomic, getter=getBar, readonly) NSString * bar;");
+        header, "@property (copy, nonatomic, getter=getBar, readonly) NSString * bar;");
+    assertInTranslation(
+        header, "@property (class, copy, nonatomic, getter=getBar, readonly) NSString * bar;");
   }
 }
 
diff --git a/translator/src/test/java/com/google/devtools/j2objc/gen/ObjectiveCHeaderGeneratorTest.java b/translator/src/test/java/com/google/devtools/j2objc/gen/ObjectiveCHeaderGeneratorTest.java
index 77fd225..f4bfa34 100644
--- a/translator/src/test/java/com/google/devtools/j2objc/gen/ObjectiveCHeaderGeneratorTest.java
+++ b/translator/src/test/java/com/google/devtools/j2objc/gen/ObjectiveCHeaderGeneratorTest.java
@@ -768,7 +768,8 @@
             + "}";
     String translation = translateSourceFile(sourceContent, "FooBar", "FooBar.h");
     assertTranslatedLines(
-        translation, "@property (nonatomic, getter=getFooField, readonly) NSString * fooField;");
+        translation,
+        "@property (copy, nonatomic, getter=getFooField, readonly) NSString * fooField;");
   }
 
   public void testPropertiesOfGetTypesWithSetters() throws IOException {
@@ -789,8 +790,8 @@
     String translation = translateSourceFile(sourceContent, "FooBar", "FooBar.h");
     assertTranslatedLines(
         translation,
-        "@property (nonatomic, getter=getFooField, setter=setFooFieldWithNSString:) NSString *"
-            + " fooField;");
+        "@property (copy, nonatomic, getter=getFooField, setter=setFooFieldWithNSString:) NSString"
+            + " * fooField;");
   }
 
   public void testPropertyAnnotationSuppression() throws IOException {
@@ -815,7 +816,7 @@
             + "}";
     String translation = translateSourceFile(sourceContent, "FooBar", "FooBar.h");
     assertNotInTranslation(
-        translation, "@property (nonatomic, getter=getBar, readonly) NSString * bar;");
+        translation, "@property (copy, nonatomic, getter=getBar, readonly) NSString * bar;");
   }
 
   public void testPropertiesStaticMethods() throws IOException {
@@ -831,7 +832,7 @@
     String translation = translateSourceFile(sourceContent, "FooBar", "FooBar.h");
     assertTranslatedLines(
         translation,
-        "@property (class, nonatomic, getter=getFieldFoo, readonly) NSString * fieldFoo;");
+        "@property (class, copy, nonatomic, getter=getFieldFoo, readonly) NSString * fieldFoo;");
   }
 
   public void testPropertiesOfGetTypesDuplicateNames() throws IOException {
@@ -885,7 +886,7 @@
     String translation = translateSourceFile(sourceContent, "foo.bar.FooBar", "foo/bar/FooBar.h");
     assertTranslatedLines(
         translation,
-        "@property (nonatomic, getter=getFooField, setter=setFooFieldWithNSString:, nullable)"
+        "@property (copy, nonatomic, getter=getFooField, setter=setFooFieldWithNSString:, nullable)"
             + " NSString * fooField;");
   }
 
@@ -919,10 +920,40 @@
     String translation = translateSourceFile(sourceContent, "FooBar", "FooBar.h");
     assertTranslatedLines(
         translation,
-        "@property (nonatomic, getter=getFooField, setter=setFooFieldWithNSString:)"
+        "@property (copy, nonatomic, getter=getFooField, setter=setFooFieldWithNSString:)"
             + " NSString * fooField;");
   }
 
+  public void testRecordImplementingPropertyInterface() throws IOException {
+    addSourceFile(
+        """
+        import com.google.j2objc.annotations.Property;
+        public interface HasIdentifier {
+          @Property
+          String identifier();
+        }
+        """,
+        "HasIdentifier.java");
+    addSourceFile(
+        """
+        import com.google.j2objc.annotations.Property;
+        public record ItemRecord(
+            String identifier,
+            @Property("assign") String rawName,
+            @Property.Suppress String suppressedProp) implements HasIdentifier {}
+        """,
+        "ItemRecord.java");
+    String protocolHeader = translateSourceFile("HasIdentifier", "HasIdentifier.h");
+    assertInTranslation(
+        protocolHeader,
+        "@property (copy, nonatomic, getter=identifier, readonly) NSString * identifier;");
+    String recordHeader = translateSourceFile("ItemRecord", "ItemRecord.h");
+    assertInTranslation(
+        recordHeader, "@property (readonly, copy, nonatomic) NSString *identifier;");
+    assertInTranslation(recordHeader, "@property (readonly, assign, nonatomic) NSString *rawName;");
+    assertNotInTranslation(recordHeader, "*suppressedProp;");
+  }
+
   public void testAddIgnoreDeprecationWarningsPragmaIfDeprecatedDeclarationsIsEnabled()
       throws IOException {
     options.enableDeprecatedDeclarations();
diff --git a/translator/src/test/java/com/google/devtools/j2objc/translate/AbstractMethodRewriterTest.java b/translator/src/test/java/com/google/devtools/j2objc/translate/AbstractMethodRewriterTest.java
index 4b6555ba..4cefb34 100644
--- a/translator/src/test/java/com/google/devtools/j2objc/translate/AbstractMethodRewriterTest.java
+++ b/translator/src/test/java/com/google/devtools/j2objc/translate/AbstractMethodRewriterTest.java
@@ -54,7 +54,8 @@
         "PromptBoxActionRegistryImpl.java");
     String header = translateSourceFile("PromptBoxActionRegistry", "PromptBoxActionRegistry.h");
     assertInTranslation(
-        header, "@property (nonatomic, getter=getSubmitAction, readonly) NSString * submitAction;");
+        header,
+        "@property (copy, nonatomic, getter=getSubmitAction, readonly) NSString * submitAction;");
     String translation =
         translateSourceFile("PromptBoxActionRegistryImpl", "PromptBoxActionRegistryImpl.m");
     // Verify that -Wobjc-protocol-property-synthesis is suppressed alongside compiler similarity