Skip to content

Commit 7b4cb55

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

17 files changed

+161
-39
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/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

jre_emul/Classes/J2ObjC_common.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
2929
#endif
3030

31+
#if __has_feature(nullability)
32+
#pragma clang diagnostic push
33+
#pragma GCC diagnostic ignored "-Wnullability-completeness"
34+
#endif
35+
3136
# ifndef OBJC_METHOD_FAMILY_NONE
3237
# if __has_attribute(objc_method_family)
3338
# define OBJC_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))
@@ -260,8 +265,7 @@ J2OBJC_VOLATILE_ACCESS_DEFN(Double, jdouble)
260265
* @define J2OBJC_TYPE_LITERAL_HEADER
261266
* @param TYPE The name of the type to declare the accessor for.
262267
*/
263-
#define J2OBJC_TYPE_LITERAL_HEADER(TYPE) \
264-
FOUNDATION_EXPORT IOSClass *TYPE##_class_(void);
268+
#define J2OBJC_TYPE_LITERAL_HEADER(TYPE) FOUNDATION_EXPORT IOSClass *_Nonnull TYPE##_class_(void);
265269

266270
/*!
267271
* Defines the type literal accessor for a class or enum type. This macro should
@@ -271,7 +275,7 @@ J2OBJC_VOLATILE_ACCESS_DEFN(Double, jdouble)
271275
* @param TYPE The name of the type to define the accessor for.
272276
*/
273277
#define J2OBJC_CLASS_TYPE_LITERAL_SOURCE(TYPE) \
274-
IOSClass *TYPE##_class_(void) { \
278+
IOSClass *_Nonnull TYPE##_class_(void) { \
275279
static IOSClass *cls; \
276280
static dispatch_once_t token; \
277281
TYPE##_initialize(); \
@@ -289,7 +293,7 @@ J2OBJC_VOLATILE_ACCESS_DEFN(Double, jdouble)
289293
* @param TYPE The name of the type to define the accessor for.
290294
*/
291295
#define J2OBJC_INTERFACE_TYPE_LITERAL_SOURCE(TYPE) \
292-
IOSClass *TYPE##_class_(void) { \
296+
IOSClass *_Nonnull TYPE##_class_(void) { \
293297
static IOSClass *cls; \
294298
static dispatch_once_t token; \
295299
TYPE##_initialize(); \
@@ -368,4 +372,8 @@ typedef struct J2ObjCClass_t J2ObjCClass_t;
368372
#define J2OBJC_CLASS_DECLARATION(name) \
369373
extern const J2ObjCClass_t J2OBJC_CLASS_SYMBOL(name)
370374

375+
#if __has_feature(nullability)
376+
#pragma clang diagnostic pop
377+
#endif
378+
371379
#endif // _J2OBJC_COMMON_H_

jre_emul/Classes/JavaObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
@protocol JavaObject <NSObject>
3131

3232
// Returns a copy of the object, if it implements java.lang.Cloneable.
33-
- (id)java_clone;
33+
- (id _Nonnull)java_clone;
3434

3535
// Returns the IOSClass of the receiver.
36-
- (IOSClass *)java_getClass;
36+
- (IOSClass * _Nonnull)java_getClass;
3737

3838
// Wakes up a waiting thread (if any).
3939
- (void)java_notify;

0 commit comments

Comments
 (0)