Skip to content

Commit b3fb22c

Browse files
tomballcopybara-github
authored andcommitted
Annotates IOSObjectArray for nullability.
PiperOrigin-RevId: 736318095
1 parent 1b51f28 commit b3fb22c

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

jre_emul/Classes/IOSObjectArray.h

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@
2424

2525
#import "IOSArray.h"
2626

27+
#pragma clang diagnostic push
28+
#pragma GCC diagnostic ignored "-Wnullability-completeness"
29+
2730
@class IOSClass;
2831
@class IOSObjectArray;
2932

3033
/**
3134
* An emulation class that represents a Java object array. Like a Java array,
3235
* an IOSObjectArray is fixed-size but its elements are mutable.
3336
*/
34-
@interface IOSObjectArray<__covariant ObjectType> : IOSArray<ObjectType> {
37+
NS_ASSUME_NONNULL_BEGIN
38+
@interface IOSObjectArray<__covariant ObjectType> : IOSArray <ObjectType> {
3539
@public
3640
/**
3741
* The type of elements in this array.
@@ -46,15 +50,15 @@
4650
ObjectType __strong buffer_[0] __attribute__((aligned(__alignof__(volatile_id))));
4751
}
4852

49-
@property (readonly) IOSClass *elementType;
53+
@property(readonly) IOSClass *elementType;
5054

5155
/** Create an array from a C object array, length, and type. */
52-
+ (instancetype)newArrayWithObjects:(const ObjectType *)objects
56+
+ (instancetype)newArrayWithObjects:(const _Nonnull ObjectType *_Nonnull)objects
5357
count:(NSUInteger)count
5458
type:(IOSClass *)type;
5559

5660
/** Create an autoreleased array from a C object array, length, and type. */
57-
+ (instancetype)arrayWithObjects:(const ObjectType *)objects
61+
+ (instancetype)arrayWithObjects:(const _Nonnull ObjectType *_Nonnull)objects
5862
count:(NSUInteger)count
5963
type:(IOSClass *)type;
6064

@@ -101,7 +105,7 @@
101105
* @throws IndexOutOfBoundsException
102106
* if the specified length is greater than the array size.
103107
*/
104-
- (void)getObjects:(NSObject **)buffer length:(NSUInteger)length;
108+
- (void)getObjects:(NSObject *_Nonnull *_Nonnull)buffer length:(NSUInteger)length;
105109

106110
@end
107111

@@ -111,8 +115,8 @@
111115
* if index is out of range
112116
* @return the element at index.
113117
*/
114-
__attribute__((always_inline)) inline id IOSObjectArray_Get(
115-
__unsafe_unretained IOSObjectArray *array, jint index) {
118+
__attribute__((always_inline)) inline id _Nullable IOSObjectArray_Get(
119+
__unsafe_unretained IOSObjectArray *_Nonnull array, jint index) {
116120
IOSArray_checkIndex(array->size_, index);
117121
return ALWAYS_RETAINED_AUTORELEASED_RETURN_VALUE(array->buffer_[index]);
118122
}
@@ -123,7 +127,8 @@ __attribute__((always_inline)) inline id IOSObjectArray_Get(
123127
* if index is out of range
124128
* @return the replacement object.
125129
*/
126-
FOUNDATION_EXPORT id IOSObjectArray_Set(IOSObjectArray *array, NSUInteger index, id value);
130+
FOUNDATION_EXPORT id _Nullable IOSObjectArray_Set(IOSObjectArray *_Nonnull array, NSUInteger index,
131+
id _Nullable value);
127132

128133
/**
129134
* Sets element at a specified index, same as IOSObjectArray_Set(), but this function
@@ -132,22 +137,28 @@ FOUNDATION_EXPORT id IOSObjectArray_Set(IOSObjectArray *array, NSUInteger index,
132137
* if index is out of range
133138
* @return the replacement object.
134139
*/
135-
FOUNDATION_EXPORT id IOSObjectArray_SetAndConsume(IOSObjectArray *array, NSUInteger index,
136-
id __attribute__((ns_consumed)) value);
140+
FOUNDATION_EXPORT id _Nullable IOSObjectArray_SetAndConsume(IOSObjectArray *_Nonnull array,
141+
NSUInteger index,
142+
id _Nullable
143+
__attribute__((ns_consumed)) value);
137144

138145
// Internal only. Provides a pointer to an element with the array itself.
139146
// Used for translating certain compound expressions.
140147
typedef struct JreArrayRef {
141-
__unsafe_unretained IOSObjectArray *arr;
142-
__strong id *pValue;
148+
__unsafe_unretained IOSObjectArray *_Nonnull arr;
149+
__strong id _Nonnull *_Nullable pValue;
143150
} JreArrayRef;
144151

145152
// Internal only functions.
146153
__attribute__((always_inline)) inline JreArrayRef IOSObjectArray_GetRef(
147-
__unsafe_unretained IOSObjectArray *array, jint index) {
154+
__unsafe_unretained IOSObjectArray *_Nonnull array, jint index) {
148155
IOSArray_checkIndex(array->size_, index);
149-
return (JreArrayRef){ .arr = array, .pValue = &array->buffer_[index] };
156+
return (JreArrayRef){.arr = array, .pValue = &array->buffer_[index]};
150157
}
151-
FOUNDATION_EXPORT id IOSObjectArray_SetRef(JreArrayRef ref, id value);
158+
FOUNDATION_EXPORT id _Nullable IOSObjectArray_SetRef(JreArrayRef ref, id _Nullable value);
159+
160+
NS_ASSUME_NONNULL_END
161+
162+
#pragma clang diagnostic pop
152163

153-
#endif // IOSObjectArray_H
164+
#endif // IOSObjectArray_H

0 commit comments

Comments
 (0)