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

Allow TYPE_USE on MagicConstant, Pattern, RegExp and Subst #1

Closed
wants to merge 2 commits into from

Conversation

bric3
Copy link
Owner

@bric3 bric3 commented Feb 29, 2024

This should fix JetBrains#43 (and supersedes JetBrains#77).

The main goal of this PR is to enable documenting the code on the generic type parameters. Later this could also be integrated in IDE inspection.

After this PR and this is released a developer can document it's API this way :

Map<@Pattern("[a-z]+(-[a-z]+)*") String, @Language("RegExp") String> regexes

Since TYPE_USE is not available prior Java 8, the Java 5 project stripped this enum value from source. However it was missing some cases. This PR is more lenient in detecting and stripping this value.

  1. @Target({LOCAL_VARIABLE, TYPE_USE, ANNOTATION_TYPE}) => @Target({LOCAL_VARIABLE, ANNOTATION_TYPE})
  2. @Target({ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE, ElementType.PARAMETER}) => @Target({ElementType.LOCAL_VARIABLE, ElementType.PARAMETER})
  3. @Target({ElementType.FIELD, ElementType.TYPE_USE}) => @Target({ElementType.FIELD, })
  4. @Target({ElementType.TYPE_USE, ElementType.FIELD}) => @Target({ ElementType.FIELD})

The previous regex only supported the typed enum usage, and didn't work when the enum was at the end.

The new regex should be much more lenient on the placement and handles use of enum values when imported.
This allows to place this annotation on the type declaration of generic types, e.g.

Map<@pattern("p") String, @language("RegExp") String>
@bric3
Copy link
Owner Author

bric3 commented Feb 29, 2024

🤦‍♂️ wrong project

@bric3 bric3 closed this Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant