From 8c5b2252eaa6d5c2f1adbd2c179e911c740dd4ad Mon Sep 17 00:00:00 2001 From: David Vacca <515103+mdvacca@users.noreply.github.com> Date: Thu, 20 Feb 2025 09:52:03 -0800 Subject: [PATCH] Migrate ReactLegacyArchitectureProcessor to kotlin Summary: Migrate ReactLegacyArchitectureProcessor to kotlin changelog: [internal] internal Differential Revision: D69929877 --- .../ReactLegacyArchitectureProcessor.java | 55 ------------------- .../ReactLegacyArchitectureProcessor.kt | 48 ++++++++++++++++ 2 files changed, 48 insertions(+), 55 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactLegacyArchitectureProcessor.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactLegacyArchitectureProcessor.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactLegacyArchitectureProcessor.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactLegacyArchitectureProcessor.java deleted file mode 100644 index 01798a4d0e9c24..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactLegacyArchitectureProcessor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - - -package com.facebook.react.processing; - -import com.facebook.annotationprocessors.common.ProcessorBase; - -import com.facebook.react.common.annotations.internal.LegacyArchitecture; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import java.util.Set; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.annotation.processing.SupportedSourceVersion; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.Element; -import javax.lang.model.element.TypeElement; - -@SupportedAnnotationTypes("com.facebook.react.common.annotations.internal.LegacyArchitecture") -@SupportedSourceVersion(SourceVersion.RELEASE_11) -public class ReactLegacyArchitectureProcessor extends ProcessorBase { - - @Override - protected boolean processImpl(Set annotations, RoundEnvironment roundEnv) { - String outputFileName = System.getenv().get("OUTPUT_FILE_NAME"); - if (String.valueOf(outputFileName).isEmpty()) { - return true; - } - Set elements = roundEnv.getElementsAnnotatedWith(LegacyArchitecture.class); - List classes = new ArrayList<>(); - - for (Element element : elements) { - TypeElement classType = (TypeElement) element; - String className = classType.getQualifiedName().toString().replace(".", "/"); - classes.add("type L" + className + ";"); - } - - try (FileWriter writer = new FileWriter(outputFileName, true)) { - for (String clazz : classes) { - writer.write(clazz + "\n"); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - return true; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactLegacyArchitectureProcessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactLegacyArchitectureProcessor.kt new file mode 100644 index 00000000000000..6f8e33f534761b --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactLegacyArchitectureProcessor.kt @@ -0,0 +1,48 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.processing + +import com.facebook.annotationprocessors.common.ProcessorBase +import com.facebook.react.common.annotations.internal.LegacyArchitecture +import java.io.FileWriter +import java.io.IOException +import javax.annotation.processing.RoundEnvironment +import javax.annotation.processing.SupportedAnnotationTypes +import javax.annotation.processing.SupportedSourceVersion +import javax.lang.model.SourceVersion +import javax.lang.model.element.TypeElement + +@SupportedAnnotationTypes("com.facebook.react.common.annotations.internal.LegacyArchitecture") +@SupportedSourceVersion(SourceVersion.RELEASE_11) +class ReactLegacyArchitectureProcessor : ProcessorBase() { + override fun processImpl(annotations: Set, roundEnv: RoundEnvironment): Boolean { + val outputFileName = System.getenv()["OUTPUT_FILE_NAME"] + if (outputFileName.isNullOrEmpty()) { + return true + } + val elements = roundEnv.getElementsAnnotatedWith(LegacyArchitecture::class.java) + val classes: MutableList = ArrayList() + + for (element in elements) { + val classType = element as TypeElement + val className = classType.qualifiedName.toString().replace(".", "/") + classes.add("type L$className;") + } + + try { + FileWriter(outputFileName, true).use { writer -> + for (clazz in classes) { + writer.write(clazz + "\n") + } + } + } catch (e: IOException) { + throw RuntimeException(e) + } + return true + } +}