简体   繁体   English

我可以使用Java ASTParser解析.war或.jar文件吗?

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

I am following a tutorial to use ASTParser to parse a Java project: 我正在遵循使用ASTParser解析Java项目的教程:

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. 但是我想要的是使用ASTPArser解析Java项目的war或jar文件。 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. AST是抽象语法树。 An AST is generated when a single compilation file is parsed. 当解析单个编译文件时,将生成AST。 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. WAR和EAR是归档文件,基本上是带有一些元数据文件的ZIP文件,这些元数据文件告诉读取它们的特殊应用程序(例如,兼容的EJB服务器)如​​何处理它们。

The Abstract Syntax Tree of an archive makes no sense. 归档文件的抽象语法树没有任何意义。 That's like the AST of a folder, or document. 就像文件夹或文档的AST一样。 But the algorithm should be clear. 但是算法应该清楚。

  1. Unpack the archive to a directory 将档案解压缩到目录
  2. For each .java in that directory 对于该目录中的每个.java
  3. Open the file, build the AST, do whatever else you want. 打开文件,构建AST,然后执行其他任何操作。

Tools like Checkstyle do similar work under the covers to analyze projects. Checkstyle之类的工具在后台进行类似的工作以分析项目。 If you're stuck, or feeling brave, you may want to trace through that code to get an understanding of how they do it. 如果您陷入困境或感到胆怯,则可能需要遍历该代码以了解他们的操作方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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