mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-01 06:22:39 +08:00
Find hasConstant status via preprocessing
Reviewed By: javache Differential Revision: D4867563 fbshipit-source-id: 66e4505d142fc4776cd727a025005b43d500b167
This commit is contained in:
committed by
Facebook Github Bot
parent
ea89af53cd
commit
8e382fd006
@@ -14,8 +14,8 @@ java_annotation_processor(
|
||||
java_library(
|
||||
name = "processing-lib",
|
||||
srcs = glob(["*.java"]),
|
||||
source = "7",
|
||||
target = "7",
|
||||
source = "8",
|
||||
target = "8",
|
||||
deps = [
|
||||
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
|
||||
react_native_dep("third-party/java/javapoet:javapoet"),
|
||||
|
||||
@@ -10,7 +10,9 @@ 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.AnnotationMirror;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.MirroredTypesException;
|
||||
@@ -19,6 +21,7 @@ import javax.lang.model.util.Elements;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -149,19 +152,32 @@ public class ReactModuleSpecProcessor extends AbstractProcessor {
|
||||
String keyString = nativeModule + ".class";
|
||||
|
||||
TypeElement typeElement = mElements.getTypeElement(nativeModule);
|
||||
if (typeElement == null) {
|
||||
throw new ReactModuleSpecException(
|
||||
keyString + " not found by ReactModuleSpecProcessor. " +
|
||||
"Did you misspell the module?");
|
||||
}
|
||||
ReactModule reactModule = typeElement.getAnnotation(ReactModule.class);
|
||||
if (reactModule == null) {
|
||||
throw new ReactModuleSpecException(
|
||||
keyString + " not found by ReactModuleSpecProcessor. " +
|
||||
"Did you forget to add the @ReactModule annotation to the native module?");
|
||||
}
|
||||
|
||||
List<? extends Element> elements = typeElement.getEnclosedElements();
|
||||
boolean hasConstants = false;
|
||||
if (elements != null) {
|
||||
hasConstants = elements.stream()
|
||||
.anyMatch((Element m) -> m.getKind() == ElementKind.METHOD && m.getSimpleName().contentEquals("getConstants"));
|
||||
}
|
||||
|
||||
String valueString = new StringBuilder()
|
||||
.append("new ReactModuleInfo(")
|
||||
.append("\"").append(reactModule.name()).append("\"").append(", ")
|
||||
.append(reactModule.canOverrideExistingModule()).append(", ")
|
||||
.append(reactModule.supportsWebWorkers()).append(", ")
|
||||
.append(reactModule.needsEagerInit()).append(", ")
|
||||
.append(reactModule.hasConstants())
|
||||
.append(hasConstants)
|
||||
.append(")")
|
||||
.toString();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user