问题
Is there a plug-in for Eclipse that lets you search based on the Java AST (Abstract Syntax Tree) of your project files? The "Java Search" feature doesn't seem to cover cases like:
"Get me all the fields declared as type 'X' in all classes"
I can imagine many more possibilities that would open up with an AST-based search, but I don't even know if such a plug-in would have practical performance.
Update: As pointed out by Kevin below, the Java Search feature does cover the use case I mentioned. I'm still curious though about whether or not someone has written a plug-in that allows any arbitrary kind of AST search, ex. "Get all string concatenations" (InfixExpression with + operator and StringLiteral operand)
回答1:
Get me all the fields declared as type 'X' in all classes
I don't know what else you had in mind but I believe you can accomplish this specific search by doing the following:
- Opening up type X (Ctrl-Shift-T)
- Highlight the class name
- Ctrl-H to search
- Search for Type / Match Locations -> Field Types
回答2:
There are several Eclipse plug-ins that provide object-oriented query languages and aim to answer such queries. Some of them:
- Browse-by-Query
- SEA-QL
- Semmle code
Outside Eclipse there is JArchitect Code Query Language
回答3:
It's not exactly what you're looking for, but nWire for Java can give you a lot of information which is derived from the AST. It also has a full text search for searching any type, method, field, etc. Once you find what you're looking for, a click will show you all the associations of that component.
Check out the demo here.
来源:https://stackoverflow.com/questions/2202921/ast-based-search-for-eclipse