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

Error prone RedundantModifier check supports more interface components #1021

Merged

Conversation

carterkozak
Copy link
Contributor

public interface Iface {
-  public static void a() {}
+  static void a() {}
}
public interface Iface {
-  public static final int VALUE = 1;
+  int VALUE = 1;
}

Before this PR

After this PR

==COMMIT_MSG==
Error prone RedundantModifier check supports interface static methods and fields.
==COMMIT_MSG==

@changelog-app
Copy link

changelog-app bot commented Nov 4, 2019

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Error prone RedundantModifier check supports interface static methods and fields.

Check the box to generate changelog(s)

  • Generate changelog entry

@policy-bot policy-bot bot requested a review from j-baker November 4, 2019 19:47
@carterkozak carterkozak force-pushed the ckozak/RedundantModifier_interface_components branch from 07cc7a8 to 0700dd3 Compare November 4, 2019 19:48
@carterkozak
Copy link
Contributor Author

I haven't had a chance to test this on a large internal project yet, will post here once I've verified it.

@carterkozak
Copy link
Contributor Author

Verified on a large internal project.

```diff
public interface Iface {
-  public static void a() {}
+  static void a() {}
}
```

```diff
public interface Iface {
-  public static final int VALUE = 1;
+  int VALUE = 1;
}
```
@carterkozak carterkozak force-pushed the ckozak/RedundantModifier_interface_components branch from d0cba81 to 82042b8 Compare November 5, 2019 23:20
@carterkozak carterkozak requested a review from iamdanfox November 6, 2019 00:20
@carterkozak
Copy link
Contributor Author

Verified the new change on a large internal project as well.

@@ -45,38 +45,65 @@
severity = BugPattern.SeverityLevel.ERROR,
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm a tiny bit concerned that having this at ERROR level might introduce unnecessary friction when people just want to run things like ./gradlew test locally. We're just detecting redundant code, not actually 'wrong' in anywa way... given that excavator can come around and auto-fix, what do you think about putting this as suggestion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I initially used error because this in some part replaces a checkstyle check which we verify premerge.
Given that robots can fix this for us, and it's not a correctness issue, I don't mind moving it to a suggestion, and allowing minor regressions until the robots sweep through.

@@ -108,6 +135,12 @@ public Description matchMethod(MethodTree tree, VisitorState state) {
.addFix(SuggestedFixes.removeModifiers(tree, state, Modifier.PUBLIC, Modifier.ABSTRACT))
.build();
}
if (INTERFACE_STATIC_METHOD_MODIFIERS.matches(tree, state)) {
return buildDescription(tree)
.setMessage("Interface components are public by default. The 'public' modifier is unnecessary.")
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting that java9 lets people define private methods in interfaces! https://bugs.openjdk.java.net/browse/JDK-8071453

This should be all fine though, because we're explicitly only detecting and fixing the public keyword.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I designed this with JEP 213 in mind.

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