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

JCodeModel.parseType(String) silently ignores type params in specific scenarios #1505

Closed
perceptron8 opened this issue Jan 30, 2021 · 3 comments

Comments

@perceptron8
Copy link

If there are multiple type params and (at least) one one of them is generic, parseType works properly only if this param is the last one.

Because of that this test passes:

JCodeModel model = new JCodeModel();
JType type = model.parseType("Map<K,Pair<X,Y>>");
assertEquals("Map<K,Pair<X,Y>>", type.fullName());

This one fails miserably:

JCodeModel model = new JCodeModel();
JType type = model.parseType("Map<Pair<X,Y>,V>");
assertEquals("Map<Pair<X,Y>,V>", type.fullName());
org.opentest4j.AssertionFailedError: expected: <Map<Pair<X,Y>,V>> but was: <Map<Pair<X,Y>>>

Shouldn't TypeNameParser be smart enough to deal with such simple names?

@perceptron8
Copy link
Author

In the meantime, I'd like to assure you, that I know how to construct these types programmatically and confirm, that my use case is indeed strictly related to parsing.

JCodeModel model = new JCodeModel();
JClass Map = model.ref("Map");
JClass Pair = model.ref("Pair");
JClass X = model.ref("X");
JClass Y = model.ref("Y");
JClass V = model.ref("V");
JType type = Map.narrow(Pair.narrow(X, Y), V);
assertEquals("Map<Pair<X,Y>,V>", type.fullName());
JCodeModel model = new JCodeModel();
JClass Map = model.ref("Map");
JClass Pair = model.ref("Pair");
JClass K = model.ref("K");
JClass X = model.ref("X");
JClass Y = model.ref("Y");
JType type = Map.narrow(K, Pair.narrow(X, Y));
assertEquals("Map<K,Pair<X,Y>>", type.fullName());

@lukasj
Copy link
Member

lukasj commented May 12, 2022

should be fixed in master (4.0.0)

@lukasj lukasj closed this as completed May 12, 2022
@perceptron8
Copy link
Author

Thank you very much!
I apologize for not writing sooner.

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

2 participants