简体   繁体   中英

Using Java ASTParser can I parse a .war or .jar file?

I am following a tutorial to use ASTParser to parse a Java project:

http://www.programcreek.com/2011/08/code-to-parse-a-java-project/

But what I want is, using ASTPArser to parse a war or a jar file of a Java project. Is it possible? If yes, can you please tell me how?

Thanks in advance!

Do you understand what these technologies are?

An AST is an Abstract Syntax Tree. An AST is generated when a single compilation file is parsed. WAR and EAR are archive files, basically fancy ZIPs with some metadata files that tell special applications that read them (eg a compliant EJB server) how to handle them.

The Abstract Syntax Tree of an archive makes no sense. That's like the AST of a folder, or document. But the algorithm should be clear.

  1. Unpack the archive to a directory
  2. For each .java in that directory
  3. Open the file, build the AST, do whatever else you want.

Tools like Checkstyle do similar work under the covers to analyze projects. If you're stuck, or feeling brave, you may want to trace through that code to get an understanding of how they do it.

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