简体   繁体   English

在Eclipse中搜索代码行

[英]Search a code line in Eclipse

I'm developing a code in Eclipse (java). 我正在Eclipse(java)中开发代码。 While debugging the code, I used a lot of System.out.println(...) . 在调试代码时,我使用了很多System.out.println(...) Now I need to delete all these lines. 现在我需要删除所有这些行。 To do this, I wrote System.out.println in Search->Java, but it hasn't provided any search result. 为此,我在Search-> Java中编写了System.out.println ,但它没有提供任何搜索结果。 So, how can I find all occurancies of this string System.out.println ? 那么,我怎样才能找到这个字符串System.out.println所有可能性呢?

Search -> File. 搜索 - >文件。 Input "System.out.println" and select the type of files you want to search in "*.java" (without quotes) 输入“System.out.println”并在“* .java”中选择要搜索的文件类型(不带引号)

The "Java search" is something different. “Java搜索”是不同的东西。 It doesn't allow you to find stuff in java files but methods/declarations/etc. 它不允许你在java文件中找到东西,但是方法/声明/等等。 in java files. 在java文件中。 For instance declare somewhere in your project "String canYou = "FindMe?";" 例如,在项目中的某处声明“String canYou =”FindMe?“;” and then do Search -> Java, input "String" and select "Type" and hit search. 然后执行搜索 - > Java,输入“String”并选择“Type”并点击搜索。 It should find all the String uses in you project, including the aforementioned one. 它应该找到您项目中的所有String用法,包括前面提到的。

Try writing System.out.println anywhere in your project, select this text and afterwards press ctrl + alt + g (sorry don't know exactly what kind of search this stands for) and it will give you all the occurrences of this string in all your projects(workspace-wise). 尝试在项目的任何地方编写System.out.println ,选择此文本,然后按ctrl + alt + g (抱歉不知道究竟是什么类型的搜索)并且它会给你所有出现的这个字符串所有项目(工作区)。 I'm 100% sure it stands for exactly something in search > java - you can take a closer look to see for exactly what. 我100%肯定它代表搜索> java中的确切内容 - 您可以仔细查看确切的内容。 Other than that you can have a conditional execution for the logs - ie 除此之外,您可以对日志进行条件执行 - 即

if(Consts.DEBUG){
    Log("something");
}

We have written an eclipse plugin to do the same. 我们编写了一个eclipse插件来做同样的事情。 It will find the System.out.println in your java code and comment it out. 它将在您的Java代码中找到System.out.println并将其注释掉。 We will soon have a version which will delete it also. 我们很快就会有一个版本删除它。 Hope this is useful. 希望这很有用。

http://eclipseo.blogspot.in/2013/05/commenting-systemoutprintln-from.html http://eclipseo.blogspot.in/2013/05/commenting-systemoutprintln-from.html

just search for println . 只是搜索println I bet eclipse is interpreting what you are putting in as a regex. 我敢打赌,eclipse正在解释你作为正则表达式所做的事情。

我会在println方法上找到用法(ctrl + shift + g)

press Control + H 按Control + H.

this will open up the search window, go to File Search tab and look for the system.out.println( 这将打开搜索窗口,转到文件搜索选项卡并查找system.out.println(

Use the menu Search->File and in the "Containing Text" field type in "System.out.println*", in the "File name patterns" field type in "*.java". 使用菜单Search-> File并在“Containing Text”字段中键入“System.out.println *”,在“文件名模式”字段中输入“* .java”。 Now press the "Replace" button in the lower right corner. 现在按下右下角的“替换”按钮。 Leave blank the "With" field and click the "Preview" button. 将“With”字段留空,然后单击“预览”按钮。 Uncheck any occurrences you want to keep and then press "OK". 取消选中要保留的任何事件,然后按“确定”。

You may want to make sure your code is in version control before attempting this in case you do it wrong and want to go back. 在尝试此操作之前,您可能希望确保您的代码处于版本控制之下,以防您执行错误并希望返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM