有没有任何工具来重构一个java代码库的编码风格? [英] Are there any tools out there to refactor the coding-style of a java code base?

查看:170
本文介绍了有没有任何工具来重构一个java代码库的编码风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当在现有项目上做一些工作时,我会使用已经在代码库中建立的任何样式。但我们的团队必须维护多个中小型项目,它们在编码风格上略有不同。如果我们可以清除这些差异,它会更有效率和更少的混乱。

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 to medium sized projects which all differ slightly in coding style. It would be more efficient and less confusing if we could cleanup these differences.

所以我在寻找一个工具,允许我重构现有的风格。许多功能已经由标准代码格式化工具提供,如更改缩进样式。我遗漏的是一个工具,允许我删除字段和参数名称的前缀。在一些项目中,所有成员都以m开头,所有参数都以p开头,静态成员以s开头。

So I'm looking for a tool that allows me to refactor the existing style. Lots of features are already provided by standard code formatting tools, like changing the indentation style. What I'm missing is a tool that allows me to strip the prefixes of field and parameter names. In some projects all members are prefixed with "m", all parameters are prefixed with "p" and static members are prefixed with "s".

该工具应该能够处理以下情况:

The tool should be able to handle cases like:

void setValue(String pValue) {
  mValue = pValue;
}

这应该成为:

void setValue(String value) {
  this.value = value;
}

工具应该在类似这种情况下生成警告:

The tool should generate a warning in a case like this:

void setValue(String pValue) {
  int value = 42
}

我知道每个主要的IDE提供重构:重命名功能。我所寻找的是一个工具,它处理一个整个代码库,而不需要单独浏览每个参数/字段。

I know every major IDE provides the refactor: rename feature. What I'm looking for though is a tool which processes a whole code base without me needing to go over each parameter/field individually.

编辑

很多答案提到了重新格式化源的工具代码或检查基于一组样式规则的代码库。我知道这些工具存在。我特别想要的是一个高级工具,允许我删除范围特定的变量名前缀。

A lot of the answers mention tools to re-format source code or check the code base against a set of style rules. I'm aware that those tools exist. What I'm specifically looking for is an advanced tool that allows me to remove scope specific variable name prefixes.

推荐答案

我在寻找类似的工具,甚至更先进的工具。我试图实现设计度量,这是非常上下文相关的。我发现了一些工具,这是商业和昂贵的,如Ndepend和反射。我还发现了一些开源工具,它们像Hammurapi。还有一些工具,如Checkstyle,Findbugs和PMD,可以用于非常简单的用例。我发现的最好的工具是MoDisco。它基于Eclipse EMF,允许生成您的代码的模型,而不是进行一些查询或转换(使用M2M工具)。我唯一的问题是,它是相当缓慢的标准〜20k LOC项目。试一试,也许对于你的用例它就够了。

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.

这篇关于有没有任何工具来重构一个java代码库的编码风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆