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

Package prefixes from prop file are in the wrong order #995

Closed
sfuku7 opened this issue Aug 2, 2018 · 8 comments
Closed

Package prefixes from prop file are in the wrong order #995

sfuku7 opened this issue Aug 2, 2018 · 8 comments
Assignees
Labels

Comments

@sfuku7
Copy link
Contributor

sfuku7 commented Aug 2, 2018

Hi

To translate code, I was using ‘—prefix’ options to specify multiple package prefixes. And recently the definition of the prefix mapping was moved to a prop file to translate with ‘—prefixes’ option.

But I found that prefixes of the translated code are different from before.

I guess java.util.Properties#load() causes this issue.

https://github.com/google/j2objc/blob/master/translator/src/main/java/com/google/devtools/j2objc/util/PackagePrefixes.java#L131

I’m using wildcard to specify packages.

@tomball
Copy link
Collaborator

tomball commented Aug 2, 2018

Do you have an example demonstrating this? I agree it may be java.util.Properties, but that's just a guess now.

@sfuku7
Copy link
Contributor Author

sfuku7 commented Aug 2, 2018

Hi

Thanks for your comment !

Here is a demo.

$ find .
.
./prefixes.properties
./foo
./foo/bar
./foo/bar/b
./foo/bar/b/Cat.java
$ cat foo/bar/b/Cat.java 
package foo.bar.b;

class Cat {}
$ j2objc --prefix 'foo.bar.b.*=FBB' --prefix 'foo.bar.*=FBX' foo/bar/b/Cat.java && cat foo/bar/b/Cat.h
//
//  Generated by the J2ObjC translator.  DO NOT EDIT!
//  source: foo/bar/b/Cat.java
//

#include "J2ObjC_header.h"

#pragma push_macro("INCLUDE_ALL_FooBarBCat")
#ifdef RESTRICT_FooBarBCat
#define INCLUDE_ALL_FooBarBCat 0
#else
#define INCLUDE_ALL_FooBarBCat 1
#endif
#undef RESTRICT_FooBarBCat

#if !defined (FBBCat_) && (INCLUDE_ALL_FooBarBCat || defined(INCLUDE_FBBCat))
#define FBBCat_

@interface FBBCat : NSObject

#pragma mark Package-Private

- (instancetype)init;

@end

J2OBJC_EMPTY_STATIC_INIT(FBBCat)

FOUNDATION_EXPORT void FBBCat_init(FBBCat *self);

FOUNDATION_EXPORT FBBCat *new_FBBCat_init() NS_RETURNS_RETAINED;

FOUNDATION_EXPORT FBBCat *create_FBBCat_init();

J2OBJC_TYPE_LITERAL_HEADER(FBBCat)

@compatibility_alias FooBarBCat FBBCat;

#endif

#pragma pop_macro("INCLUDE_ALL_FooBarBCat")
$ cat prefixes.properties 
foo.bar.b.*=FBB
foo.bar.*=FBX
$ j2objc --prefixes prefixes.properties foo/bar/b/Cat.java && cat foo/bar/b/Cat.h
//
//  Generated by the J2ObjC translator.  DO NOT EDIT!
//  source: foo/bar/b/Cat.java
//

#include "J2ObjC_header.h"

#pragma push_macro("INCLUDE_ALL_FooBarBCat")
#ifdef RESTRICT_FooBarBCat
#define INCLUDE_ALL_FooBarBCat 0
#else
#define INCLUDE_ALL_FooBarBCat 1
#endif
#undef RESTRICT_FooBarBCat

#if !defined (FBXCat_) && (INCLUDE_ALL_FooBarBCat || defined(INCLUDE_FBXCat))
#define FBXCat_

@interface FBXCat : NSObject

#pragma mark Package-Private

- (instancetype)init;

@end

J2OBJC_EMPTY_STATIC_INIT(FBXCat)

FOUNDATION_EXPORT void FBXCat_init(FBXCat *self);

FOUNDATION_EXPORT FBXCat *new_FBXCat_init() NS_RETURNS_RETAINED;

FOUNDATION_EXPORT FBXCat *create_FBXCat_init();

J2OBJC_TYPE_LITERAL_HEADER(FBXCat)

@compatibility_alias FooBarBCat FBXCat;

#endif

#pragma pop_macro("INCLUDE_ALL_FooBarBCat")

Is my usage correct ?
I'm using wildcards for over wrapped packages.

My expectation is as below

Settings

foo.bar.b.*=FBB
foo.bar.*=FBX

Expected results

foo.bar.b.Cat => FBBCat
foo.bar.Dog => FBXDog

@tomball tomball self-assigned this Aug 2, 2018
@antonio-cortes-perez
Copy link
Contributor

antonio-cortes-perez commented Aug 2, 2018 via email

@tomball
Copy link
Collaborator

tomball commented Aug 2, 2018

The reason Properties was used is that it was already in jre_core (the minimal set of JRE classes for j2objc-generated files), so a separate parser didn't need to be written and increase the size of jre_core. Looking at Properties, the solution may be to use its package-private LineReader class to parse each line the same as Properties, which IOSClass would save to a LinkedHashMap (also in jre_core). I'll give it a try and see what breaks. :-)

@tomball
Copy link
Collaborator

tomball commented Aug 2, 2018

I think it will be safe to drop Properties' support for representing \uxxxx as Unicode characters, since we can instead require prefixes.properties files be encoded in UTF-8 instead of ISO 8859-1 as Properties does. Does that seem reasonable?

@antonio-cortes-perez
Copy link
Contributor

antonio-cortes-perez commented Aug 2, 2018 via email

@sfuku7
Copy link
Contributor Author

sfuku7 commented Aug 2, 2018

Thanks !

I’ll use prefix packages not relying on declared order at this moment.

tomball added a commit that referenced this issue Aug 24, 2018
…of Properties to preserve line order.

	Change on 2018/08/03 by tball <tball@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=207265443
@antonio-cortes-perez
Copy link
Contributor

Fixed in version 2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants