Annotate core classes of Fabric with NonNull and Nullable annotations

Summary:
This diff annotates core classes of Fabric with NonNull and Nullable annotations, this will help analysis of nullability plus improving integration with Kotlin clients

Changelog: Add NonNull annotation to Fabric core classes

Reviewed By: shergin

Differential Revision: D18010918

fbshipit-source-id: 40fe68470b97cdf740f52dfeb9130465aab5e6df
This commit is contained in:
David Vacca
2019-10-25 15:11:51 -07:00
committed by Facebook Github Bot
parent a58fcbff0b
commit 619e27e9a1
7 changed files with 35 additions and 27 deletions
@@ -8,6 +8,7 @@
package com.facebook.react.fabric;
import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.JavaScriptContextHolder;
@@ -40,7 +41,8 @@ public class Binding {
ComponentFactoryDelegate componentsRegistry,
Object reactNativeConfig);
public native void startSurface(int surfaceId, String moduleName, NativeMap initialProps);
public native void startSurface(
int surfaceId, @NonNull String moduleName, @NonNull NativeMap initialProps);
public native void startSurfaceWithConstraints(
int surfaceId,
@@ -61,12 +63,12 @@ public class Binding {
int surfaceId, float minWidth, float maxWidth, float minHeight, float maxHeight);
public void register(
JavaScriptContextHolder jsContext,
FabricUIManager fabricUIManager,
EventBeatManager eventBeatManager,
MessageQueueThread jsMessageQueueThread,
ComponentFactoryDelegate componentFactoryDelegate,
ReactNativeConfig reactNativeConfig) {
@NonNull JavaScriptContextHolder jsContext,
@NonNull FabricUIManager fabricUIManager,
@NonNull EventBeatManager eventBeatManager,
@NonNull MessageQueueThread jsMessageQueueThread,
@NonNull ComponentFactoryDelegate componentFactoryDelegate,
@NonNull ReactNativeConfig reactNativeConfig) {
fabricUIManager.setBinding(this);
installFabricUIManager(
jsContext.get(),
@@ -7,6 +7,7 @@
package com.facebook.react.fabric;
import androidx.annotation.NonNull;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
@@ -17,7 +18,7 @@ public class ComponentFactoryDelegate {
FabricSoLoader.staticInit();
}
@DoNotStrip private final HybridData mHybridData;
@NonNull @DoNotStrip private final HybridData mHybridData;
@DoNotStrip
private static native HybridData initHybrid();
@@ -7,6 +7,7 @@
package com.facebook.react.fabric;
import androidx.annotation.NonNull;
import java.util.HashMap;
import java.util.Map;
@@ -18,7 +19,7 @@ import java.util.Map;
*/
public class FabricComponents {
private static final Map<String, String> sComponentNames = new HashMap<>();
private static @NonNull final Map<String, String> sComponentNames = new HashMap<>();
static {
// TODO T31905686: unify component names between JS - Android - iOS - C++
@@ -7,6 +7,7 @@
package com.facebook.react.fabric;
import androidx.annotation.NonNull;
import com.facebook.react.bridge.JSIModuleProvider;
import com.facebook.react.bridge.JavaScriptContextHolder;
import com.facebook.react.bridge.ReactApplicationContext;
@@ -38,16 +39,16 @@ import com.facebook.systrace.Systrace;
public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
private final JavaScriptContextHolder mJSContext;
private final ReactApplicationContext mReactApplicationContext;
private final ComponentFactoryDelegate mComponentFactoryDelegate;
private final ReactNativeConfig mConfig;
@NonNull private final JavaScriptContextHolder mJSContext;
@NonNull private final ReactApplicationContext mReactApplicationContext;
@NonNull private final ComponentFactoryDelegate mComponentFactoryDelegate;
@NonNull private final ReactNativeConfig mConfig;
public FabricJSIModuleProvider(
ReactApplicationContext reactApplicationContext,
JavaScriptContextHolder jsContext,
ComponentFactoryDelegate componentFactoryDelegate,
ReactNativeConfig config) {
@NonNull ReactApplicationContext reactApplicationContext,
@NonNull JavaScriptContextHolder jsContext,
@NonNull ComponentFactoryDelegate componentFactoryDelegate,
@NonNull ReactNativeConfig config) {
mReactApplicationContext = reactApplicationContext;
mJSContext = jsContext;
mComponentFactoryDelegate = componentFactoryDelegate;
@@ -79,7 +80,7 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
return uiManager;
}
private FabricUIManager createUIManager(EventBeatManager eventBeatManager) {
private FabricUIManager createUIManager(@NonNull EventBeatManager eventBeatManager) {
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricJSIModuleProvider.createUIManager");
UIManagerModule nativeModule = mReactApplicationContext.getNativeModule(UIManagerModule.class);
@@ -7,20 +7,21 @@
package com.facebook.react.fabric;
import androidx.annotation.NonNull;
import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.modules.core.ChoreographerCompat;
public abstract class GuardedFrameCallback extends ChoreographerCompat.FrameCallback {
private final NativeModuleCallExceptionHandler mExceptionHandler;
@NonNull private final NativeModuleCallExceptionHandler mExceptionHandler;
@Deprecated
protected GuardedFrameCallback(ReactContext reactContext) {
protected GuardedFrameCallback(@NonNull ReactContext reactContext) {
this(reactContext.getExceptionHandler());
}
protected GuardedFrameCallback(NativeModuleCallExceptionHandler exceptionHandler) {
protected GuardedFrameCallback(@NonNull NativeModuleCallExceptionHandler exceptionHandler) {
mExceptionHandler = exceptionHandler;
}
@@ -7,6 +7,7 @@
package com.facebook.react.fabric;
import androidx.annotation.NonNull;
import com.facebook.proguard.annotations.DoNotStrip;
// This is a wrapper for the ReactNativeConfig object in C++
@@ -18,7 +19,7 @@ public interface ReactNativeConfig {
* @param param The string name of the parameter being requested.
*/
@DoNotStrip
boolean getBool(String param);
boolean getBool(@NonNull String param);
/**
* Get an integer param by string name. Default should be 0.
@@ -26,7 +27,7 @@ public interface ReactNativeConfig {
* @param param The string name of the parameter being requested.
*/
@DoNotStrip
int getInt64(String param);
int getInt64(@NonNull String param);
/**
* Get a string param by string name. Default should be "", empty string.
@@ -34,7 +35,7 @@ public interface ReactNativeConfig {
* @param param The string name of the parameter being requested.
*/
@DoNotStrip
String getString(String param);
String getString(@NonNull String param);
/**
* Get a double param by string name. Default should be 0.
@@ -42,5 +43,5 @@ public interface ReactNativeConfig {
* @param param The string name of the parameter being requested.
*/
@DoNotStrip
double getDouble(String param);
double getDouble(@NonNull String param);
}
@@ -8,6 +8,7 @@
package com.facebook.react.fabric;
import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.NativeMap;
@@ -36,10 +37,10 @@ public class StateWrapperImpl implements StateWrapper {
@Override
public native ReadableNativeMap getState();
public native void updateStateImpl(NativeMap map);
public native void updateStateImpl(@NonNull NativeMap map);
@Override
public void updateState(WritableMap map) {
public void updateState(@NonNull WritableMap map) {
updateStateImpl((NativeMap) map);
}
}