Skip to content

Commit fed5b6e

Browse files
axe-fbfacebook-github-bot
authored andcommitted
Make C++ RN Modules explicitly specify that they are C++ modules
Summary: Currently `ReactModuleSpecProcessor` looks at each of the modules, and sees if the module inherits from `CxxModuleWrapper` to see if it is a C++ module or not. With this change, we now require C++ modules to explicitly specify that they are C++ modules, instead of doing annotation processing magic. Also note that annotation processor do not work with interfaces but with classes only, so this also removes the dependency of the annotation processor from the bridge buck target. Reviewed By: achen1 Differential Revision: D9597352 fbshipit-source-id: fd847ac382699d2ab78f7d7c6e2dbd7c60d3f0c4
1 parent d283d8f commit fed5b6e

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,10 @@
4242
* correct annotation is not included
4343
*/
4444
boolean hasConstants() default true;
45+
46+
/**
47+
* Indicates if a module is a C++ module or a Java Module
48+
* @return
49+
*/
50+
boolean isCxxModule() default false;
4551
}

ReactAndroid/src/main/java/com/facebook/react/module/processing/BUCK

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ rn_java_library(
2222
react_native_dep("third-party/java/javapoet:javapoet"),
2323
react_native_dep("third-party/java/jsr-305:jsr-305"),
2424
react_native_target("java/com/facebook/react/module/annotations:annotations"),
25-
react_native_target("java/com/facebook/react/bridge:bridge"),
2625
react_native_target("java/com/facebook/react/module/model:model"),
2726
],
2827
)

ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,28 @@
55

66
package com.facebook.react.module.processing;
77

8-
import com.facebook.react.bridge.CxxModuleWrapper;
8+
import static javax.lang.model.element.Modifier.PUBLIC;
9+
import static javax.tools.Diagnostic.Kind.ERROR;
10+
11+
import com.facebook.infer.annotation.SuppressFieldNotInitialized;
12+
import com.facebook.react.module.annotations.ReactModule;
13+
import com.facebook.react.module.annotations.ReactModuleList;
14+
import com.facebook.react.module.model.ReactModuleInfo;
15+
import com.facebook.react.module.model.ReactModuleInfoProvider;
16+
import com.squareup.javapoet.ClassName;
17+
import com.squareup.javapoet.CodeBlock;
18+
import com.squareup.javapoet.JavaFile;
19+
import com.squareup.javapoet.MethodSpec;
20+
import com.squareup.javapoet.ParameterizedTypeName;
21+
import com.squareup.javapoet.TypeName;
22+
import com.squareup.javapoet.TypeSpec;
23+
import java.io.IOException;
24+
import java.util.ArrayList;
25+
import java.util.Collections;
26+
import java.util.HashMap;
27+
import java.util.List;
28+
import java.util.Map;
29+
import java.util.Set;
930
import javax.annotation.processing.AbstractProcessor;
1031
import javax.annotation.processing.Filer;
1132
import javax.annotation.processing.Messager;
@@ -158,8 +179,6 @@ private CodeBlock getCodeBlockForReactModuleInfos(List<String> nativeModules)
158179
} else {
159180
builder.addStatement("$T map = new $T()", MAP_TYPE, INSTANTIATED_MAP_TYPE);
160181

161-
TypeMirror cxxModuleWrapperTypeMirror = mElements.getTypeElement(CxxModuleWrapper.class.getName()).asType();
162-
163182
for (String nativeModule : nativeModules) {
164183
String keyString = nativeModule;
165184

@@ -189,15 +208,13 @@ private CodeBlock getCodeBlockForReactModuleInfos(List<String> nativeModules)
189208
name -> name.contentEquals("getConstants") || name.contentEquals("getTypedExportedConstants"));
190209
}
191210

192-
boolean isCxxModule = mTypes.isAssignable(typeElement.asType(), cxxModuleWrapperTypeMirror);
193-
194211
String valueString = new StringBuilder()
195212
.append("new ReactModuleInfo(")
196213
.append("\"").append(reactModule.name()).append("\"").append(", ")
197214
.append(reactModule.canOverrideExistingModule()).append(", ")
198215
.append(reactModule.needsEagerInit()).append(", ")
199216
.append(hasConstants).append(", ")
200-
.append(isCxxModule)
217+
.append(reactModule.isCxxModule())
201218
.append(")")
202219
.toString();
203220

0 commit comments

Comments
 (0)