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

Feature Request: Mark annotations as ElementType.ANNOTATION_TYPE #1901

Closed
ameisen opened this issue Oct 14, 2018 · 5 comments
Closed

Feature Request: Mark annotations as ElementType.ANNOTATION_TYPE #1901

ameisen opened this issue Oct 14, 2018 · 5 comments
Labels
parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these.

Comments

@ameisen
Copy link

ameisen commented Oct 14, 2018

Hello again (though from my personal account this time rather than my work account),

I am requesting that the Lombok annotations have their @Target appended with ElementType.ANNOTATION_TYPE.

I have a collection of combined annotations, combined using com.fasterxml.jackson.annotation.JacksonAnnotationsInside. However, I am unable to integrate lombok annotations with them due to the fact that the lombok annotations cannot target annotations themselves.

In one particular case (but not the only case), I have two separate annotations: @NotNull and @CheckedNotNull. @NotNull is a combination of a bunch of annotations to target javax, IntelliJ, Eclipse, VS Code, etc. @CheckedNotNull is similar but should also integrate lombok's @NonNull (so it actually, well, checks the value). This'd be trivial to do in C++ or Scala, but lombok's @NonNull is the only one I'm familiar with to do it in Java.

Not sure if there are additional complications - I haven't tested adding the additional target myself, yet. If I get time, I will.

@rspilker
Copy link
Collaborator

Can you at least give a code example? What would you like to type, and how should it behave?

@rspilker rspilker added the parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these. label Oct 15, 2018
@m-kuklinski
Copy link

At work, so responding using my work account.

An example:

	@Target({ANNOTATION_TYPE, FIELD, LOCAL_VARIABLE, METHOD, PARAMETER})
	@Retention(RetentionPolicy.RUNTIME)
	@com.fasterxml.jackson.annotation.JacksonAnnotationsInside
	@javax.validation.constraints.NotNull
	@org.jetbrains.annotations.NotNull
	@org.eclipse.jdt.annotations.NonNull
	@lombok.NonNull
	public @interface CheckedNotNull { }

This is a rather crude example, though.

Sometimes I want to just combine multiple annotations together into a 'super-annotation'. I tend to have annotations for things like immutability, and such. For instance, making a @CommonClass annotation internally with @Slf4j, @Immutable, @FieldNameConstants, and @Data.

The main thing I could suspect being a problem is that the Lombok AST parser may get confused and think it is actually annotating the annotation rather than what that annotation applies to. I have not yet tested this (by adding the flag myself).

@ameisen
Copy link
Author

ameisen commented Oct 25, 2018

Alternatively, if it would be possible to provide an equivalent mechanism to JacksonAnnotationsInside...?

I made a local copy of the NonNull annotation, and added the ANNOTATION_TYPE target. The logic was not injected, so that didn't work - that could have been due to the annotation having been part of my project (albeit in the lombok namespace), though.

@rzwitserloot
Copy link
Collaborator

I don't know what this mechanism is but it makes no sense. NonNull says something about the thing you put it on. Sooo.. the annotation interface cannot be null? That's like saying a circle cannot fly.

Perhaps this is some meta-annotation thingie where some tool will replace an annotation with all the annotations that are on the annotation. This is not what the spec of annotations is designed to do, and would require writing an incorrect, confusing @Target. No can do.

@rzwitserloot
Copy link
Collaborator

See #2294 for the concept of meta-annotating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these.
Projects
None yet
Development

No branches or pull requests

4 participants