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

Enhancement request: new @EnumVal() that would behave like @StringVal() #2953

Closed
smonteiro opened this issue Dec 3, 2019 · 4 comments
Closed
Milestone

Comments

@smonteiro
Copy link
Contributor

smonteiro commented Dec 3, 2019

I could be wrong but I did not find documentation for a @EnumVal
The concept is not too far-fetched: one wants to enforce domain, co-domain, and range:

Example of use case:
import javax.lang.model.type.TypeKind;
static @EnumVal({TypeKind.BYTE,
TypeKind.BOOLEAN,
TypeKind.CHAR,
TypeKind.DOUBLE,
TypeKind.FLOAT,
TypeKind.INT,
TypeKind.LONG}) TypeKind toPrimitiveTypeKind(...)
...
static int fromPrimitiveTypeKind( @EnumVal({TypeKind.BYTE,
TypeKind.BOOLEAN,
TypeKind.CHAR,
TypeKind.DOUBLE,
TypeKind.FLOAT,
TypeKind.INT,
TypeKind.LONG}) TypeKind tk) {...)

@kelloggm
Copy link
Contributor

kelloggm commented Dec 3, 2019

This is probably related to #2156. I agree that it would be useful for the Value Checker to support an @EnumVal annotation; see e.g.
this comment in a third-party checker, which describes a desire to write annotations in a stub file on enum constants. The linked CF issue (#2147) was closed in favor of the more general #2156.

@smonteiro
Copy link
Contributor Author

While the topic of #2156 is Enum, it is about something else.
My interest here is to clamp the domain of arguments to functions and clamp their return values.

@mernst
Copy link
Member

mernst commented Dec 6, 2019

I agree that this is a valuable enhancement, and that it's unrelated to #2156.
I don't think this would be very challenging to do: the logic should be very similar to the other *Val annotations.

@mernst
Copy link
Member

mernst commented Dec 12, 2020

Fixed in 483bd23

@mernst mernst closed this as completed Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants