Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: AddRemoveUnusedDeclarations#1263

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Pankraz76 wants to merge1 commit intogoogle:master
base:master
Choose a base branch
Loading
fromPankraz76:RemoveUnusedDeclarations

Conversation

Pankraz76
Copy link

feat: AddRemoveUnusedDeclarations formatting rule

This PR introduces a new Java formatting rule that automatically removes redundant modifiers and declarations that are either:

  • Implicitly provided by Java language specifications
  • Unnecessarily verbose without adding clarity
  • Obsolete in modern Java versions

Motivation

During codebase modernization efforts (#2524), we identified recurring patterns where:

  1. Developers explicitly declare language defaults (e.g.,public in interfaces)
  2. Projects maintain legacy modifier patterns (e.g.,final static instead ofstatic final)
  3. Modern Java features aren't fully leveraged (records, sealed classes)

As highlighted inthis comment, such redundancies:

  • Increase cognitive load during code reviews
  • Create maintenance overhead
  • Reduce code consistency

Key Features

The rule handles:

  • Interface members:

    • Removes redundantpublic,static,final,abstract modifiers
    • Example:public static final int CONSTint CONST
  • Nested types:

    • Simplifies modifiers in inner classes/interfaces
    • Example:public static class Innerstatic class Inner
  • Enum declarations:

    • Removes redundant modifiers on constants and methods
    • Example:public static final VALUEVALUE
  • Modern Java features:

    • Optimizes record components (public final params → implicit)
    • Simplifies sealed class hierarchies
  • Annotation declarations:

    • Removes redundant modifiers on annotation elements
    • Preserves special syntax (@interface formatting)

Benefits

  1. Reduced Noise:

    • Eliminate redundant modifiers in typical codebases
    • Focuses attention on meaningful declarations
  2. Maintenance Efficiency:

    • Automatic updates when Java language defaults change
    • Consistent application across entire codebase
  3. Modern Java Support:

    • First-class handling of records and sealed classes
    • Future-proof for new language features
  4. Non-intrusive:

    • Preserves all actual semantics
    • Only removes truly redundant declarations

Implementation Notes

  • Built as a standalone step compatible with existing formatting pipelines
  • Preserves all non-redundant modifiers (e.g., keepsprivate when meaningful)
  • Handles special cases like@Nullable final parameters
  • Comprehensive test coverage

Integration

Works seamlessly with:

  • Google Java Format
  • Spotless (via#2530)
  • Any Java formatting pipeline

@google-claGoogle CLA
Copy link

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View thisfailed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Pankraz76Pankraz76force-pushed theRemoveUnusedDeclarations branch 2 times, most recently from6e0d142 to304839cCompareJune 27, 2025 11:31
@Pankraz76
Copy link
Author

kindly request your feedback@nedtwigg@iddeepak.

Thanks.

@Pankraz76Pankraz76 marked this pull request as ready for reviewJune 27, 2025 11:32
@Pankraz76Pankraz76 changed the titlefeat: AddReplaceObsoletesStepfeat: AddRemoveUnusedDeclarationsJun 27, 2025
@Pankraz76Pankraz76force-pushed theRemoveUnusedDeclarations branch 2 times, most recently from3e2ecb4 to83b6daaCompareJune 27, 2025 12:45
@Pankraz76
Copy link
Author

@jbduncan
Copy link
Contributor

@Pankraz76, for future reference, Google employees can't even look at your PR until youaccept the CLA.

@Pankraz76
Copy link
Author

its signed:

AgreementNameDate SignedManage
Google Individual CLAvincent potucekJun 27, 2025 05:50 PDTEdit Contact Information

AgreementNameDate SignedManage
Google Individual CLAvincent potucekJun 27, 2025 05:50 PDTEdit Contact Information

@Pankraz76
Copy link
Author

as every tweak encountered here is fixed in palantir, consider google dead and will drop accordingly:

@Pankraz76Pankraz76 reopened thisAug 6, 2025
@Pankraz76Pankraz76force-pushed theRemoveUnusedDeclarations branch from83b6daa to6dfcb65CompareAugust 6, 2025 10:14
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Pankraz76@jbduncan

[8]ページ先頭

©2009-2025 Movatter.jp