Skip to content

Commit c55194a

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

18 files changed

+192
-55
lines changed

jre_emul/Classes/IOSArray.h

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

2424
#import <Foundation/NSArray.h>
2525

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

2833
/**
2934
* An abstract class that represents a Java array. Like a Java array,
3035
* an IOSArray is fixed-size but its elements are mutable.
3136
*/
37+
NS_ASSUME_NONNULL_BEGIN
3238
@interface IOSArray<__covariant ObjectType> : NSMutableArray<ObjectType> {
3339
@public
3440
/**
@@ -59,6 +65,7 @@
5965
- (void *)buffer;
6066

6167
@end
68+
NS_ASSUME_NONNULL_END
6269

6370
CF_EXTERN_C_BEGIN
6471
void IOSArray_throwOutOfBoundsWithMsg(jint size, jint index);
@@ -80,4 +87,7 @@ __attribute__((always_inline)) inline void IOSArray_checkRange(
8087
}
8188
}
8289

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

jre_emul/Classes/IOSArrayClass.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,22 @@
2424

2525
#import "IOSClass.h"
2626

27+
#if __has_feature(nullability)
28+
#pragma clang diagnostic push
29+
#pragma GCC diagnostic ignored "-Wnullability-completeness"
30+
#endif
31+
2732
@interface IOSArrayClass : IOSClass {
2833
// An IOSClass is used instead of a Class so a IOSPrimitiveClass can be used.
29-
IOSClass *componentType_;
34+
IOSClass *_Nonnull componentType_;
3035
}
3136

32-
- (instancetype)initWithComponentType:(IOSClass *)type;
37+
- (instancetype)initWithComponentType:(IOSClass * _Nonnull)type;
3338

3439
@end
3540

41+
#if __has_feature(nullability)
42+
#pragma clang diagnostic pop
43+
#endif
44+
3645
#endif // _IOSArrayClass_H_

jre_emul/Classes/IOSClass.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
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-completeness"
35+
#endif
36+
3237
@class IOSObjectArray;
3338
@class JavaLangClassLoader;
3439
@class JavaLangReflectConstructor;
@@ -45,6 +50,7 @@
4550
* instances: those representing real classes and interfaces, those
4651
* representing primitive types, and those representing array classes.
4752
*/
53+
NS_ASSUME_NONNULL_BEGIN
4854
@interface IOSClass : NSObject <JavaLangReflectAnnotatedElement,
4955
JavaLangReflectGenericDeclaration, JavaIoSerializable,
5056
JavaLangReflectType, NSCopying> {
@@ -99,17 +105,17 @@
99105

100106
// Class.getMethod(String, Class...)
101107
- (JavaLangReflectMethod *)getMethod:(NSString *)name
102-
parameterTypes:(IOSObjectArray *)types;
108+
parameterTypes:(nullable IOSObjectArray *)types;
103109

104110
// Class.getDeclaredMethod(String, Class...)
105111
- (JavaLangReflectMethod *)getDeclaredMethod:(NSString *)name
106-
parameterTypes:(IOSObjectArray *)types;
112+
parameterTypes:(nullable IOSObjectArray *)types;
107113

108114
// Class.getDeclaredConstructor(Class...)
109-
- (JavaLangReflectConstructor *)getDeclaredConstructor:(IOSObjectArray *)types;
115+
- (JavaLangReflectConstructor *)getDeclaredConstructor:(nullable IOSObjectArray *)types;
110116

111117
// Class.getConstructor(Class)
112-
- (JavaLangReflectConstructor *)getConstructor:(IOSObjectArray *)types;
118+
- (JavaLangReflectConstructor *)getConstructor:(nullable IOSObjectArray *)types;
113119

114120
// Class.getConstructors()
115121
- (IOSObjectArray *)getConstructors;
@@ -130,10 +136,10 @@
130136
+ (IOSClass *)forName:(NSString *)className;
131137
+ (IOSClass *)forName:(NSString *)className
132138
initialize:(jboolean)load
133-
classLoader:(JavaLangClassLoader *)loader;
139+
classLoader:(nullable JavaLangClassLoader *)loader;
134140

135141
// Class.cast(Object)
136-
- (id)cast:(id)throwable;
142+
- (id)cast:(nullable id)throwable;
137143

138144
// Class.getEnclosingClass()
139145
- (IOSClass *)getEnclosingClass;
@@ -154,9 +160,8 @@
154160
- (IOSObjectArray *)getGenericInterfaces;
155161
- (IOSObjectArray *)getTypeParameters;
156162

157-
- (id<JavaLangAnnotationAnnotation>)
158-
getAnnotationWithIOSClass:(IOSClass *)annotationClass;
159-
- (jboolean)isAnnotationPresentWithIOSClass:(IOSClass *)annotationType;
163+
- (id<JavaLangAnnotationAnnotation>)getAnnotationWithIOSClass:(nullable IOSClass *)annotationClass;
164+
- (jboolean)isAnnotationPresentWithIOSClass:(nullable IOSClass *)annotationType;
160165
- (IOSObjectArray *)getAnnotations;
161166
- (IOSObjectArray *)getDeclaredAnnotations;
162167
- (id<JavaLangAnnotationAnnotation>)
@@ -219,7 +224,7 @@ CF_EXTERN_C_BEGIN
219224
IOSClass *IOSClass_forName_(NSString *className);
220225
// Class.forName(String, boolean, ClassLoader)
221226
IOSClass *IOSClass_forName_initialize_classLoader_(
222-
NSString *className, jboolean load, JavaLangClassLoader *loader);
227+
NSString *className, jboolean load, JavaLangClassLoader * _Nullable loader);
223228

224229
// Lookup a IOSClass from its associated ObjC class, protocol or component type.
225230
IOSClass *IOSClass_fromClass(Class cls);
@@ -252,4 +257,10 @@ J2OBJC_STATIC_INIT(IOSClass)
252257

253258
J2OBJC_TYPE_LITERAL_HEADER(IOSClass)
254259

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

jre_emul/Classes/IOSConcreteClass.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,23 @@
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-completeness"
29+
#endif
30+
2631
@interface IOSConcreteClass : IOSClass {
27-
Class class_;
32+
Class _Nonnull class_;
2833
}
2934

30-
- (instancetype)initWithClass:(Class)cls
31-
metadata:(const J2ObjcClassInfo *)metadata;
32-
- (instancetype)initWithClass:(Class)cls;
35+
- (instancetype)initWithClass:(Class _Nonnull)cls
36+
metadata:(const J2ObjcClassInfo * _Nonnull)metadata;
37+
- (instancetype)initWithClass:(Class _Nonnull)cls;
3338

3439
@end
3540

41+
#if __has_feature(nullability)
42+
#pragma clang diagnostic pop
43+
#endif
44+
3645
#endif // _IOSConcreteClass_H_

jre_emul/Classes/IOSMetadata.h

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

2525
#import "J2ObjC_types.h"
2626

27+
#if __has_feature(nullability)
28+
#pragma clang diagnostic push
29+
#pragma GCC diagnostic ignored "-Wnullability-completeness"
30+
#endif
31+
2732
// Current metadata structure version
2833
#define J2OBJC_METADATA_VERSION 7
2934

@@ -88,4 +93,8 @@ typedef struct J2ObjcClassInfo {
8893
ptr_idx annotationsIdx;
8994
} J2ObjcClassInfo;
9095

96+
#if __has_feature(nullability)
97+
#pragma clang diagnostic pop
98+
#endif
99+
91100
#endif // JreEmulation_IOSMetadata_h

jre_emul/Classes/IOSObjectArray.h

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

2525
#import "IOSArray.h"
2626

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

3035
/**
3136
* An emulation class that represents a Java object array. Like a Java array,
3237
* an IOSObjectArray is fixed-size but its elements are mutable.
3338
*/
34-
@interface IOSObjectArray<__covariant ObjectType> : IOSArray<ObjectType> {
39+
NS_ASSUME_NONNULL_BEGIN
40+
@interface IOSObjectArray<__covariant ObjectType> : IOSArray <ObjectType> {
3541
@public
3642
/**
3743
* The type of elements in this array.
@@ -46,15 +52,15 @@
4652
ObjectType __strong buffer_[0] __attribute__((aligned(__alignof__(volatile_id))));
4753
}
4854

49-
@property (readonly) IOSClass *elementType;
55+
@property(readonly) IOSClass *elementType;
5056

5157
/** Create an array from a C object array, length, and type. */
52-
+ (instancetype)newArrayWithObjects:(const ObjectType *)objects
58+
+ (instancetype)newArrayWithObjects:(const _Nonnull ObjectType *_Nonnull)objects
5359
count:(NSUInteger)count
5460
type:(IOSClass *)type;
5561

5662
/** Create an autoreleased array from a C object array, length, and type. */
57-
+ (instancetype)arrayWithObjects:(const ObjectType *)objects
63+
+ (instancetype)arrayWithObjects:(const _Nonnull ObjectType *_Nonnull)objects
5864
count:(NSUInteger)count
5965
type:(IOSClass *)type;
6066

@@ -101,7 +107,7 @@
101107
* @throws IndexOutOfBoundsException
102108
* if the specified length is greater than the array size.
103109
*/
104-
- (void)getObjects:(NSObject **)buffer length:(NSUInteger)length;
110+
- (void)getObjects:(NSObject *_Nonnull *_Nonnull)buffer length:(NSUInteger)length;
105111

106112
@end
107113

@@ -111,8 +117,8 @@
111117
* if index is out of range
112118
* @return the element at index.
113119
*/
114-
__attribute__((always_inline)) inline id IOSObjectArray_Get(
115-
__unsafe_unretained IOSObjectArray *array, jint index) {
120+
__attribute__((always_inline)) inline id _Nullable IOSObjectArray_Get(
121+
__unsafe_unretained IOSObjectArray *_Nonnull array, jint index) {
116122
IOSArray_checkIndex(array->size_, index);
117123
return ALWAYS_RETAINED_AUTORELEASED_RETURN_VALUE(array->buffer_[index]);
118124
}
@@ -123,7 +129,8 @@ __attribute__((always_inline)) inline id IOSObjectArray_Get(
123129
* if index is out of range
124130
* @return the replacement object.
125131
*/
126-
FOUNDATION_EXPORT id IOSObjectArray_Set(IOSObjectArray *array, NSUInteger index, id value);
132+
FOUNDATION_EXPORT id _Nullable IOSObjectArray_Set(IOSObjectArray *_Nonnull array, NSUInteger index,
133+
id _Nullable value);
127134

128135
/**
129136
* Sets element at a specified index, same as IOSObjectArray_Set(), but this function
@@ -132,22 +139,30 @@ FOUNDATION_EXPORT id IOSObjectArray_Set(IOSObjectArray *array, NSUInteger index,
132139
* if index is out of range
133140
* @return the replacement object.
134141
*/
135-
FOUNDATION_EXPORT id IOSObjectArray_SetAndConsume(IOSObjectArray *array, NSUInteger index,
136-
id __attribute__((ns_consumed)) value);
142+
FOUNDATION_EXPORT id _Nullable IOSObjectArray_SetAndConsume(IOSObjectArray *_Nonnull array,
143+
NSUInteger index,
144+
id _Nullable
145+
__attribute__((ns_consumed)) value);
137146

138147
// Internal only. Provides a pointer to an element with the array itself.
139148
// Used for translating certain compound expressions.
140149
typedef struct JreArrayRef {
141-
__unsafe_unretained IOSObjectArray *arr;
142-
__strong id *pValue;
150+
__unsafe_unretained IOSObjectArray *_Nonnull arr;
151+
__strong id _Nonnull *_Nullable pValue;
143152
} JreArrayRef;
144153

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

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

jre_emul/Classes/IOSPrimitiveArray.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
#pragma clang diagnostic push
3737
#pragma clang diagnostic ignored "-Wzero-length-array"
3838

39+
#if __has_feature(nullability)
40+
#pragma clang diagnostic push
41+
#pragma GCC diagnostic ignored "-Wnullability-completeness"
42+
#endif
43+
44+
NS_ASSUME_NONNULL_BEGIN
45+
3946
@class JavaLangBoolean;
4047
@class JavaLangByte;
4148
@class JavaLangCharacter;
@@ -774,9 +781,12 @@ __attribute__((always_inline)) inline jdouble *IOSDoubleArray_GetRef(
774781
return &array->buffer_[index];
775782
}
776783

784+
NS_ASSUME_NONNULL_END
777785

778-
#undef PRIMITIVE_ARRAY_INTERFACE
779-
#undef PRIMITIVE_ARRAY_C_INTERFACE
780-
786+
#if __has_feature(nullability)
781787
#pragma clang diagnostic pop
788+
#endif
789+
790+
#pragma clang diagnostic pop // ignored "-Wzero-length-array"
791+
782792
#endif // IOSPrimitiveArray_H

jre_emul/Classes/IOSPrimitiveClass.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
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.
3030
@interface IOSPrimitiveClass : IOSClass {
31-
NSString *name_;
32-
NSString *type_;
31+
NSString * _Nonnull name_;
32+
NSString * _Nonnull type_;
3333
}
3434

35-
- (instancetype)initWithName:(NSString *)name type:(NSString *)type;
35+
- (instancetype)initWithName:(NSString * _Nonnull)name type:(NSString * _Nonnull)type;
3636

3737
// For a primitive type, return its associated wrapper class.
38-
- (IOSClass *)wrapperClass;
38+
- (IOSClass * _Nonnull)wrapperClass;
3939

4040
@end
4141

jre_emul/Classes/IOSProtocolClass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@interface IOSProtocolClass : IOSClass
2626

27-
- (instancetype)initWithProtocol:(Protocol *)protocol;
27+
- (instancetype)initWithProtocol:(Protocol * _Nonnull)protocol;
2828

2929
@end
3030

0 commit comments

Comments
 (0)