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
@@ -11,6 +11,9 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Java {@link ArrayList} backed implementation of {@link ReadableArray} and {@link WritableArray}
|
||||
* Instances of this class SHOULD NOT be used for communication between java and JS, use instances
|
||||
@@ -95,7 +98,7 @@ public class JavaOnlyArray implements ReadableArray, WritableArray {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(int index) {
|
||||
public @Nullable String getString(int index) {
|
||||
return (String) mBackingList.get(index);
|
||||
}
|
||||
|
||||
@@ -115,12 +118,12 @@ public class JavaOnlyArray implements ReadableArray, WritableArray {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dynamic getDynamic(int index) {
|
||||
public @Nonnull Dynamic getDynamic(int index) {
|
||||
return DynamicFromArray.create(this, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableType getType(int index) {
|
||||
public @Nonnull ReadableType getType(int index) {
|
||||
Object object = mBackingList.get(index);
|
||||
|
||||
if (object == null) {
|
||||
@@ -157,17 +160,17 @@ public class JavaOnlyArray implements ReadableArray, WritableArray {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushString(String value) {
|
||||
public void pushString(@Nonnull String value) {
|
||||
mBackingList.add(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushArray(WritableArray array) {
|
||||
public void pushArray(@Nullable WritableArray array) {
|
||||
mBackingList.add(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushMap(WritableMap map) {
|
||||
public void pushMap(@Nonnull WritableMap map) {
|
||||
mBackingList.add(map);
|
||||
}
|
||||
|
||||
@@ -177,7 +180,7 @@ public class JavaOnlyArray implements ReadableArray, WritableArray {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Object> toArrayList() {
|
||||
public @Nonnull ArrayList<Object> toArrayList() {
|
||||
return new ArrayList<Object>(mBackingList);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user