Skip to content

Commit

Permalink
Makes JavaObject inherit the NSObject protocol so that NSObject doesn…
Browse files Browse the repository at this point in the history
…'t also need to be added on all translated interfaces.

	Change on 2016/05/10 by kstanger <[email protected]>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=121955491
  • Loading branch information
kstanger authored and tomball committed May 17, 2016
1 parent 7c49d0b commit c52c5a7
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 32 deletions.
25 changes: 8 additions & 17 deletions jre_emul/Classes/IOSClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -804,24 +804,15 @@ bool IsJavaInterface(Protocol *protocol) {
unsigned int count;
Protocol **protocolList = protocol_copyProtocolList(protocol, &count);
bool result = false;
if (count >= 2) {
// Every translated Java interface has NSObject and JavaObject as the last two inherited
// protocols.
bool foundNSObject = false;
bool foundJavaObject = false;
for (unsigned int i = 0; i < count; i++) {
if (protocolList[i] == @protocol(NSObject)) {
foundNSObject = true;
}
if (protocolList[i] == @protocol(JavaObject)) {
foundJavaObject = true;
}
// Every translated Java interface has JavaObject as the last inherited protocol.
// Every translated Java annotation has JavaLangAnnotationAnnotation as its only inherited
// protocol.
for (unsigned int i = 0; i < count; i++) {
if (protocolList[i] == @protocol(JavaObject)
|| protocolList[i] == @protocol(JavaLangAnnotationAnnotation)) {
result = true;
break;
}
result = foundNSObject && foundJavaObject;
} else {
// Every translated Java annotation has JavaLangAnnotationAnnotation as its only inherited
// protocol.
result = count == 1 && protocolList[0] == @protocol(JavaLangAnnotationAnnotation);
}
free(protocolList);
return result;
Expand Down
2 changes: 1 addition & 1 deletion jre_emul/Classes/JavaObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@class IOSClass;

/// A protocol that defines Java Object-compatible methods.
@protocol JavaObject
@protocol JavaObject <NSObject>

// Returns a copy of the object, if it implements java.lang.Cloneable.
- (id)clone;
Expand Down
2 changes: 1 addition & 1 deletion jre_emul/Classes/java/lang/Iterable.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* Instances of classes that implement this interface can be used with
* the enhanced for loop.
*/
@protocol JavaLangIterable < NSObject, JavaObject, NSFastEnumeration >
@protocol JavaLangIterable <NSFastEnumeration, JavaObject>
- (id<JavaUtilIterator>)iterator;
@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ J2OBJC_EMPTY_STATIC_INIT(ComGoogleProtobufGeneratedMessage_Builder)
J2OBJC_TYPE_LITERAL_HEADER(ComGoogleProtobufGeneratedMessage_Builder)

@protocol ComGoogleProtobufGeneratedMessage_ExtendableMessageOrBuilder
<ComGoogleProtobufMessageOrBuilder, NSObject, JavaObject>
<ComGoogleProtobufMessageOrBuilder, JavaObject>

- (BOOL)hasExtensionWithComGoogleProtobufExtensionLite:
(ComGoogleProtobufExtensionLite *)extension;
Expand Down
4 changes: 2 additions & 2 deletions protobuf/runtime/src/com/google/protobuf/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
@protocol ComGoogleProtobufMessage_Builder;

@protocol ComGoogleProtobufMessage
<ComGoogleProtobufMessageLite, ComGoogleProtobufMessageOrBuilder, NSObject, JavaObject>
<ComGoogleProtobufMessageLite, ComGoogleProtobufMessageOrBuilder, JavaObject>

- (id<ComGoogleProtobufMessage_Builder>)toBuilder;
- (id<ComGoogleProtobufMessage_Builder>)newBuilderForType NS_RETURNS_NOT_RETAINED;
Expand All @@ -60,7 +60,7 @@ J2OBJC_EMPTY_STATIC_INIT(ComGoogleProtobufMessage)
J2OBJC_TYPE_LITERAL_HEADER(ComGoogleProtobufMessage)

@protocol ComGoogleProtobufMessage_Builder
<ComGoogleProtobufMessageLite_Builder, ComGoogleProtobufMessageOrBuilder, NSObject, JavaObject>
<ComGoogleProtobufMessageLite_Builder, ComGoogleProtobufMessageOrBuilder, JavaObject>

- (id<ComGoogleProtobufMessage_Builder>)
setRepeatedFieldWithComGoogleProtobufDescriptors_FieldDescriptor:(id)descriptor
Expand Down
5 changes: 2 additions & 3 deletions protobuf/runtime/src/com/google/protobuf/MessageLite.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@class JavaIoOutputStream;
@protocol ComGoogleProtobufMessageLite_Builder;

@protocol ComGoogleProtobufMessageLite<ComGoogleProtobufMessageLiteOrBuilder, NSObject, JavaObject>
@protocol ComGoogleProtobufMessageLite <ComGoogleProtobufMessageLiteOrBuilder, JavaObject>

- (id<ComGoogleProtobufMessageLite_Builder>)toBuilder;
- (id<ComGoogleProtobufMessageLite_Builder>)newBuilderForType NS_RETURNS_NOT_RETAINED;
Expand All @@ -59,8 +59,7 @@ J2OBJC_EMPTY_STATIC_INIT(ComGoogleProtobufMessageLite)

J2OBJC_TYPE_LITERAL_HEADER(ComGoogleProtobufMessageLite)

@protocol ComGoogleProtobufMessageLite_Builder
<ComGoogleProtobufMessageLiteOrBuilder, NSObject, JavaObject>
@protocol ComGoogleProtobufMessageLite_Builder <ComGoogleProtobufMessageLiteOrBuilder, JavaObject>

- (id<ComGoogleProtobufMessageLite>)build;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#import "JreEmulation.h"

@protocol ComGoogleProtobufMessageLiteOrBuilder<NSObject, JavaObject>
@protocol ComGoogleProtobufMessageLiteOrBuilder <JavaObject>
@end

J2OBJC_EMPTY_STATIC_INIT(ComGoogleProtobufMessageLiteOrBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@protocol ComGoogleProtobufMessage;
@protocol JavaUtilMap;

@protocol ComGoogleProtobufMessageOrBuilder <NSObject, JavaObject>
@protocol ComGoogleProtobufMessageOrBuilder <JavaObject>

- (id<ComGoogleProtobufMessage>)getDefaultInstanceForType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

@class ComGoogleProtobufDescriptors_EnumValueDescriptor;

@protocol ComGoogleProtobufProtocolMessageEnum <NSObject, JavaObject>
@protocol ComGoogleProtobufProtocolMessageEnum <JavaObject>

- (int)getNumber;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "J2ObjC_header.h"
#include "java/util/List.h"

@protocol ComGoogleProtobufProtocolStringList < JavaUtilList, NSObject, JavaObject >
@protocol ComGoogleProtobufProtocolStringList < JavaUtilList, JavaObject >

- (id<JavaUtilList>)asByteStringList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ private List<String> getInterfaceNames() {
names.remove("NSCopying");
names.add(0, "NSCopying");
} else if (isInterfaceType()) {
names.add("NSObject");
names.add("JavaObject");
}
return names;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public void testSuperInterfaceTranslation() throws IOException {
"package unit.test; public interface Example extends Bar {} interface Bar {}",
"Example", "unit/test/Example.h");
assertTranslation(translation,
"@protocol UnitTestExample < UnitTestBar, NSObject, JavaObject >");
"@protocol UnitTestExample < UnitTestBar, JavaObject >");
}

public void testConstTranslation() throws IOException {
Expand Down Expand Up @@ -859,7 +859,7 @@ public void testStaticInterfaceMethodDeclaredInCompanionClass() throws IOExcepti
String header = translateSourceFile(source, "Test", "Test.h");
String impl = getTranslatedFile("Test.m");

assertTranslation(header, "@protocol Foo < NSObject, JavaObject >");
assertTranslation(header, "@protocol Foo < JavaObject >");
assertTranslatedSegments(header, "@interface Foo : NSObject", "+ (void)f;", "@end");
// Should only have one occurrence from the companion class.
assertOccurrences(header, "+ (void)f;", 1);
Expand Down

0 comments on commit c52c5a7

Please sign in to comment.