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

Enhance @with by supporting multiple arguments #43

Closed
mreuvers opened this issue Dec 2, 2016 · 9 comments
Closed

Enhance @with by supporting multiple arguments #43

mreuvers opened this issue Dec 2, 2016 · 9 comments

Comments

@mreuvers
Copy link
Contributor

mreuvers commented Dec 2, 2016

Hey Joe,

As said, this is a useful enhancement. I intend to add this (creating this issue to track). It will look like this:

@with (String s=list.get(0), List<Long> list=x.getIt()) {
 ...
}

And an equivalent java 8 version. The change will be backwards compatible, so the single argument switch will remains working as is.

There is however one thing I am not sure about, the null-safe with statement.
If multiple arguments are present, and the with statement is tagged with '?'.
What shall we do:

  • Execute the block inside, if all the arguments are non-null
  • Forbid the null-safe with if there's more than 1 argument
  • ...

Example:

@with? (String s=list.get(0), List<Long> list=x.getIt()) {
 ..
}
else {

}

What are your thoughts?

@jjlauer
Copy link
Member

jjlauer commented Dec 2, 2016 via email

@mreuvers
Copy link
Contributor Author

mreuvers commented Dec 2, 2016

Ok, that felt like the better option to me as well. Going to pick this one up then. :)

@mreuvers
Copy link
Contributor Author

mreuvers commented Dec 3, 2016

Hey @jjlauer,

While working on some tests for the with block, I encountered the following:

@with(String s = s.get(0)) {
  @s
}
else {
  // it will never get here, but the else is allowed here
}

The above is currently allowed already, though the else will never be executed since this is not a null-safe block (it is a bit like dead code).
This may be a bug, and it may be nice to actually have it fail, so users do get an error about it.

I can fix this alongside this enhancement if you want, to allow the else only for a null-safe with block. I intend to forbid it already for the multiple arguments one anyway.

What has your preference?

@jjlauer
Copy link
Member

jjlauer commented Dec 3, 2016 via email

@mreuvers
Copy link
Contributor Author

mreuvers commented Dec 3, 2016

Hey @jjlauer,

All right.

How do we want to escape the comma, as it can easily be used in the expressions e.g.

@with (List<String> subs = strings.sublist(1\,2), List<String> anotherSub=strings.subList(0\,1).subList(0\,1), String t = "hello\, world") {
}

In the above example I escaped the relevant ones with a single back slash, I guess that would be my preference. What do you think?

@jjlauer
Copy link
Member

jjlauer commented Dec 3, 2016 via email

@mreuvers
Copy link
Contributor Author

mreuvers commented Dec 3, 2016

Semicolon would not really work either, since it can be used inside a String (see above).

I'll think about it for now on how to deal with it. If I get the comma working I prefer that over something else. If not then we can do something else.

@mreuvers
Copy link
Contributor Author

Hey @jjlauer

I had other things to do past month, but at last I had the time to deal with this. I just created a pull request to resolve this enhancement.

See the request for all the details, in short it uses the normal comma and no escapes are necessary.

Could you merge it in and release the version later on?

Thanks!

@mreuvers
Copy link
Contributor Author

Thanks for applying the pull request and releasing @jjlauer!

I will close this issue then. :)

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