Compare commits

...
Author SHA1 Message Date
David Vacca fe69515571 Migrate ReactLegacyArchitectureProcessor to kotlin (#49571)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/49571

Migrate ReactLegacyArchitectureProcessor to kotlin

changelog: [internal] internal

Reviewed By: cortinico

Differential Revision: D69929877

fbshipit-source-id: 448c8de54cbb1f72eeee747edaf4cbb2a5fd365d
2025-02-21 19:24:12 +00:00
@@ -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<TypeElement>, roundEnv: RoundEnvironment): Boolean {
val outputFileName = System.getenv()["RN_LEGACY_ARCH_OUTPUT_FILE_NAME"]
if (outputFileName.isNullOrEmpty()) {
return true
}
val elements = roundEnv.getElementsAnnotatedWith(LegacyArchitecture::class.java)
val classes: MutableList<String> = mutableListOf()
elements.forEach { element ->
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
}
}