Skip to content

Commit b0ffaab

Browse files
tomballcopybara-github
authored andcommitted
Translator generates Objective-C "bool" instead of jboolean for Java boolean types.
Replaced all "jboolean" references in third_party/java_src/j2objc/** with "bool". Added "typedef bool jboolean" for backwards compatibility with native Objective-C code. Verified: * clang treats bool and BOOL as identical * Objective-C YES == __objc_yes (clang primitive) * Objective-C NO == __objc_no (clang primitive) * Java Boolean.True.booleanValue() == objc_yes * Java Boolean.False.booleanValue() == objc_no Note: Java true/false has always been directly translated as Objective-C true/false PiperOrigin-RevId: 754226927
1 parent e7ca18e commit b0ffaab

File tree

122 files changed

+2211
-2378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+2211
-2378
lines changed

jre_emul/Classes/AnnotationUtils.m

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@
4343
*/
4444

4545
static jint hashMember(NSString *name, id value);
46-
static jboolean isValidAnnotationMemberType(IOSClass *type);
47-
static jboolean memberEquals(IOSClass *type, id o1, id o2);
46+
static bool isValidAnnotationMemberType(IOSClass *type);
47+
static bool memberEquals(IOSClass *type, id o1, id o2);
4848

49-
50-
jboolean JreAnnotationEquals(id a1, id a2) {
49+
bool JreAnnotationEquals(id a1, id a2) {
5150
if (a1 == a2) {
5251
return true;
5352
}
@@ -83,7 +82,6 @@ jboolean JreAnnotationEquals(id a1, id a2) {
8382
return true;
8483
}
8584

86-
8785
jint JreAnnotationHashCode(id a) {
8886
jint result = 0;
8987
IOSClass *type = [((id<JavaLangAnnotationAnnotation>) nil_chk(a)) annotationType];
@@ -108,8 +106,7 @@ jint JreAnnotationHashCode(id a) {
108106
return result;
109107
}
110108

111-
112-
static jboolean isValidAnnotationMemberType(IOSClass *type) {
109+
static bool isValidAnnotationMemberType(IOSClass *type) {
113110
if ([type isArray]) {
114111
type = [type getComponentType];
115112
}
@@ -120,8 +117,7 @@ static jboolean isValidAnnotationMemberType(IOSClass *type) {
120117
|| [NSString_class_() isEqual:type] || [IOSClass_class_() isEqual:type];
121118
}
122119

123-
124-
static jboolean annotationArrayMemberEquals(IOSObjectArray *a1, IOSObjectArray *a2) {
120+
static bool annotationArrayMemberEquals(IOSObjectArray *a1, IOSObjectArray *a2) {
125121
if (a1->size_ != a2->size_) {
126122
return false;
127123
}
@@ -133,8 +129,7 @@ static jboolean annotationArrayMemberEquals(IOSObjectArray *a1, IOSObjectArray *
133129
return true;
134130
}
135131

136-
137-
static jboolean arrayMemberEquals(IOSClass *componentType, id o1, id o2) {
132+
static bool arrayMemberEquals(IOSClass *componentType, id o1, id o2) {
138133
if ([componentType isAnnotation]) {
139134
return annotationArrayMemberEquals(o1, o2);
140135
}
@@ -165,7 +160,7 @@ static jboolean arrayMemberEquals(IOSClass *componentType, id o1, id o2) {
165160
return JavaUtilArrays_equalsWithNSObjectArray_withNSObjectArray_(o1, o2);
166161
}
167162

168-
static jboolean memberEquals(IOSClass *type, id o1, id o2) {
163+
static bool memberEquals(IOSClass *type, id o1, id o2) {
169164
if (o1 == o2) {
170165
return true;
171166
}
@@ -181,7 +176,6 @@ static jboolean memberEquals(IOSClass *type, id o1, id o2) {
181176
return [o1 isEqual:o2];
182177
}
183178

184-
185179
jint arrayMemberHash(IOSClass *componentType, id o) {
186180
if ([componentType isEqual:JavaLangByte_get_TYPE()]) {
187181
return JavaUtilArrays_hashCodeWithByteArray_(o);

jre_emul/Classes/IOSArrayClass.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ - (IOSClass *)getComponentType {
4444
return componentType_;
4545
}
4646

47-
- (jboolean)isArray {
47+
- (bool)isArray {
4848
return true;
4949
}
5050

5151
- (IOSClass *)getSuperclass {
5252
return NSObject_class_();
5353
}
5454

55-
- (jboolean)isInstance:(id)object {
55+
- (bool)isInstance:(id)object {
5656
IOSClass *objClass = [object java_getClass];
5757
return [objClass isArray] && [componentType_ isAssignableFrom:[objClass getComponentType]];
5858
}
5959

60-
- (jboolean)isAssignableFrom:(IOSClass *)cls {
60+
- (bool)isAssignableFrom:(IOSClass *)cls {
6161
return [cls isArray] && [componentType_ isAssignableFrom:[cls getComponentType]];
6262
}
6363

jre_emul/Classes/IOSArrayTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ - (void)testCheckRange {
7373
}
7474

7575
- (void)testBooleanArrayCopy {
76-
const jboolean *bools = (jboolean[]){ TRUE, FALSE, TRUE, FALSE };
76+
const bool *bools = (bool[]){TRUE, FALSE, TRUE, FALSE};
7777
IOSBooleanArray *a1 = [IOSBooleanArray arrayWithBooleans:bools count:4];
7878
IOSBooleanArray *a2 = AUTORELEASE([a1 copy]);
7979
XCTAssertEqual([a1 length], [a2 length], @"bad array size");

jre_emul/Classes/IOSClass.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
- (IOSClass *)getDeclaringClass;
8282

8383
// Class.isInstance(Object)
84-
- (jboolean)isInstance:(id)object;
84+
- (bool)isInstance:(id)object;
8585

8686
// These methods all return the same class name.
8787
- (NSString *)getName;
@@ -118,7 +118,7 @@
118118
- (IOSObjectArray *)getMethods;
119119

120120
// Class.isAssignableFrom(Class)
121-
- (jboolean) isAssignableFrom:(IOSClass *)cls;
121+
- (bool)isAssignableFrom:(IOSClass *)cls;
122122

123123
// Class.asSubclass(Class)
124124
- (IOSClass *)asSubclass:(IOSClass *)cls;
@@ -129,7 +129,7 @@
129129
// Class.forName
130130
+ (IOSClass *)forName:(NSString *)className;
131131
+ (IOSClass *)forName:(NSString *)className
132-
initialize:(jboolean)load
132+
initialize:(bool)load
133133
classLoader:(JavaLangClassLoader *)loader;
134134

135135
// Class.cast(Object)
@@ -139,24 +139,24 @@
139139
- (IOSClass *)getEnclosingClass;
140140

141141
// Class.isMemberClass
142-
- (jboolean)isMemberClass;
143-
- (jboolean)isLocalClass;
142+
- (bool)isMemberClass;
143+
- (bool)isLocalClass;
144144

145-
- (jboolean)isArray;
146-
- (jboolean)isEnum;
147-
- (jboolean)isInterface;
148-
- (jboolean)isPrimitive;
149-
- (jboolean)isAnnotation;
150-
- (jboolean)isSynthetic;
151-
- (jboolean)isRecord;
145+
- (bool)isArray;
146+
- (bool)isEnum;
147+
- (bool)isInterface;
148+
- (bool)isPrimitive;
149+
- (bool)isAnnotation;
150+
- (bool)isSynthetic;
151+
- (bool)isRecord;
152152

153153
- (IOSObjectArray *)getInterfaces;
154154
- (IOSObjectArray *)getGenericInterfaces;
155155
- (IOSObjectArray *)getTypeParameters;
156156

157157
- (id<JavaLangAnnotationAnnotation>)
158158
getAnnotationWithIOSClass:(IOSClass *)annotationClass;
159-
- (jboolean)isAnnotationPresentWithIOSClass:(IOSClass *)annotationType;
159+
- (bool)isAnnotationPresentWithIOSClass:(IOSClass *)annotationType;
160160
- (IOSObjectArray *)getAnnotations;
161161
- (IOSObjectArray *)getDeclaredAnnotations;
162162
- (id<JavaLangAnnotationAnnotation>)
@@ -172,9 +172,9 @@
172172

173173
- (JavaLangReflectConstructor *)getEnclosingConstructor;
174174
- (JavaLangReflectMethod *)getEnclosingMethod;
175-
- (jboolean)isAnonymousClass;
175+
- (bool)isAnonymousClass;
176176

177-
- (jboolean)desiredAssertionStatus;
177+
- (bool)desiredAssertionStatus;
178178

179179
- (IOSObjectArray *)getEnumConstants;
180180
- (IOSObjectArray *)getRecordComponents;
@@ -193,10 +193,10 @@
193193

194194
// Boxing and unboxing (internal)
195195
- (id)__boxValue:(J2ObjcRawValue *)rawValue;
196-
- (jboolean)__unboxValue:(id)value toRawValue:(J2ObjcRawValue *)rawValue;
196+
- (bool)__unboxValue:(id)value toRawValue:(J2ObjcRawValue *)rawValue;
197197
- (void)__readRawValue:(J2ObjcRawValue *)rawValue fromAddress:(const void *)addr;
198198
- (void)__writeRawValue:(J2ObjcRawValue *)rawValue toAddress:(const void *)addr;
199-
- (jboolean)__convertRawValue:(J2ObjcRawValue *)rawValue toType:(IOSClass *)type;
199+
- (bool)__convertRawValue:(J2ObjcRawValue *)rawValue toType:(IOSClass *)type;
200200

201201
// Internal methods
202202
- (JavaLangReflectMethod *)getMethodWithSelector:(const char *)selector;
@@ -218,8 +218,8 @@ CF_EXTERN_C_BEGIN
218218
// Class.forName(String)
219219
IOSClass *IOSClass_forName_(NSString *className);
220220
// Class.forName(String, boolean, ClassLoader)
221-
IOSClass *IOSClass_forName_initialize_classLoader_(
222-
NSString *className, jboolean load, JavaLangClassLoader *loader);
221+
IOSClass *IOSClass_forName_initialize_classLoader_(NSString *className, bool load,
222+
JavaLangClassLoader *loader);
223223

224224
// Lookup a IOSClass from its associated ObjC class, protocol or component type.
225225
IOSClass *IOSClass_fromClass(Class cls);

jre_emul/Classes/IOSClass.m

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ - (IOSClass *)getDeclaringClass {
227227
}
228228

229229
// Returns true if an object is an instance of this class.
230-
- (jboolean)isInstance:(id)object {
230+
- (bool)isInstance:(id)object {
231231
return false;
232232
}
233233

@@ -380,7 +380,7 @@ - (JavaLangReflectConstructor *)getDeclaredConstructor:(IOSObjectArray *)paramet
380380
@throw create_JavaLangNoSuchMethodException_init();
381381
}
382382

383-
- (jboolean)isAssignableFrom:(IOSClass *)cls {
383+
- (bool)isAssignableFrom:(IOSClass *)cls {
384384
@throw create_JavaLangAssertionError_initWithId_(@"abstract method not overridden");
385385
}
386386

@@ -426,7 +426,7 @@ - (NSString *)toGenericString {
426426
[sb appendWithNSString:[self getName]];
427427
IOSObjectArray *typeparms = [self getTypeParameters];
428428
if (((IOSObjectArray *) nil_chk(typeparms))->size_ > 0) {
429-
jboolean first = true;
429+
bool first = true;
430430
[sb appendWithChar:'<'];
431431
for (id<JavaLangReflectTypeVariable> typeparm in typeparms) {
432432
if (!first) {
@@ -683,14 +683,14 @@ + (IOSClass *)forName:(NSString *)className {
683683
return IOSClass_forName_(className);
684684
}
685685

686-
IOSClass *IOSClass_forName_initialize_classLoader_(
687-
NSString *className, jboolean load, JavaLangClassLoader *loader) {
686+
IOSClass *IOSClass_forName_initialize_classLoader_(NSString *className, bool load,
687+
JavaLangClassLoader *loader) {
688688
IOSClass_initialize();
689689
return IOSClass_forName_(className);
690690
}
691691

692692
+ (IOSClass *)forName:(NSString *)className
693-
initialize:(jboolean)load
693+
initialize:(bool)load
694694
classLoader:(JavaLangClassLoader *)loader {
695695
return IOSClass_forName_initialize_classLoader_(className, load, loader);
696696
}
@@ -710,44 +710,44 @@ - (IOSClass *)getEnclosingClass {
710710
return enclosingClass ? JreClassForString(enclosingClass) : nil;
711711
}
712712

713-
- (jboolean)isArray {
713+
- (bool)isArray {
714714
return false;
715715
}
716716

717-
- (jboolean)isEnum {
717+
- (bool)isEnum {
718718
return false;
719719
}
720720

721-
- (jboolean)isRecord{
721+
- (bool)isRecord {
722722
return [self getSuperclass] == JavaLangRecord_class_();
723723
}
724724

725-
- (jboolean)isInterface {
725+
- (bool)isInterface {
726726
return false;
727727
}
728728

729-
- (jboolean)isPrimitive {
729+
- (bool)isPrimitive {
730730
return false; // Overridden by IOSPrimitiveClass.
731731
}
732732

733-
static jboolean hasModifier(IOSClass *cls, int flag) {
733+
static bool hasModifier(IOSClass *cls, int flag) {
734734
return cls->metadata_ ? (cls->metadata_->modifiers & flag) > 0 : false;
735735
}
736736

737-
- (jboolean)isAnnotation {
737+
- (bool)isAnnotation {
738738
return hasModifier(self, JavaLangReflectModifier_ANNOTATION);
739739
}
740740

741-
- (jboolean)isMemberClass {
741+
- (bool)isMemberClass {
742742
return metadata_ && JrePtrAtIndex(metadata_->ptrTable, metadata_->enclosingClassIdx)
743743
&& ![self isAnonymousClass];
744744
}
745745

746-
- (jboolean)isLocalClass {
746+
- (bool)isLocalClass {
747747
return [self getEnclosingMethod] && ![self isAnonymousClass];
748748
}
749749

750-
- (jboolean)isSynthetic {
750+
- (bool)isSynthetic {
751751
return hasModifier(self, JavaLangReflectModifier_SYNTHETIC);
752752
}
753753

@@ -835,7 +835,7 @@ - (IOSObjectArray *)getTypeParameters {
835835
return nil;
836836
}
837837

838-
- (jboolean)isAnnotationPresentWithIOSClass:(IOSClass *)annotationClass {
838+
- (bool)isAnnotationPresentWithIOSClass:(IOSClass *)annotationClass {
839839
return [self getAnnotationWithIOSClass:annotationClass] != nil;
840840
}
841841

@@ -937,8 +937,7 @@ - (id)getClassLoader {
937937
}
938938

939939
// Adds all the fields for a specified class to a specified dictionary.
940-
static void GetFieldsFromClass(IOSClass *iosClass, NSMutableDictionary *fields,
941-
jboolean publicOnly) {
940+
static void GetFieldsFromClass(IOSClass *iosClass, NSMutableDictionary *fields, bool publicOnly) {
942941
const J2ObjcClassInfo *metadata = IOSClass_GetMetadataOrFail(iosClass);
943942
for (int i = 0; i < metadata->fieldCount; i++) {
944943
const J2ObjcFieldInfo *fieldInfo = &metadata->fields[i];
@@ -1038,8 +1037,8 @@ - (JavaLangReflectConstructor *)getEnclosingConstructor {
10381037

10391038

10401039
// Adds all the inner classes for a specified class to a specified dictionary.
1041-
static void GetInnerClasses(IOSClass *iosClass, NSMutableArray *classes,
1042-
jboolean publicOnly, jboolean includeInterfaces) {
1040+
static void GetInnerClasses(IOSClass *iosClass, NSMutableArray *classes, bool publicOnly,
1041+
bool includeInterfaces) {
10431042
const J2ObjcClassInfo *metadata = iosClass->metadata_;
10441043
if (metadata) {
10451044
IOSObjectArray *innerClasses = JreParseClassList(
@@ -1082,11 +1081,11 @@ - (IOSObjectArray *)getDeclaredClasses {
10821081
return result;
10831082
}
10841083

1085-
- (jboolean)isAnonymousClass {
1084+
- (bool)isAnonymousClass {
10861085
return false;
10871086
}
10881087

1089-
- (jboolean)desiredAssertionStatus {
1088+
- (bool)desiredAssertionStatus {
10901089
return false;
10911090
}
10921091

@@ -1182,7 +1181,7 @@ - (id)__boxValue:(J2ObjcRawValue *)rawValue {
11821181
return (id)rawValue->asId;
11831182
}
11841183

1185-
- (jboolean)__unboxValue:(id)value toRawValue:(J2ObjcRawValue *)rawValue {
1184+
- (bool)__unboxValue:(id)value toRawValue:(J2ObjcRawValue *)rawValue {
11861185
rawValue->asId = value;
11871186
return true;
11881187
}
@@ -1195,7 +1194,7 @@ - (void)__writeRawValue:(J2ObjcRawValue *)rawValue toAddress:(const void *)addr
11951194
*(id *)addr = (id)rawValue->asId;
11961195
}
11971196

1198-
- (jboolean)__convertRawValue:(J2ObjcRawValue *)rawValue toType:(IOSClass *)type {
1197+
- (bool)__convertRawValue:(J2ObjcRawValue *)rawValue toType:(IOSClass *)type {
11991198
// No conversion necessary if both types are ids.
12001199
return ![type isPrimitive];
12011200
}
@@ -1210,7 +1209,7 @@ - (IOSClass *)java_getClass {
12101209
return IOSClass_class_();
12111210
}
12121211

1213-
static jboolean IsStringType(Class cls) {
1212+
static bool IsStringType(Class cls) {
12141213
// We can't trigger class initialization because that might recursively enter
12151214
// FetchClass and result in deadlock within the FastPointerLookup. Therefore,
12161215
// we can't use [cls isSubclassOfClass:[NSString class]].

0 commit comments

Comments
 (0)