Skip to content

Simplify annotation handling in SpringJUnit5Check #157

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

Closed
wants to merge 5 commits into from

Conversation

davebarda
Copy link

No description provided.

@davebarda davebarda requested a review from wilkinsona February 15, 2020 23:05
Copy link
Contributor

@wilkinsona wilkinsona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @davebarda. I've left a few comments. Could you please take a look and, if you agree and have the time to do so, update the proposal accordingly?

@@ -75,14 +67,6 @@
BANNED_IMPORTS = Collections.unmodifiableSet(bannedImports);
}

private static void addAnnotation(Set<String> annotations, String annotation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that removing this method and the usage of it will introduce a regression. The javadoc for AnnotationUtil.containsAnnotation(DetailAst, List<String>) says that it "accepts both simple and fully-qualified names". If a user has annotated a method with, for example, @org.junit.Test rather than importing org.junit.test and annotating with @Test, this change will cause the usage to be missed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method accepts both simple and fully-qualified names, e.g. "Override" will match both java.lang.Override and Override.

Which means that if we are using only the non FQN then we receive a check for both, there is also a test for that:
JUnit5BadAnnotation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are using only the non FQN

I don't think we can't be certain that this is the case. One user could write @org.junit.Test while another could write @Test along with import org.junit.Test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is that I believe it catches both

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I see what you mean now. I agree that just the simple names should be sufficient.

We try to keep issues and pull requests focused on a single change. To that end, would you mind splitting the corrections to JUnit5BadModifier and the simplifications above into separate pull requests?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I have updated this one to be the refactor, I'll create a new one for the test

@davebarda davebarda requested a review from wilkinsona February 21, 2020 22:05
@@ -75,14 +67,6 @@
BANNED_IMPORTS = Collections.unmodifiableSet(bannedImports);
}

private static void addAnnotation(Set<String> annotations, String annotation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are using only the non FQN

I don't think we can't be certain that this is the case. One user could write @org.junit.Test while another could write @Test along with import org.junit.Test.

…" in order to add it in a different PR

This reverts commit 152e98d.
@davebarda davebarda changed the title Fixed test with bad .java file(Wrong imports and annotations) Refactored SpringJUnit5Check.java Feb 26, 2020
@wilkinsona wilkinsona changed the title Refactored SpringJUnit5Check.java Simplify annotation handling in SpringJUnit5Check Feb 27, 2020
@wilkinsona wilkinsona added this to the 0.0.21 milestone Feb 27, 2020
wilkinsona pushed a commit that referenced this pull request Feb 27, 2020
Checkstyle's AnnotationUtil.containsAnnotation automatically handles
simple and fully qualified names. For example, Override matches both
java.lang.Override and Override. This means that SpringJUnit5Check
need only care about the simple names of the annotations that it
wants to detect.

See gh-157
@wilkinsona
Copy link
Contributor

@davebarda Thank you very much for making your first contribution to Spring Java Format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants