我正在寻找一种在完整的Java应用程序上执行批处理重构的方法。这就是说,在还不是这样的情况下,将方法参数设为final。
这里有人知道这样的工具吗?或者解析Java源代码并可以通过这样的更改进行扩展的东西。
发布于 2011-10-25 18:07:36
您可以在IntelliJ中进行批量更改,以更改每个字段、局部变量或参数,这些字段、局部变量或参数可能是最终的。
使用选项进行代码分析,并全局“应用修复”,确保它仍然可以编译,因为在一些奇怪的情况下,它并不总是100%正确。
发布于 2011-10-25 18:40:07
正如Peter Lawrey所建议的,IntelliJ做到了这一点。
Analyze -> Inspect code ->自定义配置文件
在"Code style issues“一节中,您有:
字段可能是最终的
This inspection reports any fields which may safely be made final. A static field may
be final if it is initialized in its declaration or in one static class initializer, but
not both. A non-static field may be final if it is initialized in its declaration or in
one non-static class initializer or in all constructors.
Powered by InspectionGadgets局部变量或参数可以是最终的
This inspection reports parameters or local variables, found in the specified inspection
scope, that may have a final modifier added.
Use check boxes in the inspection options below, to define whether parameters or local
variables (or both) are to be reported.这可能只会使final成为可以安全的变量,但您试图发现的变量将仍然是非final的。尽管如此,这仍然是一种发现它们的方法。
发布于 2011-10-25 18:12:58
我不知道Eclipse或NetBeans中有这样的重构。但是一个像样的正则表达式替换就可以做到这一点。为了确保您不会意外地在不应该发生的地方执行它,您可能需要手动确认每个替换。但是,如果您有数百个类,这可能是不可行的。在这种情况下,到处进行替换,然后检查与旧版本的差异可能是有用的。
如果任何参数因为被覆盖而不是最终的,那么它将在编译过程中变得清晰。
https://stackoverflow.com/questions/7887580
复制相似问题