Find hasConstant status via preprocessing
Reviewed By: javache Differential Revision: D4867563 fbshipit-source-id: 66e4505d142fc4776cd727a025005b43d500b167
This commit is contained in:
parent
ea89af53cd
commit
8e382fd006
|
@ -71,7 +71,7 @@ import com.facebook.react.uimanager.UIManagerModule;
|
|||
* isolates us from the problems that may be caused by concurrent updates of animated graph while UI
|
||||
* thread is "executing" the animation loop.
|
||||
*/
|
||||
@ReactModule(name = NativeAnimatedModule.NAME, hasConstants = false)
|
||||
@ReactModule(name = NativeAnimatedModule.NAME)
|
||||
public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
||||
OnBatchCompleteListener, LifecycleEventListener {
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import com.facebook.react.module.annotations.ReactModule;
|
|||
|
||||
// This module is being called only by Java via the static method "poke" that
|
||||
// requires it to alreay be initialized, thus we eagerly initialize this module
|
||||
@ReactModule(name = "JSCSamplingProfiler", needsEagerInit = true, hasConstants = false)
|
||||
@ReactModule(name = "JSCSamplingProfiler", needsEagerInit = true)
|
||||
public class JSCSamplingProfiler extends ReactContextBaseJavaModule {
|
||||
public interface SamplingProfiler extends JavaScriptModule {
|
||||
void poke(int token);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ import com.facebook.react.bridge.WritableMap;
|
|||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
|
||||
|
||||
@ReactModule(name = AppStateModule.NAME, hasConstants = false)
|
||||
@ReactModule(name = AppStateModule.NAME)
|
||||
public class AppStateModule extends ReactContextBaseJavaModule
|
||||
implements LifecycleEventListener {
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import com.facebook.react.module.annotations.ReactModule;
|
|||
/**
|
||||
* Native module that handles device hardware events like hardware back presses.
|
||||
*/
|
||||
@ReactModule(name = "DeviceEventManager", hasConstants = false)
|
||||
@ReactModule(name = "DeviceEventManager")
|
||||
public class DeviceEventManagerModule extends ReactContextBaseJavaModule {
|
||||
|
||||
@SupportsWebWorkers
|
||||
|
|
|
@ -23,7 +23,7 @@ import com.facebook.react.common.JavascriptException;
|
|||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
|
||||
@ReactModule(name = ExceptionsManagerModule.NAME, hasConstants = false)
|
||||
@ReactModule(name = ExceptionsManagerModule.NAME)
|
||||
public class ExceptionsManagerModule extends BaseJavaModule {
|
||||
|
||||
protected static final String NAME = "ExceptionsManager";
|
||||
|
|
|
@ -20,7 +20,7 @@ import com.facebook.react.module.annotations.ReactModule;
|
|||
* Simple native module that allows JS to notify native of having completed some task work, so that
|
||||
* it can e.g. release any resources, stop timers etc.
|
||||
*/
|
||||
@ReactModule(name = HeadlessJsTaskSupportModule.MODULE_NAME, hasConstants = false)
|
||||
@ReactModule(name = HeadlessJsTaskSupportModule.MODULE_NAME)
|
||||
public class HeadlessJsTaskSupportModule extends ReactContextBaseJavaModule {
|
||||
|
||||
protected static final String MODULE_NAME = "HeadlessJsTaskSupport";
|
||||
|
|
|
@ -42,7 +42,7 @@ import com.facebook.react.module.annotations.ReactModule;
|
|||
/**
|
||||
* Native module for JS timer execution. Timers fire on frame boundaries.
|
||||
*/
|
||||
@ReactModule(name = Timing.NAME, supportsWebWorkers = true, hasConstants = false)
|
||||
@ReactModule(name = Timing.NAME, supportsWebWorkers = true)
|
||||
public final class Timing extends ReactContextBaseJavaModule implements LifecycleEventListener,
|
||||
OnExecutorUnregisteredListener, HeadlessJsTaskEventListener {
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
|
|||
* Module that records debug information during transitions (animated navigation events such as
|
||||
* going from one screen to another).
|
||||
*/
|
||||
@ReactModule(name = AnimationsDebugModule.NAME, hasConstants = false)
|
||||
@ReactModule(name = AnimationsDebugModule.NAME)
|
||||
public class AnimationsDebugModule extends ReactContextBaseJavaModule {
|
||||
|
||||
protected static final String NAME = "AnimationsDebugModule";
|
||||
|
|
|
@ -33,7 +33,7 @@ import static com.facebook.react.modules.storage.ReactDatabaseSupplier.KEY_COLUM
|
|||
import static com.facebook.react.modules.storage.ReactDatabaseSupplier.TABLE_CATALYST;
|
||||
import static com.facebook.react.modules.storage.ReactDatabaseSupplier.VALUE_COLUMN;
|
||||
|
||||
@ReactModule(name = AsyncStorageModule.NAME, hasConstants = false)
|
||||
@ReactModule(name = AsyncStorageModule.NAME)
|
||||
public final class AsyncStorageModule
|
||||
extends ReactContextBaseJavaModule implements ModuleDataCleaner.Cleanable {
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import com.facebook.react.module.annotations.ReactModule;
|
|||
*
|
||||
* Example returned owner hierarchy: ['RootView', 'Dialog', 'TitleView', 'Text']
|
||||
*/
|
||||
@ReactModule(name = "DebugComponentOwnershipModule", hasConstants = false)
|
||||
@ReactModule(name = "DebugComponentOwnershipModule")
|
||||
public class DebugComponentOwnershipModule extends ReactContextBaseJavaModule {
|
||||
|
||||
public interface RCTDebugComponentOwnership extends JavaScriptModule {
|
||||
|
|
Loading…
Reference in New Issue