mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Format Java code in xplat/js/react-native-github
Summary: This diff formats the Java class files inside xplat/js/react-native-github. Since google-java-format was enabled in D16071401 we want to codemode the existing code so that users don't have to deal with formatter lint noise at diff-time. ```arc f --paths-cmd 'hg files -I "**/*.java"'``` drop-conflicts Reviewed By: cpojer Differential Revision: D16071725 fbshipit-source-id: fc6e3852e45742c109f0c5ac4065d64201c74204
This commit is contained in:
committed by
Facebook Github Bot
parent
61e95e5cbf
commit
6c0f73b322
+22
-24
@@ -1,27 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
|
||||
* directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.facebook.react.common.build.ReactBuildConfig;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.facebook.react.common.build.ReactBuildConfig;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Class responsible for holding all the {@link JavaScriptModule}s. Uses Java proxy objects
|
||||
* to dispatch method calls on JavaScriptModules to the bridge using the corresponding
|
||||
* module and method ids so the proper function is executed in JavaScript.
|
||||
* Class responsible for holding all the {@link JavaScriptModule}s. Uses Java proxy objects to
|
||||
* dispatch method calls on JavaScriptModules to the bridge using the corresponding module and
|
||||
* method ids so the proper function is executed in JavaScript.
|
||||
*/
|
||||
public final class JavaScriptModuleRegistry {
|
||||
private final HashMap<Class<? extends JavaScriptModule>, JavaScriptModule> mModuleInstances;
|
||||
@@ -31,17 +28,18 @@ public final class JavaScriptModuleRegistry {
|
||||
}
|
||||
|
||||
public synchronized <T extends JavaScriptModule> T getJavaScriptModule(
|
||||
CatalystInstance instance,
|
||||
Class<T> moduleInterface) {
|
||||
CatalystInstance instance, Class<T> moduleInterface) {
|
||||
JavaScriptModule module = mModuleInstances.get(moduleInterface);
|
||||
if (module != null) {
|
||||
return (T) module;
|
||||
}
|
||||
|
||||
JavaScriptModule interfaceProxy = (JavaScriptModule) Proxy.newProxyInstance(
|
||||
moduleInterface.getClassLoader(),
|
||||
new Class[]{moduleInterface},
|
||||
new JavaScriptModuleInvocationHandler(instance, moduleInterface));
|
||||
JavaScriptModule interfaceProxy =
|
||||
(JavaScriptModule)
|
||||
Proxy.newProxyInstance(
|
||||
moduleInterface.getClassLoader(),
|
||||
new Class[] {moduleInterface},
|
||||
new JavaScriptModuleInvocationHandler(instance, moduleInterface));
|
||||
mModuleInstances.put(moduleInterface, interfaceProxy);
|
||||
return (T) interfaceProxy;
|
||||
}
|
||||
@@ -52,8 +50,7 @@ public final class JavaScriptModuleRegistry {
|
||||
private @Nullable String mName;
|
||||
|
||||
public JavaScriptModuleInvocationHandler(
|
||||
CatalystInstance catalystInstance,
|
||||
Class<? extends JavaScriptModule> moduleInterface) {
|
||||
CatalystInstance catalystInstance, Class<? extends JavaScriptModule> moduleInterface) {
|
||||
mCatalystInstance = catalystInstance;
|
||||
mModuleInterface = moduleInterface;
|
||||
|
||||
@@ -62,8 +59,10 @@ public final class JavaScriptModuleRegistry {
|
||||
for (Method method : mModuleInterface.getDeclaredMethods()) {
|
||||
if (!methodNames.add(method.getName())) {
|
||||
throw new AssertionError(
|
||||
"Method overloading is unsupported: " + mModuleInterface.getName() +
|
||||
"#" + method.getName());
|
||||
"Method overloading is unsupported: "
|
||||
+ mModuleInterface.getName()
|
||||
+ "#"
|
||||
+ method.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,10 +86,9 @@ public final class JavaScriptModuleRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object invoke(Object proxy, Method method, @Nullable Object[] args) throws Throwable {
|
||||
NativeArray jsArgs = args != null
|
||||
? Arguments.fromJavaArgs(args)
|
||||
: new WritableNativeArray();
|
||||
public @Nullable Object invoke(Object proxy, Method method, @Nullable Object[] args)
|
||||
throws Throwable {
|
||||
NativeArray jsArgs = args != null ? Arguments.fromJavaArgs(args) : new WritableNativeArray();
|
||||
mCatalystInstance.callFunction(getJSModuleName(), method.getName(), jsArgs);
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user