remove all @ReactModule runtime annotation processing
Summary: Runtime annotation processing uses reflection which is slow. We'll use build time annotation processing instead and create at build time static ModuleInfo classes which have "name", "canOverrideExistingModule", "supportsWebWorkers", "needsEagerInit". Reviewed By: lexs Differential Revision: D3752243 fbshipit-source-id: 3518c6f38087d8799a61410864007041389c0e15
This commit is contained in:
parent
1557325e4a
commit
288934398b
|
@ -9,13 +9,6 @@
|
|||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.annotations.ReactModule;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.systrace.Systrace;
|
||||
import com.facebook.systrace.SystraceMessage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -24,6 +17,10 @@ import java.lang.reflect.Method;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.systrace.Systrace;
|
||||
import com.facebook.systrace.SystraceMessage;
|
||||
|
||||
import static com.facebook.infer.annotation.Assertions.assertNotNull;
|
||||
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
|
||||
|
@ -465,17 +462,6 @@ public abstract class BaseJavaModule implements NativeModule {
|
|||
writer.endObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
ReactModule module = getClass().getAnnotation(ReactModule.class);
|
||||
if (module == null) {
|
||||
throw new IllegalStateException(
|
||||
getClass().getSimpleName() +
|
||||
"module must have @ReactModule annotation or override getName()");
|
||||
}
|
||||
return module.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
// do nothing
|
||||
|
@ -499,11 +485,7 @@ public abstract class BaseJavaModule implements NativeModule {
|
|||
|
||||
@Override
|
||||
public boolean supportsWebWorkers() {
|
||||
ReactModule module = getClass().getAnnotation(ReactModule.class);
|
||||
if (module == null) {
|
||||
return false;
|
||||
}
|
||||
return module.supportsWebWorkers();
|
||||
return false;
|
||||
}
|
||||
|
||||
private static char paramTypeToChar(Class paramClass) {
|
||||
|
|
|
@ -9,9 +9,11 @@
|
|||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import com.facebook.react.common.build.ReactBuildConfig;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
|
||||
|
@ -19,9 +21,6 @@ import org.powermock.modules.junit4.rule.PowerMockRule;
|
|||
import org.powermock.reflect.Whitebox;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import com.facebook.react.bridge.annotations.ReactModule;
|
||||
import com.facebook.react.common.build.ReactBuildConfig;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
@ -77,20 +76,31 @@ public class ModuleSpecTest {
|
|||
assertThat(contextModule.getReactApplicationContext()).isSameAs(context);
|
||||
}
|
||||
|
||||
@ReactModule(name = "ComplexModule")
|
||||
public static class ComplexModule extends BaseJavaModule {
|
||||
|
||||
public ComplexModule(int a, int b) {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "ComplexModule";
|
||||
}
|
||||
}
|
||||
|
||||
@ReactModule(name = "SimpleModule")
|
||||
public static class SimpleModule extends BaseJavaModule {
|
||||
|
||||
public String getName() {
|
||||
return "SimpleModule";
|
||||
}
|
||||
}
|
||||
|
||||
@ReactModule(name = "SimpleContextModule")
|
||||
public static class SimpleContextModule extends ReactContextBaseJavaModule {
|
||||
|
||||
public SimpleContextModule(ReactApplicationContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "SimpleContextModule";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue