eclipse-jdt / eclipse-jdt/eclipse.jdt.ui
Add name recommendation function for renaming field.
- Dominant language
- Java
- Stars
- 59
- Forks
- 127
- Avg merge
- 21h 41m
- Merged PRs (30d)
- 31
Description
> **Renaming is one of the most frequently used features in IDEs (like Eclipse). However, we notice that their recommendation of new names during renames could be further improved. Here we present this issue to specify how we can improve the name recommendation for Rename Field refactorings.**
- The following code snippet comes the well-known project OpenJDK. Line 44 of jdk/src/java.desktop/share/classes/sun/ java2d /marlin/Dasher.java. In this example, the original developers renamed the field "recLimit" to a new name "REC_LIMIT" because static and fine fields should follow the well-known ConstantNamingConvention (i.e., capitalizing all characters and connecting words with ‘_’).

- When the developers select the field "recLimit" and click the refactoring menu "Rename" in Eclipse, Eclipse will present the following refactoring wizard where the old field name "recLimit" appears in the wizard as the default new name.

- A better choice here is to recommend the field that complies with constant naming conventions as the suggested new name. As a generic rule, we propose the following heuristics:
If (f.modifiers CONTAINS ‘Final’ ) and ( f.modifiers CONTAINS ‘Static’ ) and (f.name NOTFOLLOW ConstantNamingConvention) :
f.newName= Conver2ConstantNamingConvention(f.name)
- We have validated the heuristic on 10574 field renamings actually conducted by the original developers in open-source applications. In total, the heuristic recommend 1073 names where 922 are exactly the same as what the original developers finally used. That is , the precision is 86%.
- We also submit the pull request to resolve this issue. When renaming field names that violate the constant naming convention, we modify the original field name to comply with the constant naming conventions and suggest it as the new name, and display it in the rename wizard.
Contributor guide
Assessment
This issue has not been assessed yet.