mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
nullable annotations to ReadableMap, WritableMap, ReadableArray, Writable. (#23329)
Summary: Kotlin is getting traction and more developers write RN native modules in it. This PR adds nullable annotations to help with Kotlin null inference and improve developer experience. Also it'll help checking code quality using lint. I skimmed through JavaOnlyMap.java, JavaOnlyArray.java, ReadableNativeArray.java, ReadableNativeMap.java, WritableNativeArray.java and WritableNativeMap.java to infer nullability. This is breaking change to Kotlin code. [Android] [Changed] - Add nullable annotations to ReadableMap, WritableMap, ReadableArray, Writable. Pull Request resolved: https://github.com/facebook/react-native/pull/23329 Differential Revision: D14002571 Pulled By: cpojer fbshipit-source-id: 899d8b3b0a5dad43e8300e6c4ea4208cca0f01a9
This commit is contained in:
committed by
Facebook Github Bot
parent
d002d30325
commit
b640b6faf7
@@ -7,10 +7,14 @@
|
||||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Implementation of a write-only map stored in native memory. Use
|
||||
* {@link Arguments#createMap()} if you need to stub out creating this class in a test.
|
||||
@@ -23,19 +27,19 @@ public class WritableNativeMap extends ReadableNativeMap implements WritableMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public native void putBoolean(String key, boolean value);
|
||||
public native void putBoolean(@Nonnull String key, boolean value);
|
||||
@Override
|
||||
public native void putDouble(String key, double value);
|
||||
public native void putDouble(@Nonnull String key, double value);
|
||||
@Override
|
||||
public native void putInt(String key, int value);
|
||||
public native void putInt(@Nonnull String key, int value);
|
||||
@Override
|
||||
public native void putString(String key, String value);
|
||||
public native void putString(@Nonnull String key, @Nonnull String value);
|
||||
@Override
|
||||
public native void putNull(String key);
|
||||
public native void putNull(@NonNull String key);
|
||||
|
||||
// Note: this consumes the map so do not reuse it.
|
||||
@Override
|
||||
public void putMap(String key, WritableMap value) {
|
||||
public void putMap(@Nonnull String key, @Nonnull WritableMap value) {
|
||||
Assertions.assertCondition(
|
||||
value == null || value instanceof WritableNativeMap, "Illegal type provided");
|
||||
putNativeMap(key, (WritableNativeMap) value);
|
||||
@@ -43,7 +47,7 @@ public class WritableNativeMap extends ReadableNativeMap implements WritableMap
|
||||
|
||||
// Note: this consumes the map so do not reuse it.
|
||||
@Override
|
||||
public void putArray(String key, WritableArray value) {
|
||||
public void putArray(@Nonnull String key, @Nonnull WritableArray value) {
|
||||
Assertions.assertCondition(
|
||||
value == null || value instanceof WritableNativeArray, "Illegal type provided");
|
||||
putNativeArray(key, (WritableNativeArray) value);
|
||||
@@ -51,7 +55,7 @@ public class WritableNativeMap extends ReadableNativeMap implements WritableMap
|
||||
|
||||
// Note: this **DOES NOT** consume the source map
|
||||
@Override
|
||||
public void merge(ReadableMap source) {
|
||||
public void merge(@Nonnull ReadableMap source) {
|
||||
Assertions.assertCondition(source instanceof ReadableNativeMap, "Illegal type provided");
|
||||
mergeNativeMap((ReadableNativeMap) source);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user