Skip to content

Recipe to remove underscores in private field names #630

@greg-at-moderne

Description

@greg-at-moderne

What problem are you trying to solve?

Apply modern code standards.

I think it used to be a bit of a common practice to denote private class fields with names which either started with or ended with underscores. While technically allowed, I don't think this is mainstream in Java. Thus it makes sense to have a recipe to rename the fields not to have these _ prefixes/suffixes.

Describe the situation before applying the recipe

public class ParseLocation {
  private String _ruleName;

  public String getRuleName() {
    return _ruleName;
  }
  public void setRuleName(String ruleName) {
    _ruleName = ruleName;
  }
}

Describe the situation after applying the recipe

public class ParseLocation {
  private String ruleName;

  public String getRuleName() {
    return ruleName;
  }
  public void setRuleName(String ruleName) {
    this.ruleName = ruleName;
  }
}

Any additional context

  • When making the changes, beware of name clashes. Even visible in the simple setter example above.
  • For this reason, not marking this is a good-first-issue.

OSS repro

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Recipes Wanted

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions