Skip to content

Commit e690a66

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

16 files changed

+82
-36
lines changed

jre_emul/Classes/IOSArray.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* An abstract class that represents a Java array. Like a Java array,
3030
* an IOSArray is fixed-size but its elements are mutable.
3131
*/
32+
NS_ASSUME_NONNULL_BEGIN
3233
@interface IOSArray<__covariant ObjectType> : NSMutableArray<ObjectType> {
3334
@public
3435
/**
@@ -59,6 +60,7 @@
5960
- (void *)buffer;
6061

6162
@end
63+
NS_ASSUME_NONNULL_END
6264

6365
CF_EXTERN_C_BEGIN
6466
void IOSArray_throwOutOfBoundsWithMsg(jint size, jint index);

jre_emul/Classes/IOSArrayClass.h

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

2525
#import "IOSClass.h"
2626

27+
NS_ASSUME_NONNULL_BEGIN
2728
@interface IOSArrayClass : IOSClass {
2829
// An IOSClass is used instead of a Class so a IOSPrimitiveClass can be used.
2930
IOSClass *componentType_;
@@ -32,5 +33,6 @@
3233
- (instancetype)initWithComponentType:(IOSClass *)type;
3334

3435
@end
36+
NS_ASSUME_NONNULL_END
3537

3638
#endif // _IOSArrayClass_H_

jre_emul/Classes/IOSClass.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* instances: those representing real classes and interfaces, those
4646
* representing primitive types, and those representing array classes.
4747
*/
48+
NS_ASSUME_NONNULL_BEGIN
4849
@interface IOSClass : NSObject <JavaLangReflectAnnotatedElement,
4950
JavaLangReflectGenericDeclaration, JavaIoSerializable,
5051
JavaLangReflectType, NSCopying> {
@@ -99,17 +100,17 @@
99100

100101
// Class.getMethod(String, Class...)
101102
- (JavaLangReflectMethod *)getMethod:(NSString *)name
102-
parameterTypes:(IOSObjectArray *)types;
103+
parameterTypes:(nullable IOSObjectArray *)types;
103104

104105
// Class.getDeclaredMethod(String, Class...)
105106
- (JavaLangReflectMethod *)getDeclaredMethod:(NSString *)name
106-
parameterTypes:(IOSObjectArray *)types;
107+
parameterTypes:(nullable IOSObjectArray *)types;
107108

108109
// Class.getDeclaredConstructor(Class...)
109-
- (JavaLangReflectConstructor *)getDeclaredConstructor:(IOSObjectArray *)types;
110+
- (JavaLangReflectConstructor *)getDeclaredConstructor:(nullable IOSObjectArray *)types;
110111

111112
// Class.getConstructor(Class)
112-
- (JavaLangReflectConstructor *)getConstructor:(IOSObjectArray *)types;
113+
- (JavaLangReflectConstructor *)getConstructor:(nullable IOSObjectArray *)types;
113114

114115
// Class.getConstructors()
115116
- (IOSObjectArray *)getConstructors;
@@ -130,10 +131,10 @@
130131
+ (IOSClass *)forName:(NSString *)className;
131132
+ (IOSClass *)forName:(NSString *)className
132133
initialize:(jboolean)load
133-
classLoader:(JavaLangClassLoader *)loader;
134+
classLoader:(nullable JavaLangClassLoader *)loader;
134135

135136
// Class.cast(Object)
136-
- (id)cast:(id)throwable;
137+
- (id)cast:(nullable id)throwable;
137138

138139
// Class.getEnclosingClass()
139140
- (IOSClass *)getEnclosingClass;
@@ -154,9 +155,8 @@
154155
- (IOSObjectArray *)getGenericInterfaces;
155156
- (IOSObjectArray *)getTypeParameters;
156157

157-
- (id<JavaLangAnnotationAnnotation>)
158-
getAnnotationWithIOSClass:(IOSClass *)annotationClass;
159-
- (jboolean)isAnnotationPresentWithIOSClass:(IOSClass *)annotationType;
158+
- (id<JavaLangAnnotationAnnotation>)getAnnotationWithIOSClass:(nullable IOSClass *)annotationClass;
159+
- (jboolean)isAnnotationPresentWithIOSClass:(nullable IOSClass *)annotationType;
160160
- (IOSObjectArray *)getAnnotations;
161161
- (IOSObjectArray *)getDeclaredAnnotations;
162162
- (id<JavaLangAnnotationAnnotation>)
@@ -212,6 +212,7 @@
212212
- (IOSObjectArray *)getEnumConstantsShared;
213213

214214
@end
215+
NS_ASSUME_NONNULL_END
215216

216217
CF_EXTERN_C_BEGIN
217218

jre_emul/Classes/IOSConcreteClass.h

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

26+
NS_ASSUME_NONNULL_BEGIN
2627
@interface IOSConcreteClass : IOSClass {
2728
Class class_;
2829
}
@@ -32,5 +33,6 @@
3233
- (instancetype)initWithClass:(Class)cls;
3334

3435
@end
36+
NS_ASSUME_NONNULL_END
3537

3638
#endif // _IOSConcreteClass_H_

jre_emul/Classes/IOSObjectArray.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
* An emulation class that represents a Java object array. Like a Java array,
3232
* an IOSObjectArray is fixed-size but its elements are mutable.
3333
*/
34-
@interface IOSObjectArray<__covariant ObjectType> : IOSArray<ObjectType> {
34+
NS_ASSUME_NONNULL_BEGIN
35+
@interface IOSObjectArray<__covariant ObjectType> : IOSArray <ObjectType> {
3536
@public
3637
/**
3738
* The type of elements in this array.
@@ -46,15 +47,15 @@
4647
ObjectType __strong buffer_[0] __attribute__((aligned(__alignof__(volatile_id))));
4748
}
4849

49-
@property (readonly) IOSClass *elementType;
50+
@property(readonly) IOSClass *elementType;
5051

5152
/** Create an array from a C object array, length, and type. */
52-
+ (instancetype)newArrayWithObjects:(const ObjectType *)objects
53+
+ (instancetype)newArrayWithObjects:(const _Nonnull ObjectType *_Nonnull)objects
5354
count:(NSUInteger)count
5455
type:(IOSClass *)type;
5556

5657
/** Create an autoreleased array from a C object array, length, and type. */
57-
+ (instancetype)arrayWithObjects:(const ObjectType *)objects
58+
+ (instancetype)arrayWithObjects:(const _Nonnull ObjectType *_Nonnull)objects
5859
count:(NSUInteger)count
5960
type:(IOSClass *)type;
6061

@@ -101,18 +102,19 @@
101102
* @throws IndexOutOfBoundsException
102103
* if the specified length is greater than the array size.
103104
*/
104-
- (void)getObjects:(NSObject **)buffer length:(NSUInteger)length;
105+
- (void)getObjects:(NSObject *_Nonnull *_Nonnull)buffer length:(NSUInteger)length;
105106

106107
@end
108+
NS_ASSUME_NONNULL_END
107109

108110
/**
109111
* Gets element at a specified index, functional equivalent to objectAtIndex:.
110112
* @throws IndexOutOfBoundsException
111113
* if index is out of range
112114
* @return the element at index.
113115
*/
114-
__attribute__((always_inline)) inline id IOSObjectArray_Get(
115-
__unsafe_unretained IOSObjectArray *array, jint index) {
116+
__attribute__((always_inline)) inline id _Nullable IOSObjectArray_Get(
117+
__unsafe_unretained IOSObjectArray *_Nonnull array, jint index) {
116118
IOSArray_checkIndex(array->size_, index);
117119
return ALWAYS_RETAINED_AUTORELEASED_RETURN_VALUE(array->buffer_[index]);
118120
}
@@ -123,7 +125,8 @@ __attribute__((always_inline)) inline id IOSObjectArray_Get(
123125
* if index is out of range
124126
* @return the replacement object.
125127
*/
126-
FOUNDATION_EXPORT id IOSObjectArray_Set(IOSObjectArray *array, NSUInteger index, id value);
128+
FOUNDATION_EXPORT id _Nullable IOSObjectArray_Set(IOSObjectArray *_Nonnull array, NSUInteger index,
129+
id _Nullable value);
127130

128131
/**
129132
* Sets element at a specified index, same as IOSObjectArray_Set(), but this function
@@ -132,22 +135,24 @@ FOUNDATION_EXPORT id IOSObjectArray_Set(IOSObjectArray *array, NSUInteger index,
132135
* if index is out of range
133136
* @return the replacement object.
134137
*/
135-
FOUNDATION_EXPORT id IOSObjectArray_SetAndConsume(IOSObjectArray *array, NSUInteger index,
136-
id __attribute__((ns_consumed)) value);
138+
FOUNDATION_EXPORT id _Nullable IOSObjectArray_SetAndConsume(IOSObjectArray *_Nonnull array,
139+
NSUInteger index,
140+
id _Nullable
141+
__attribute__((ns_consumed)) value);
137142

138143
// Internal only. Provides a pointer to an element with the array itself.
139144
// Used for translating certain compound expressions.
140145
typedef struct JreArrayRef {
141-
__unsafe_unretained IOSObjectArray *arr;
142-
__strong id *pValue;
146+
__unsafe_unretained IOSObjectArray *_Nonnull arr;
147+
__strong id _Nonnull *_Nullable pValue;
143148
} JreArrayRef;
144149

145150
// Internal only functions.
146151
__attribute__((always_inline)) inline JreArrayRef IOSObjectArray_GetRef(
147-
__unsafe_unretained IOSObjectArray *array, jint index) {
152+
__unsafe_unretained IOSObjectArray *_Nonnull array, jint index) {
148153
IOSArray_checkIndex(array->size_, index);
149-
return (JreArrayRef){ .arr = array, .pValue = &array->buffer_[index] };
154+
return (JreArrayRef){.arr = array, .pValue = &array->buffer_[index]};
150155
}
151-
FOUNDATION_EXPORT id IOSObjectArray_SetRef(JreArrayRef ref, id value);
156+
FOUNDATION_EXPORT id _Nullable IOSObjectArray_SetRef(JreArrayRef ref, id _Nullable value);
152157

153-
#endif // IOSObjectArray_H
158+
#endif // IOSObjectArray_H

jre_emul/Classes/IOSPrimitiveArray.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
* An Objective-C representation of a Java boolean array. Like a Java array,
5252
* an IOSBooleanArray is fixed-size but its elements are mutable.
5353
*/
54+
NS_ASSUME_NONNULL_BEGIN
5455
@interface IOSBooleanArray : IOSArray<JavaLangBoolean *> {
5556
@public
5657
/**
@@ -111,6 +112,7 @@
111112
- (void)getBooleans:(jboolean *)buffer length:(NSUInteger)length;
112113

113114
@end
115+
NS_ASSUME_NONNULL_END
114116

115117
/**
116118
* @brief Return the boolean at the specified index.
@@ -139,6 +141,7 @@ __attribute__((always_inline)) inline jboolean *IOSBooleanArray_GetRef(
139141
* An Objective-C representation of a Java char array. Like a Java array,
140142
* an IOSCharArray is fixed-size but its elements are mutable.
141143
*/
144+
NS_ASSUME_NONNULL_BEGIN
142145
@interface IOSCharArray : IOSArray<JavaLangCharacter *> {
143146
@public
144147
/**
@@ -204,6 +207,7 @@ __attribute__((always_inline)) inline jboolean *IOSBooleanArray_GetRef(
204207
+ (instancetype)arrayWithNSString:(NSString *)string;
205208

206209
@end
210+
NS_ASSUME_NONNULL_END
207211

208212
/**
209213
* @brief Return the char at the specified index.
@@ -232,6 +236,7 @@ __attribute__((always_inline)) inline jchar *IOSCharArray_GetRef(
232236
* An Objective-C representation of a Java byte array. Like a Java array,
233237
* an IOSByteArray is fixed-size but its elements are mutable.
234238
*/
239+
NS_ASSUME_NONNULL_BEGIN
235240
@interface IOSByteArray : IOSArray<JavaLangByte *> {
236241
@public
237242
/**
@@ -311,6 +316,7 @@ __attribute__((always_inline)) inline jchar *IOSCharArray_GetRef(
311316
- (NSData *)toNSData;
312317

313318
@end
319+
NS_ASSUME_NONNULL_END
314320

315321
/**
316322
* @brief Return the byte at the specified index.
@@ -339,6 +345,7 @@ __attribute__((always_inline)) inline jbyte *IOSByteArray_GetRef(
339345
* An Objective-C representation of a Java array of shorts. Like a Java array,
340346
* an IOSShortArray is fixed-size but its elements are mutable.
341347
*/
348+
NS_ASSUME_NONNULL_BEGIN
342349
@interface IOSShortArray : IOSArray<JavaLangShort *> {
343350
@public
344351
/**
@@ -399,6 +406,7 @@ __attribute__((always_inline)) inline jbyte *IOSByteArray_GetRef(
399406
- (void)getShorts:(jshort *)buffer length:(NSUInteger)length;
400407

401408
@end
409+
NS_ASSUME_NONNULL_END
402410

403411
/**
404412
* @brief Return the short at the specified index.
@@ -427,6 +435,7 @@ __attribute__((always_inline)) inline jshort *IOSShortArray_GetRef(
427435
* An Objective-C representation of a Java int array. Like a Java array,
428436
* an IOSIntArray is fixed-size but its elements are mutable.
429437
*/
438+
NS_ASSUME_NONNULL_BEGIN
430439
@interface IOSIntArray : IOSArray<JavaLangInteger *> {
431440
@public
432441
/**
@@ -488,6 +497,7 @@ __attribute__((always_inline)) inline jshort *IOSShortArray_GetRef(
488497
- (void)getInts:(jint *)buffer length:(NSUInteger)length;
489498

490499
@end
500+
NS_ASSUME_NONNULL_END
491501

492502
/**
493503
* @brief Return the int at the specified index.
@@ -516,6 +526,7 @@ __attribute__((always_inline)) inline jint *IOSIntArray_GetRef(
516526
* An Objective-C representation of a Java long array. Like a Java array,
517527
* an IOSLongArray is fixed-size but its elements are mutable.
518528
*/
529+
NS_ASSUME_NONNULL_BEGIN
519530
@interface IOSLongArray : IOSArray<JavaLangLong *> {
520531
@public
521532
/**
@@ -577,6 +588,7 @@ __attribute__((always_inline)) inline jint *IOSIntArray_GetRef(
577588
- (void)getLongs:(jlong *)buffer length:(NSUInteger)length;
578589

579590
@end
591+
NS_ASSUME_NONNULL_END
580592

581593
/**
582594
* @brief Return the long at the specified index.
@@ -605,6 +617,7 @@ __attribute__((always_inline)) inline jlong *IOSLongArray_GetRef(
605617
* An Objective-C representation of a Java float array. Like a Java array,
606618
* an IOSFloatArray is fixed-size but its elements are mutable.
607619
*/
620+
NS_ASSUME_NONNULL_BEGIN
608621
@interface IOSFloatArray : IOSArray<JavaLangFloat *> {
609622
@public
610623
/**
@@ -665,6 +678,7 @@ __attribute__((always_inline)) inline jlong *IOSLongArray_GetRef(
665678
- (void)getFloats:(jfloat *)buffer length:(NSUInteger)length;
666679

667680
@end
681+
NS_ASSUME_NONNULL_END
668682

669683
/**
670684
* @brief Return the float at the specified index.
@@ -693,6 +707,7 @@ __attribute__((always_inline)) inline jfloat *IOSFloatArray_GetRef(
693707
* An Objective-C representation of a Java double array. Like a Java array,
694708
* an IOSDoubleArray is fixed-size but its elements are mutable.
695709
*/
710+
NS_ASSUME_NONNULL_BEGIN
696711
@interface IOSDoubleArray : IOSArray<JavaLangDouble *> {
697712
@public
698713
/**
@@ -753,6 +768,7 @@ __attribute__((always_inline)) inline jfloat *IOSFloatArray_GetRef(
753768
- (void)getDoubles:(jdouble *)buffer length:(NSUInteger)length;
754769

755770
@end
771+
NS_ASSUME_NONNULL_END
756772

757773
/**
758774
* @brief Return the double at the specified index.

jre_emul/Classes/IOSPrimitiveClass.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
// An IOSClass instance for primitive Java types, which allow primitives to
2828
// be used with Java reflection routines. This class is minimal because Java
2929
// primitive types have/need little runtime support, other than their name.
30+
NS_ASSUME_NONNULL_BEGIN
3031
@interface IOSPrimitiveClass : IOSClass {
3132
NSString *name_;
3233
NSString *type_;
@@ -38,5 +39,6 @@
3839
- (IOSClass *)wrapperClass;
3940

4041
@end
42+
NS_ASSUME_NONNULL_END
4143

4244
#endif // _IOSPrimitiveClass_H_

jre_emul/Classes/IOSProtocolClass.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222

2323
#import "IOSClass.h"
2424

25+
NS_ASSUME_NONNULL_BEGIN
2526
@interface IOSProtocolClass : IOSClass
2627

2728
- (instancetype)initWithProtocol:(Protocol *)protocol;
2829

2930
@end
31+
NS_ASSUME_NONNULL_END
3032

3133
#endif // _IOSProtocolClass_H_

jre_emul/Classes/J2ObjC_common.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ J2OBJC_VOLATILE_ACCESS_DEFN(Double, jdouble)
260260
* @define J2OBJC_TYPE_LITERAL_HEADER
261261
* @param TYPE The name of the type to declare the accessor for.
262262
*/
263-
#define J2OBJC_TYPE_LITERAL_HEADER(TYPE) \
264-
FOUNDATION_EXPORT IOSClass *TYPE##_class_(void);
263+
#define J2OBJC_TYPE_LITERAL_HEADER(TYPE) FOUNDATION_EXPORT IOSClass *_Nonnull TYPE##_class_(void);
265264

266265
/*!
267266
* Defines the type literal accessor for a class or enum type. This macro should
@@ -271,7 +270,7 @@ J2OBJC_VOLATILE_ACCESS_DEFN(Double, jdouble)
271270
* @param TYPE The name of the type to define the accessor for.
272271
*/
273272
#define J2OBJC_CLASS_TYPE_LITERAL_SOURCE(TYPE) \
274-
IOSClass *TYPE##_class_(void) { \
273+
IOSClass *_Nonnull TYPE##_class_(void) { \
275274
static IOSClass *cls; \
276275
static dispatch_once_t token; \
277276
TYPE##_initialize(); \
@@ -289,7 +288,7 @@ J2OBJC_VOLATILE_ACCESS_DEFN(Double, jdouble)
289288
* @param TYPE The name of the type to define the accessor for.
290289
*/
291290
#define J2OBJC_INTERFACE_TYPE_LITERAL_SOURCE(TYPE) \
292-
IOSClass *TYPE##_class_(void) { \
291+
IOSClass *_Nonnull TYPE##_class_(void) { \
293292
static IOSClass *cls; \
294293
static dispatch_once_t token; \
295294
TYPE##_initialize(); \

0 commit comments

Comments
 (0)