Skip to content

Commit 6734b47

Browse files
tomballcopybara-github
authored andcommitted
Updated nullability annotations in jre_emul's native headers.
PiperOrigin-RevId: 733856216
1 parent 3cc0c7b commit 6734b47

16 files changed

+231
-36
lines changed

jre_emul/Classes/IOSArray.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323

2424
#import <Foundation/NSArray.h>
2525

26+
#if __has_feature(nullability)
27+
#pragma clang diagnostic push
28+
#pragma GCC diagnostic ignored "-Wnullability"
29+
#pragma GCC diagnostic ignored "-Wnullability-completeness"
30+
#endif
31+
2632
@class IOSClass;
2733

2834
/**
2935
* An abstract class that represents a Java array. Like a Java array,
3036
* an IOSArray is fixed-size but its elements are mutable.
3137
*/
38+
NS_ASSUME_NONNULL_BEGIN
3239
@interface IOSArray<__covariant ObjectType> : NSMutableArray<ObjectType> {
3340
@public
3441
/**
@@ -59,6 +66,7 @@
5966
- (void *)buffer;
6067

6168
@end
69+
NS_ASSUME_NONNULL_END
6270

6371
CF_EXTERN_C_BEGIN
6472
void IOSArray_throwOutOfBoundsWithMsg(jint size, jint index);
@@ -80,4 +88,7 @@ __attribute__((always_inline)) inline void IOSArray_checkRange(
8088
}
8189
}
8290

91+
#if __has_feature(nullability)
92+
#pragma clang diagnostic pop
93+
#endif
8394
#endif // IOSARRAY_H

jre_emul/Classes/IOSArrayClass.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424

2525
#import "IOSClass.h"
2626

27+
#if __has_feature(nullability)
28+
#pragma clang diagnostic push
29+
#pragma GCC diagnostic ignored "-Wnullability"
30+
#pragma GCC diagnostic ignored "-Wnullability-completeness"
31+
#endif
32+
33+
NS_ASSUME_NONNULL_BEGIN
2734
@interface IOSArrayClass : IOSClass {
2835
// An IOSClass is used instead of a Class so a IOSPrimitiveClass can be used.
2936
IOSClass *componentType_;
@@ -32,5 +39,10 @@
3239
- (instancetype)initWithComponentType:(IOSClass *)type;
3340

3441
@end
42+
NS_ASSUME_NONNULL_END
43+
44+
#if __has_feature(nullability)
45+
#pragma clang diagnostic pop
46+
#endif
3547

3648
#endif // _IOSArrayClass_H_

jre_emul/Classes/IOSClass.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
#import "java/lang/reflect/GenericDeclaration.h"
3030
#import "java/lang/reflect/Type.h"
3131

32+
#if __has_feature(nullability)
33+
#pragma clang diagnostic push
34+
#pragma GCC diagnostic ignored "-Wnullability"
35+
#pragma GCC diagnostic ignored "-Wnullability-completeness"
36+
#endif
37+
3238
@class IOSObjectArray;
3339
@class JavaLangClassLoader;
3440
@class JavaLangReflectConstructor;
@@ -45,6 +51,7 @@
4551
* instances: those representing real classes and interfaces, those
4652
* representing primitive types, and those representing array classes.
4753
*/
54+
NS_ASSUME_NONNULL_BEGIN
4855
@interface IOSClass : NSObject <JavaLangReflectAnnotatedElement,
4956
JavaLangReflectGenericDeclaration, JavaIoSerializable,
5057
JavaLangReflectType, NSCopying> {
@@ -99,17 +106,17 @@
99106

100107
// Class.getMethod(String, Class...)
101108
- (JavaLangReflectMethod *)getMethod:(NSString *)name
102-
parameterTypes:(IOSObjectArray *)types;
109+
parameterTypes:(nullable IOSObjectArray *)types;
103110

104111
// Class.getDeclaredMethod(String, Class...)
105112
- (JavaLangReflectMethod *)getDeclaredMethod:(NSString *)name
106-
parameterTypes:(IOSObjectArray *)types;
113+
parameterTypes:(nullable IOSObjectArray *)types;
107114

108115
// Class.getDeclaredConstructor(Class...)
109-
- (JavaLangReflectConstructor *)getDeclaredConstructor:(IOSObjectArray *)types;
116+
- (JavaLangReflectConstructor *)getDeclaredConstructor:(nullable IOSObjectArray *)types;
110117

111118
// Class.getConstructor(Class)
112-
- (JavaLangReflectConstructor *)getConstructor:(IOSObjectArray *)types;
119+
- (JavaLangReflectConstructor *)getConstructor:(nullable IOSObjectArray *)types;
113120

114121
// Class.getConstructors()
115122
- (IOSObjectArray *)getConstructors;
@@ -130,10 +137,10 @@
130137
+ (IOSClass *)forName:(NSString *)className;
131138
+ (IOSClass *)forName:(NSString *)className
132139
initialize:(jboolean)load
133-
classLoader:(JavaLangClassLoader *)loader;
140+
classLoader:(nullable JavaLangClassLoader *)loader;
134141

135142
// Class.cast(Object)
136-
- (id)cast:(id)throwable;
143+
- (id)cast:(nullable id)throwable;
137144

138145
// Class.getEnclosingClass()
139146
- (IOSClass *)getEnclosingClass;
@@ -154,9 +161,8 @@
154161
- (IOSObjectArray *)getGenericInterfaces;
155162
- (IOSObjectArray *)getTypeParameters;
156163

157-
- (id<JavaLangAnnotationAnnotation>)
158-
getAnnotationWithIOSClass:(IOSClass *)annotationClass;
159-
- (jboolean)isAnnotationPresentWithIOSClass:(IOSClass *)annotationType;
164+
- (id<JavaLangAnnotationAnnotation>)getAnnotationWithIOSClass:(nullable IOSClass *)annotationClass;
165+
- (jboolean)isAnnotationPresentWithIOSClass:(nullable IOSClass *)annotationType;
160166
- (IOSObjectArray *)getAnnotations;
161167
- (IOSObjectArray *)getDeclaredAnnotations;
162168
- (id<JavaLangAnnotationAnnotation>)
@@ -252,4 +258,10 @@ J2OBJC_STATIC_INIT(IOSClass)
252258

253259
J2OBJC_TYPE_LITERAL_HEADER(IOSClass)
254260

261+
NS_ASSUME_NONNULL_END
262+
263+
#if __has_feature(nullability)
264+
#pragma clang diagnostic pop
265+
#endif
266+
255267
#endif // _IOSClass_H_

jre_emul/Classes/IOSConcreteClass.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
#import "IOSClass.h"
2424
#import "IOSMetadata.h"
2525

26+
#if __has_feature(nullability)
27+
#pragma clang diagnostic push
28+
#pragma GCC diagnostic ignored "-Wnullability"
29+
#pragma GCC diagnostic ignored "-Wnullability-completeness"
30+
#endif
31+
32+
NS_ASSUME_NONNULL_BEGIN
2633
@interface IOSConcreteClass : IOSClass {
2734
Class class_;
2835
}
@@ -32,5 +39,10 @@
3239
- (instancetype)initWithClass:(Class)cls;
3340

3441
@end
42+
NS_ASSUME_NONNULL_END
43+
44+
#if __has_feature(nullability)
45+
#pragma clang diagnostic pop
46+
#endif
3547

3648
#endif // _IOSConcreteClass_H_

jre_emul/Classes/IOSObjectArray.h

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

2525
#import "IOSArray.h"
2626

27+
#if __has_feature(nullability)
28+
#pragma clang diagnostic push
29+
#pragma GCC diagnostic ignored "-Wnullability"
30+
#pragma GCC diagnostic ignored "-Wnullability-completeness"
31+
#endif
32+
2733
@class IOSClass;
2834
@class IOSObjectArray;
2935

3036
/**
3137
* An emulation class that represents a Java object array. Like a Java array,
3238
* an IOSObjectArray is fixed-size but its elements are mutable.
3339
*/
34-
@interface IOSObjectArray<__covariant ObjectType> : IOSArray<ObjectType> {
40+
NS_ASSUME_NONNULL_BEGIN
41+
@interface IOSObjectArray<__covariant ObjectType> : IOSArray <ObjectType> {
3542
@public
3643
/**
3744
* The type of elements in this array.
@@ -46,15 +53,15 @@
4653
ObjectType __strong buffer_[0] __attribute__((aligned(__alignof__(volatile_id))));
4754
}
4855

49-
@property (readonly) IOSClass *elementType;
56+
@property(readonly) IOSClass *elementType;
5057

5158
/** Create an array from a C object array, length, and type. */
52-
+ (instancetype)newArrayWithObjects:(const ObjectType *)objects
59+
+ (instancetype)newArrayWithObjects:(const _Nonnull ObjectType *_Nonnull)objects
5360
count:(NSUInteger)count
5461
type:(IOSClass *)type;
5562

5663
/** Create an autoreleased array from a C object array, length, and type. */
57-
+ (instancetype)arrayWithObjects:(const ObjectType *)objects
64+
+ (instancetype)arrayWithObjects:(const _Nonnull ObjectType *_Nonnull)objects
5865
count:(NSUInteger)count
5966
type:(IOSClass *)type;
6067

@@ -101,18 +108,19 @@
101108
* @throws IndexOutOfBoundsException
102109
* if the specified length is greater than the array size.
103110
*/
104-
- (void)getObjects:(NSObject **)buffer length:(NSUInteger)length;
111+
- (void)getObjects:(NSObject *_Nonnull *_Nonnull)buffer length:(NSUInteger)length;
105112

106113
@end
114+
NS_ASSUME_NONNULL_END
107115

108116
/**
109117
* Gets element at a specified index, functional equivalent to objectAtIndex:.
110118
* @throws IndexOutOfBoundsException
111119
* if index is out of range
112120
* @return the element at index.
113121
*/
114-
__attribute__((always_inline)) inline id IOSObjectArray_Get(
115-
__unsafe_unretained IOSObjectArray *array, jint index) {
122+
__attribute__((always_inline)) inline id _Nullable IOSObjectArray_Get(
123+
__unsafe_unretained IOSObjectArray *_Nonnull array, jint index) {
116124
IOSArray_checkIndex(array->size_, index);
117125
return ALWAYS_RETAINED_AUTORELEASED_RETURN_VALUE(array->buffer_[index]);
118126
}
@@ -123,7 +131,8 @@ __attribute__((always_inline)) inline id IOSObjectArray_Get(
123131
* if index is out of range
124132
* @return the replacement object.
125133
*/
126-
FOUNDATION_EXPORT id IOSObjectArray_Set(IOSObjectArray *array, NSUInteger index, id value);
134+
FOUNDATION_EXPORT id _Nullable IOSObjectArray_Set(IOSObjectArray *_Nonnull array, NSUInteger index,
135+
id _Nullable value);
127136

128137
/**
129138
* Sets element at a specified index, same as IOSObjectArray_Set(), but this function
@@ -132,22 +141,28 @@ FOUNDATION_EXPORT id IOSObjectArray_Set(IOSObjectArray *array, NSUInteger index,
132141
* if index is out of range
133142
* @return the replacement object.
134143
*/
135-
FOUNDATION_EXPORT id IOSObjectArray_SetAndConsume(IOSObjectArray *array, NSUInteger index,
136-
id __attribute__((ns_consumed)) value);
144+
FOUNDATION_EXPORT id _Nullable IOSObjectArray_SetAndConsume(IOSObjectArray *_Nonnull array,
145+
NSUInteger index,
146+
id _Nullable
147+
__attribute__((ns_consumed)) value);
137148

138149
// Internal only. Provides a pointer to an element with the array itself.
139150
// Used for translating certain compound expressions.
140151
typedef struct JreArrayRef {
141-
__unsafe_unretained IOSObjectArray *arr;
142-
__strong id *pValue;
152+
__unsafe_unretained IOSObjectArray *_Nonnull arr;
153+
__strong id _Nonnull *_Nullable pValue;
143154
} JreArrayRef;
144155

145156
// Internal only functions.
146157
__attribute__((always_inline)) inline JreArrayRef IOSObjectArray_GetRef(
147-
__unsafe_unretained IOSObjectArray *array, jint index) {
158+
__unsafe_unretained IOSObjectArray *_Nonnull array, jint index) {
148159
IOSArray_checkIndex(array->size_, index);
149-
return (JreArrayRef){ .arr = array, .pValue = &array->buffer_[index] };
160+
return (JreArrayRef){.arr = array, .pValue = &array->buffer_[index]};
150161
}
151-
FOUNDATION_EXPORT id IOSObjectArray_SetRef(JreArrayRef ref, id value);
162+
FOUNDATION_EXPORT id _Nullable IOSObjectArray_SetRef(JreArrayRef ref, id _Nullable value);
163+
164+
#if __has_feature(nullability)
165+
#pragma clang diagnostic pop
166+
#endif
152167

153-
#endif // IOSObjectArray_H
168+
#endif // IOSObjectArray_H

0 commit comments

Comments
 (0)