Eclipse 对所有文件进行文本搜索?
我目前正在优化我的代码(android 游戏),并希望将所有 foreach(for(:)) 替换为普通的 for。有办法找到它们吗? Ctrl-F 只查看当前文件,而 Ctrl-H 似乎没有找到任何 java 结构(不确定是否正确:ifs、whiles、访问器等)。最好没有插件,但接受任何答案。如果能够搜索任何字符串(搜索中的*),那就太好了。
TL;DR:寻找在 Eclipse 中查找所有 foreach 的方法。
I'm optimizing my code at the moment (android game), and wanted to replace all foreach(for(:)) with normal fors. Is there a way to find them all? Ctrl-F only looks through the current file and Ctrl-H doesn't seem to find any java constructs (not sure if right word: ifs, whiles, accessors etc.). Preferably without a plugin, but any answer accepted. It would also be nice if there would be a possibility to search for any string (* in Search).
TL;DR: Looking for way to find all foreaches in eclipse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,我必须说,这听起来是一个非常奇怪的优化。请记住,如果您有一个
LinkedList
,那么执行循环会比使用迭代器(for-each 循环所做的)糟糕得多。我闻到了微优化的味道。
也就是说,这里有一个适合您的解决方案:
搜索正则表达式,例如
for\s*\ (.*:
表达式匹配
for
形式的字符串,后跟一些空白,后跟(
后跟一些字符,后跟:
(这是 Java for-each 循环的特征)。First of all, I must say, this sounds like a really strange optimization. Keep in mind that if you have, say, a
LinkedList
you would be far worse of going through aloop, than using an iterator (which for-each loops does). Smells micro-optimizations long way to me.
That said, here's a solution for you:
Search for a regular expression such as
for\s*\(.*:
The expression matches strings on the form
for
, followed by some white whitespace, followed by(
followed by some characters, followed by:
(which kind of characterizes a Java for-each loop).右键单击项目,选择“搜索”,您就可以将所有
for
命令替换为for(.*;.*;.*)
等正则表达式与您想要的其他表达方式。Right-Click on the project, choose search and you're able to replace all
for
-commands with a regular expression likefor(.*;.*;.*)
with other expressions you want to.