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

[java] Refactor annotation suppression #1927

Merged
merged 7 commits into from
Sep 25, 2019

Conversation

oowekyala
Copy link
Member

This removes the need for the Java CanSuppressWarnings interface, and decouples the AST from rules.
See also this PR comment.

The implementation of the interface was duplicated 4 times, but we can use Annotatable to remove the duplication.

Relevant regression tests are in SuppressWarningsTest, which isn't touched by this PR.

TODO on master:

  • Deprecate CanSuppressWarnings and implemented methods
  • Maybe, deprecate JavaRuleViolation::isSupressed: there's a typo in the method name, and it doesn't need to be public
  • I'm also not sure we need AbstractJavaRule::isSuppressed. It seems like it's only used by one rule deprecated for removal

Notes:

  • Apex also has CanSuppressWarnings and the implementations are also perfect duplicates (7 times).
  • We could avoid hardcoding the suppressed rule names, and instead use eg an annotation on the rule class (eg SuppressionGroup("unused")), which would make the suppression mechanism extensible, and also usable by end-users.

@oowekyala oowekyala added the in:ast About the AST structure or API, the parsing step label Jul 21, 2019
@oowekyala oowekyala added this to the 7.0.0 milestone Jul 21, 2019
oowekyala added a commit that referenced this pull request Sep 24, 2019
* nspmd.lang.java.dfa
* nspmd.lang.java.symboltable
* Some of nspmd.lang.java.metrics

The remaining failures are fixed by #1927
@pmd-test
Copy link

1 Message
📖 No java rules are changed!

Generated by 🚫 Danger

@@ -96,8 +96,12 @@ public static boolean importsPackage(ASTCompilationUnit node, String packageName
return false;
}

/**
* @deprecated Used in only one deprecated rule, which is removed by pending PR #1772
Copy link
Member

Choose a reason for hiding this comment

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

#1772 is now merged… shall this method be removed altogether and deprecated in master?

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact that comment is wrong, the PR removing that rule is #2022 (rules are the old [Std|Modified]CyclomaticComplexity). But I deprecated the method in #2031

@jsotuyod
Copy link
Member

@oowekyala other than that one doubt this looks mergeable. We should also deprecate CanSuppressWarnings from master on a separate PR.

@oowekyala oowekyala merged commit 16cfc43 into pmd:java-grammar Sep 25, 2019
@oowekyala oowekyala deleted the grammar-annotation-suppression branch September 25, 2019 20:54
@oowekyala oowekyala mentioned this pull request Oct 6, 2019
2 tasks
@adangel adangel mentioned this pull request May 23, 2020
6 tasks
@adangel adangel mentioned this pull request Jan 11, 2023
1 task
@adangel adangel mentioned this pull request Jan 23, 2023
55 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in:ast About the AST structure or API, the parsing step
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants