Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify generated method names [moved] #23

Closed
kstanger opened this issue Feb 6, 2014 · 6 comments
Closed

Simplify generated method names [moved] #23

kstanger opened this issue Feb 6, 2014 · 6 comments

Comments

@kstanger
Copy link
Collaborator

kstanger commented Feb 6, 2014

This is Issue 23 moved from a Google Code project.
Added on 2012-09-05T23:15:12.000Z by tball@google.com.
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Enhancement, Priority-Medium, Usability

@tomball
Copy link
Collaborator

tomball commented May 23, 2014

Mapping files are now documented, and can be used to define Objective-C method names as desired. We'll still pursue adding support for method name annotations.

@tomball
Copy link
Collaborator

tomball commented May 23, 2014

From nbransby on the old issue tracker:

Was the ObjectiveCName annotation added for methods or only classes? I think being able to give friendlier names to exposed methods that are designed to be called from objective c code is really important despite the risk of selector clash.

Just as important I feel is the translation of arguments to their native types when the annotation is used. In other words not exposing any of the 'javaness' to the client of the translated code. I believe if you can wrap up your cross platform library in a familiar coating for iOS developers it will decrease the suspicion around using such a libary.

Just class names right now, but now that I verified that method name mapping works correctly, adding support for methods should be much easier than starting from scratch.

I'm not sure what you mean by "native types," but the types are copied verbatim from a method mapping (including typos!).

@nbransby
Copy link

By native types I mean converting any emulated classes to their native counterparts, e.g IosObjectArray to NSArray (in fact this maybe the only instance of this)

@tomball
Copy link
Collaborator

tomball commented May 24, 2014

We first tried mapping Java arrays to NSArray, but found that they differ in several critical ways. Java arrays are mutable but fixed size, while NSArray is immutable and NSMutableArray's size changes. NSArray also cannot have nil elements, while Java arrays do (and Java developers expect).

It's easy to convert between NSArray and IOSObjectArray, though. To convert from an NSArray to IOSObjectArray:

NSArray *nsArray = [NSArray arrayWithObjects: @"one", @"two", @"three", nil];
IOSObjectArray *javaArray =
    [IOSObjectArray *arrayWithNSArray:nsArray type:[IOSClass stringClass]];

To convert from an IOSObjectArray to NSArray (if javaArray doesn't have any nil elements):

NSArray *newArray = [NSArray arrayWithObjects:javaArray->buffer_
                                        count:[javaArray size]];

If you want a visible API that only uses NSArrays, you'll need to write a wrapper with the above converters.

@tomball
Copy link
Collaborator

tomball commented Oct 7, 2014

Methods and constructors are now supported for the @ObjectiveCName annotation. This allows developers to rename a method to whatever selector looks best (as long as it is unique in the class). The translator will warn if an attempt is made to rename an overridden method if that super-method doesn't have the same annotation value, and will then ignore that annotation so as to not break polymorphism.

@tomball
Copy link
Collaborator

tomball commented Oct 7, 2014

Since issues are filed for specific problems with method mapping (64, 359, 378, and 389), I'm closing this general issue in favor of j2objc-discuss discussions.

@tomball tomball closed this as completed Oct 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants