简体   繁体   中英

How to trigger an Eclipse PMD plugin feature from source code?

I have installed an Eclipse plugin called PMD and I want to use only one of its feature (extracting Abstract Syntax Tree). The main problem is, instead of right clicking on each Java source code and then clicking on the AST feature, I want to fully automatize it without clicking on anything.

Therefore, the question is is there a way or method to call that plugin's feature from the source code that I have written.

I have tried to import PMD's maven project, however I have encountered some errors and there are many features that I won't be using (supporting other languages etc.). Thereby, I'm trying to find a more lightweighted approach. PMD is a quite big project to integrate it into my own project.

Thanks in advance.

Apparently, PMD Plugin has its source code open. Therefore, when the relevant classes and methods are converted into a standard Java desktop application (rather than Plugin), it is possible to create AST files without and UI interactions.

The conversion part is quite simple and easy. Since PMD Plugin requires UI, it uses classes such as IFile, IProject etc. Thereby, these classes could be changed equivalent classes such as; File, Project etc.

After giving the path of the project and by adding a simple code that recursively traverses its sub-directories will help you find all of the Java source files. Then by sending each of the Java source files into the AST generator method will do all the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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