0

我正在学习使用 ASTParser 解析 Java 项目的教程:

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

但我想要的是,使用 ASTPArser 来解析 Java 项目的战争或 jar 文件。可能吗?如果是,你能告诉我怎么做吗?

提前致谢!

4

1 回答 1

0

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 (e.g. 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.

于 2013-09-05T06:57:58.913 回答