从 Java 项目中提取所有字符串 [英] Extract all string from a java project

查看:21
本文介绍了从 Java 项目中提取所有字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有相当多的源文件,我需要解析和提取所有字符串文字并将它们作为播放旧的 java 常量放在一个文件中.
例如:

I have a rather big number of source files that I need parse and extract all string literals and put them in a file as play old java constant.
For exemple:

Label l = new Label("Cat");

会变成:

Label l = new Label(Constants.CAT);

Constants.java 中我会:

public final static String CAT = "Cat";

我不希望在属性文本文件中具体化字符串.
原因之一是一致性和代码可读性.
另一个是我们的客户端代码使用了GWT,不支持Java属性文本文件机制.

I do not want the strings to be externalized in a property text file.
One reason is for consistency and code readability.
The other is that our client code uses GWT, which does not support Java property text file mechanism.

我可以编写某种解析器(也许使用蚂蚁替换任务)?
但我想知道 IDE 是否已经自动完成了这种事情.

I could write some sort of parser (using ant replace task maybe)?
But I wondered if an IDE already does this sort of thing automatically.

推荐答案

要完成 Peter Kelley 的回答,您可以考虑为 Eclipse IDE 使用 AST 解决方案.

To complete Peter Kelley answer, you might consider for eclipse IDE the AST solution.

然后您可以编写一个 AST 程序来解析您的源代码并执行您想要的操作.

You might then write an AST program which parse your source code and does what you want.

这个 eclipse 角提供了一个完整的例子文章,还有eclipse 帮助.
您可以在 就地翻译的实现"部分的清单 5 中找到一些示例在 Eclipse JDT 中自动嵌入领域特定语言,以及 GitHub 项目中的多个示例.

这篇关于从 Java 项目中提取所有字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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