-
Notifications
You must be signed in to change notification settings - Fork 273
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
Allow specifying visibility as string #1474
Conversation
3868f58
to
edfd734
Compare
Thank you for the PR! One one hand, all-in-all-in-the-end we might merge smth like this. On the other hand, the change is very questionable, and I want to make sure we understand context of a problem. I've reread linked tickets, so I've started to recall some of that, but anyway. First, we need to answer the following question:
This quoted statement is not something I can agree on. This might be true and I might be missing something or just plain wrong. My current take is that, If you use some annotations to some effect you should have these annotation on the classpath. But I want to put it into context, some explanation, which is important:
|
@elucash thanks for your detailed description.
Sorry in case this wasn't precise. What I meant here is based on the below error prone warning, which refers to #291.
Now using a meta-annotation as I described above isn't feasible for us.
Now when I publish these changes and consume this in another project (let's call it ProjectX), where I'd like to use ImmutableSnapshotTable.builder()...build(), we're seeing the below javac warning:
This is the part that I don't understand about this warning. ImmutableSnapshotTable itself doesn't contain any usage of In order to get rid of the warning in ProjectX, one can add a dependency to |
This got me to seriously think about, this puzzle. Maybe I'm fooling myself, but I think I'm starting to understand what's going on.
|
@elucash thanks for filling the gap with the explanation in Point 3, that's exactly the part that I didn't fully understand. We went ahead and merged apache/iceberg#8099 using
so we're not blocked by this PR here. I have not tried the suggestions you provided in Point 4 but I think those would work as well. To deal with the javac warning, I'm absolutely ok exploring other solutions, and I was also thinking about Style merging, but as you mentioned, that sounds like a lot of work for this particular issue. Also I didn't just want to solve this particular problem for our project, but for other users that might see this javac warning when using Style annotations. Let me know your thoughts about what kind of possible approach you have in mind and I can make the required changes as part of this PR. |
/** | ||
* Specify the mode in which visibility of generated value type is derived from abstract value | ||
* type. It is a good idea to not specify such attributes inline with immutable values, but | ||
* rather create style annotation (@see Style). Specifying this will override {@link #visibility()}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to expand documentation with the note about Javac warning (and maybe error-prone's one) at least briefly
It is a good idea to not specify such attributes inline with immutable values, but rather create style annotation (@see Style)
This sorta tries to explain this, but without context (of warnings) it's not explaining it well why these *String()
exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have mentioned the javac warning and added a link to #291 but I'm not sure we'd want to mention that error-prone flags this (because it's only being flagged in Palantir's error-prone implementation)
value-processor/src/org/immutables/value/processor/meta/Constitution.java
Outdated
Show resolved
Hide resolved
if (!Strings.isNullOrEmpty(style().visibilityString())) { | ||
visibility = ImplementationVisibility.valueOf(style().visibilityString()); | ||
} else { | ||
visibility = style().visibility(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like and use tabs for indents, but this repo uses 2 spaces indentation. (I've seen some other code accidentally has tabs, but that was sloppiness and exception to the rule)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed this to have 2-space indentation, but the diff now looks weirder than before (most likely because this file seems to be using Tabs for indentation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this file is in need for reformat, but thank you for getting your lines correctly
I think after thinking and realizing the "exceptional" role of what seems to be strange quirk (if not a bug) in Javac wrt class retained annotations, well I think we should merge this PR and provide this solution. This would be definitely a place where Immutables 3 (and I hope there will be such) should improve and just avoid getting into such cases. I've asked for some cosmetic changes and I'll merge the PR. |
b668641
to
096409d
Compare
096409d
to
205a2ba
Compare
Thank you @nastra for the PR and refinements, merged! |
Thanks @elucash for getting this in! |
Now that immutables/immutables#1474 has been fixed and was shipped as part of Immutables 2.10.0, we can switch to using the visibility string to fix the below compiler warnings for consuming projects: ``` warning: unknown enum constant ImplementationVisibility.PACKAGE reason: class file for org.immutables.value.Value$Style$ImplementationVisibility not found warning: unknown enum constant ImplementationVisibility.PACKAGE reason: class file for org.immutables.value.Value$Style$ImplementationVisibility not found warning: unknown enum constant ImplementationVisibility.PACKAGE reason: class file for org.immutables.value.Value$Style$ImplementationVisibility not found warning: unknown enum constant ImplementationVisibility.PACKAGE reason: class file for org.immutables.value.Value$Style$ImplementationVisibility not found warning: unknown enum constant ImplementationVisibility.PACKAGE reason: class file for org.immutables.value.Value$Style$ImplementationVisibility not found ```
…8752) Now that immutables/immutables#1474 has been fixed and was shipped as part of Immutables 2.10.0, we can switch to using the visibility string to fix the below compiler warnings for consuming projects: ``` warning: unknown enum constant ImplementationVisibility.PACKAGE reason: class file for org.immutables.value.Value$Style$ImplementationVisibility not found warning: unknown enum constant ImplementationVisibility.PACKAGE reason: class file for org.immutables.value.Value$Style$ImplementationVisibility not found warning: unknown enum constant ImplementationVisibility.PACKAGE reason: class file for org.immutables.value.Value$Style$ImplementationVisibility not found warning: unknown enum constant ImplementationVisibility.PACKAGE reason: class file for org.immutables.value.Value$Style$ImplementationVisibility not found warning: unknown enum constant ImplementationVisibility.PACKAGE reason: class file for org.immutables.value.Value$Style$ImplementationVisibility not found ```
In apache/iceberg#8099 we would like to use a custom style annotation to modify the name of the generated enclosing class (mainly to keep API compatibility).
Now we'd also like to configure
visibility = Value.Style.ImplementationVisibility.PUBLIC
so that the generated class is publicly visible.However, doing that would mean that we'd be forcing a compile-time dependency to consumers due to the issue described in #291 and the currently suggested workaround for this is to have something like
But applying both
@Value.Style(typeImmutableEnclosing = "ImmutableSnapshotTable")
and@ImmutablesPublic
doesn't work due to applying two Style definitions on the class.One could argue to move
@Value.Style(typeImmutableEnclosing = "ImmutableSnapshotTable")
into@ImmutablesPublic
but it's not feasible to create X custom meta annotations.Hence my suggestion would be to allow specifying the visibility as a string in order to avoid the issue described in #291 and to not have to introduce custom meta annotations.
@elucash could you take a look at this please?