Reputation: 85
I am developing a plugin to remove the sysout statements in an eclipse workspace. As part of this plugin I also want to provide the functionality to search and view the instances of sysout statements in eclipse search view. Is there a way to do this using the eclipse JDT API?
Upvotes: 0
Views: 683
Reputation: 28757
I'd recommend using a org.eclipse.jdt.core.search.SearchEngine
instance. In particular, you would be interested in calling the org.eclipse.jdt.core.search.SearchEngine.search(SearchPattern, SearchParticipant[], IJavaSearchScope, SearchRequestor, IProgressMonitor)
.
Take a look at the Javadoc for that method. You need to provide a proper SearchPattern
for the thing you are looking for. I would create a pattern for the System.out
and System.err
references, rather than PrintStream.println
references (since these may be legitimate).
You can specify the search scope, also. So, it can be the entire workspace, a set of projects, or even the current selection.
Upvotes: 1
Reputation: 1240
You can use Abstract Syntax Tree (AST) and the Java Model to modify your code.
To keep it abstract, you could have the user mark the expression to search for (and replace) in the outline view (in this case System.out
). You can then get access to the selected IMember
through the ISelection
and use SearchEngine
to find all references to it. After you have collected all the references you want to change you can use an ASTParser
to get the AST for the source files. I would recommend to use ASTRewrite
to do (and collect) the changes.
Here are two articles I found to be very helpfull:
Upvotes: 1