forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create initial version of ReactLegacyArchitectureProcessor (facebook#…
…49570) Summary: This diff creates a initial version of the annotation processor to output the list of types that are annotated with LegacyArchitecture changelog: [internal] internal Reviewed By: cortinico Differential Revision: D69929875
- Loading branch information
1 parent
4e308dc
commit cf7a9cb
Showing
1 changed file
with
32 additions
and
6 deletions.
There are no files selected for viewing
38 changes: 32 additions & 6 deletions
38
...Android/src/main/java/com/facebook/react/processing/ReactLegacyArchitectureProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,52 @@ | ||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. | ||
/* | ||
* 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 { | ||
|
||
public ReactLegacyArchitectureProcessor() { | ||
super(); | ||
} | ||
|
||
@Override | ||
protected boolean processImpl(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | ||
// Do nothing for now | ||
String outputFileName = System.getenv().get("RN_LEGACY_ARCH_OUTPUT_FILE_NAME"); | ||
if (outputFileName == null || outputFileName.trim().isEmpty()) { | ||
return true; | ||
} | ||
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(LegacyArchitecture.class); | ||
List<String> 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; | ||
} | ||
} |