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
This commit is contained in:
Ram N 2018-09-04 16:30:59 -07:00 committed by Facebook Github Bot
parent d283d8f80c
commit fed5b6e27a
3 changed files with 29 additions and 7 deletions

View File

@ -42,4 +42,10 @@ public @interface ReactModule {
* correct annotation is not included
*/
boolean hasConstants() default true;
/**
* Indicates if a module is a C++ module or a Java Module
* @return
*/
boolean isCxxModule() default false;
}

View File

@ -22,7 +22,6 @@ rn_java_library(
react_native_dep("third-party/java/javapoet:javapoet"),
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react/module/annotations:annotations"),
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/module/model:model"),
],
)

View File

@ -5,7 +5,28 @@
package com.facebook.react.module.processing;
import com.facebook.react.bridge.CxxModuleWrapper;
import static javax.lang.model.element.Modifier.PUBLIC;
import static javax.tools.Diagnostic.Kind.ERROR;
import com.facebook.infer.annotation.SuppressFieldNotInitialized;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.module.annotations.ReactModuleList;
import com.facebook.react.module.model.ReactModuleInfo;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
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;
@ -158,8 +179,6 @@ public class ReactModuleSpecProcessor extends AbstractProcessor {
} else {
builder.addStatement("$T map = new $T()", MAP_TYPE, INSTANTIATED_MAP_TYPE);
TypeMirror cxxModuleWrapperTypeMirror = mElements.getTypeElement(CxxModuleWrapper.class.getName()).asType();
for (String nativeModule : nativeModules) {
String keyString = nativeModule;
@ -189,15 +208,13 @@ public class ReactModuleSpecProcessor extends AbstractProcessor {
name -> name.contentEquals("getConstants") || name.contentEquals("getTypedExportedConstants"));
}
boolean isCxxModule = mTypes.isAssignable(typeElement.asType(), cxxModuleWrapperTypeMirror);
String valueString = new StringBuilder()
.append("new ReactModuleInfo(")
.append("\"").append(reactModule.name()).append("\"").append(", ")
.append(reactModule.canOverrideExistingModule()).append(", ")
.append(reactModule.needsEagerInit()).append(", ")
.append(hasConstants).append(", ")
.append(isCxxModule)
.append(reactModule.isCxxModule())
.append(")")
.toString();