Eclipse 对所有文件进行文本搜索?

发布于 2024-11-29 23:25:23 字数 236 浏览 0 评论 0原文

我目前正在优化我的代码(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一杆小烟枪 2024-12-06 23:25:23

首先,我必须说,这听起来是一个非常奇怪的优化。请记住,如果您有一个 LinkedList,那么执行循环会

for (int i = 0; i < list.size(); i++) {
    element = list.get(i);
    ...

比使用迭代器(for-each 循环所做的)糟糕得多。我闻到了微优化的味道。

也就是说,这里有一个适合您的解决方案:

  1. 确保选择了根源文件夹
  2. 单击搜索/文件搜索
  3. 将范围标记为“选定的资源”
  4. 标记正则表达式
  5. 搜索正则表达式,例如 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 a

for (int i = 0; i < list.size(); i++) {
    element = list.get(i);
    ...

loop, than using an iterator (which for-each loops does). Smells micro-optimizations long way to me.

That said, here's a solution for you:

  1. Make sure the root source folder is selected
  2. Click Search / File Search
  3. Mark Scope as "Selected resources"
  4. Mark Regular expression
  5. 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).

冷了相思 2024-12-06 23:25:23

右键单击项目,选择“搜索”,您就可以将所有 for 命令替换为 for(.*;.*;.*) 等正则表达式与您想要的其他表达方式。

Right-Click on the project, choose search and you're able to replace all for-commands with a regular expression like for(.*;.*;.*) with other expressions you want to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文