Skip to content

Commit

Permalink
Make all annotation processors derive from ProcessorBase (#39360)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #39360

X-link: facebook/litho#958

Reviewed By: MonaHashem

Differential Revision: D49113071

fbshipit-source-id: f762032e0f0b4a1566b0947fe3a24eb32be5795a
  • Loading branch information
ianlevesque authored and facebook-github-bot committed Oct 4, 2023
1 parent c4110d0 commit fea445e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/react-native/ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ android {
res.srcDirs = ["src/main/res/devsupport", "src/main/res/shell", "src/main/res/views/modal", "src/main/res/views/uimanager"]
java {
srcDirs = ["src/main/java", "src/main/libraries/soloader/java", "src/main/jni/first-party/fb/jni/java"]
exclude("com/facebook/annotationprocessors")
exclude("com/facebook/react/processing")
exclude("com/facebook/react/module/processing")
}
Expand Down Expand Up @@ -770,6 +771,7 @@ dependencies {
api(libs.okhttp3.urlconnection)
api(libs.okhttp3)
api(libs.okio)
compileOnly(libs.javax.annotation.api)
api(libs.javax.inject)

// It's up to the consumer to decide if hermes should be included or not.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.annotationprocessors.common;

import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.TypeElement;

public abstract class ProcessorBase extends AbstractProcessor {

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
return processImpl(annotations, roundEnv);
}

protected abstract boolean processImpl(
Set<? extends TypeElement> annotations, RoundEnvironment roundEnv);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static javax.lang.model.element.Modifier.PUBLIC;
import static javax.tools.Diagnostic.Kind.ERROR;

import com.facebook.annotationprocessors.common.ProcessorBase;
import com.facebook.infer.annotation.SuppressFieldNotInitialized;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.module.annotations.ReactModuleList;
Expand All @@ -29,7 +30,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager;
import javax.annotation.processing.ProcessingEnvironment;
Expand All @@ -55,7 +55,7 @@
"com.facebook.react.module.annotations.ReactModuleList",
})
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public class ReactModuleSpecProcessor extends AbstractProcessor {
public class ReactModuleSpecProcessor extends ProcessorBase {

private static final TypeName COLLECTIONS_TYPE = ParameterizedTypeName.get(Collections.class);
private static final TypeName MAP_TYPE =
Expand All @@ -78,7 +78,7 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
}

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
public boolean processImpl(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Set<? extends Element> reactModuleListElements =
roundEnv.getElementsAnnotatedWith(ReactModuleList.class);
for (Element reactModuleListElement : reactModuleListElements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static javax.tools.Diagnostic.Kind.ERROR;
import static javax.tools.Diagnostic.Kind.WARNING;

import com.facebook.annotationprocessors.common.ProcessorBase;
import com.facebook.infer.annotation.SuppressFieldNotInitialized;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.DynamicFromObject;
Expand Down Expand Up @@ -40,7 +41,6 @@
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager;
import javax.annotation.processing.ProcessingEnvironment;
Expand All @@ -66,7 +66,7 @@
*/
@SupportedAnnotationTypes("com.facebook.react.uimanager.annotations.ReactPropertyHolder")
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public class ReactPropertyProcessor extends AbstractProcessor {
public class ReactPropertyProcessor extends ProcessorBase {
private static final Map<TypeName, String> DEFAULT_TYPES;
private static final Set<TypeName> BOXED_PRIMITIVES;

Expand Down Expand Up @@ -141,7 +141,7 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
}

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
public boolean processImpl(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
// Clear properties from previous rounds
mClasses.clear();

Expand Down
3 changes: 3 additions & 0 deletions packages/react-native/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fbjni = "0.5.1"
flipper = "0.201.0"
fresco = "3.0.0"
infer-annotation = "0.18.0"
javax-annotation-api = "1.3.2"
javax-inject = "1"
jsr305 = "3.0.2"
junit = "4.13.2"
Expand Down Expand Up @@ -66,6 +67,8 @@ okhttp3-urlconnection = { module = "com.squareup.okhttp3:okhttp-urlconnection",
okhttp3 = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
javax-inject = { module = "javax.inject:javax.inject", version.ref = "javax-inject" }
javax-annotation-api = { module = "javax.annotation:javax.annotation-api", version.ref = "javax-annotation-api" }

junit = {module = "junit:junit", version.ref = "junit" }
assertj = {module = "org.assertj:assertj-core", version.ref = "assertj" }
mockito = {module = "org.mockito:mockito-inline", version.ref = "mockito" }
Expand Down

0 comments on commit fea445e

Please sign in to comment.