Skip to content

Commit

Permalink
remove all @ReactModule runtime annotation processing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aaronechiu authored and Facebook Github Bot 5 committed Aug 24, 2016
1 parent 1557325 commit 2889343
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
Expand Up @@ -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;
Expand All @@ -24,6 +17,10 @@
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;

Expand Down Expand Up @@ -465,17 +462,6 @@ public final void writeConstantsField(JsonWriter writer, String fieldName) throw
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
Expand All @@ -499,11 +485,7 @@ public void onCatalystInstanceDestroy() {

@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) {
Expand Down
Expand Up @@ -9,19 +9,18 @@

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;
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;

Expand Down Expand Up @@ -77,20 +76,31 @@ public void testSimpleContextConstructor() {
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";
}
}
}

0 comments on commit 2889343

Please sign in to comment.