Are there any tools out there to refactor the coding-style of a java code base?

前端 未结 6 1234
时光说笑
时光说笑 2021-02-06 06:57

Normally, when doing some work on an existing project, I would just go with whatever style is already established in the code base. But our team has to maintain multiple small t

相关标签:
6条回答
  • 2021-02-06 07:41

    Have you tried out Eclipse's Clean Up tool? Granted, it's not going to handle some of your examples shown here, but it does a pretty decent job in my opinion.

    0 讨论(0)
  • 2021-02-06 07:41

    Eclipse IDE is the best option for your problem..

    0 讨论(0)
  • 2021-02-06 07:52

    I was looking for similar, or even more advanced tool. I was trying to implement design metrics, which are very context dependent. I found some tools, which are commercial and quite expensive like Ndepend and reflectk. I also found some open source tools, which are stalle like Hammurapi. There are also tools like Checkstyle, Findbugs and PMD, which can be used for very simple use cases. The best tool I found was MoDisco. Its based on Eclipse EMF, allows to generate model of your code and than do some querying or transformations (using M2M tools). The only problem I had was that it is quite slow for standard ~20k LOC projects. Give it a try, maybe for your use case it will suffice.

    0 讨论(0)
  • 2021-02-06 07:54

    FindBugs is a very good tool for code static analysis. It really explores potential bugs and is easy to integrate in IDE and build tools.

    0 讨论(0)
  • 2021-02-06 07:56

    I'm not aware of an existing project that would do this for you.

    Have you considered writing your own? For example, the Eclipse framework does offer solid code formatting tools. Have you investigated extending one of them to do what you suggest? Detecting variables named with the pattern you mention should be fairly straightforward.

    I realize it's not an ideal solution. BUT, if you have a large enough code base, it may be more cost effective than doing all the edits by hand.

    0 讨论(0)
  • 2021-02-06 07:56

    Sounds like something like Jalopy might help.

    Jalopy allows you to define a code format style, and then it can read a file, package, or entire project and reformat it. I don't recall if it can do more sophisticated refactoring like changing the style of a local variable to not use Hungarian notation (the mVar crap), but it can change between whatever spacing, bracketing, ordering, and so on formatting you want.

    I've used Jalopy in the past and it worked well. I have even used it on teams where people had different personal coding styles and then at commit we all agreed on a certain format that was automatically handled by Jalopy. (When you check it out you format it your way, when it gets checked back in it gets formatted the team agreed upon way, etc.)

    One problem though, it looks like it hasn't been maintained for a year or so. But, there is a commercial version too that is much more recent -- seems the efforts went that direction. Still the older release might be fine.

    And there are other similar commercial offerings like Jindent.

    0 讨论(0)
提交回复
热议问题