Make ReactModuleInfoProvider use string keys

Summary: `ReactModuleInfoProvider` was using `Class` as the keys. This would make the classes to load. This change makes the map use canonicalName Strings of the classes, removing the need for the classes to load at this point.

Reviewed By: achen1

Differential Revision: D8944078

fbshipit-source-id: 4aa562d74d6ad3ebb9962b581d4e2f5e89d47ca6
This commit is contained in:
Ram N 2018-07-27 22:41:38 -07:00 committed by Facebook Github Bot
parent 9176fc00b5
commit d891ee1dee
3 changed files with 7 additions and 7 deletions

View File

@ -49,12 +49,12 @@ public class NativeModuleRegistryBuilder {
if (reactPackage instanceof LazyReactPackage) {
LazyReactPackage lazyReactPackage = (LazyReactPackage) reactPackage;
List<ModuleSpec> moduleSpecs = lazyReactPackage.getNativeModules(mReactApplicationContext);
Map<Class, ReactModuleInfo> reactModuleInfoMap = lazyReactPackage.getReactModuleInfoProvider()
.getReactModuleInfos();
Map<String, ReactModuleInfo> reactModuleInfoMap =
lazyReactPackage.getReactModuleInfoProvider().getReactModuleInfos();
for (ModuleSpec moduleSpec : moduleSpecs) {
Class<? extends NativeModule> type = moduleSpec.getType();
ReactModuleInfo reactModuleInfo = reactModuleInfoMap.get(type);
ReactModuleInfo reactModuleInfo = reactModuleInfoMap.get(type.getCanonicalName());
ModuleHolder moduleHolder;
if (reactModuleInfo == null) {
if (BaseJavaModule.class.isAssignableFrom(type)) {

View File

@ -12,5 +12,5 @@ import java.util.Map;
*/
public interface ReactModuleInfoProvider {
Map<Class, ReactModuleInfo> getReactModuleInfos();
Map<String, ReactModuleInfo> getReactModuleInfos();
}

View File

@ -62,7 +62,7 @@ public class ReactModuleSpecProcessor extends AbstractProcessor {
private static final TypeName COLLECTIONS_TYPE = ParameterizedTypeName.get(Collections.class);
private static final TypeName MAP_TYPE = ParameterizedTypeName.get(
Map.class,
Class.class,
String.class,
ReactModuleInfo.class);
private static final TypeName INSTANTIATED_MAP_TYPE = ParameterizedTypeName.get(HashMap.class);
@ -155,7 +155,7 @@ public class ReactModuleSpecProcessor extends AbstractProcessor {
builder.addStatement("$T map = new $T()", MAP_TYPE, INSTANTIATED_MAP_TYPE);
for (String nativeModule : nativeModules) {
String keyString = nativeModule + ".class";
String keyString = nativeModule;
TypeElement typeElement = mElements.getTypeElement(nativeModule);
if (typeElement == null) {
@ -191,7 +191,7 @@ public class ReactModuleSpecProcessor extends AbstractProcessor {
.append(")")
.toString();
builder.addStatement("map.put(" + keyString + ", " + valueString + ")");
builder.addStatement("map.put(\"" + keyString + "\", " + valueString + ")");
}
builder.addStatement("return map");
}