是否有Java语言的Java解析器? [英] Is there a Java parser for the Java language?

查看:112
本文介绍了是否有Java语言的Java解析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个Java库,该库允许我解析Java源文件并为我提供代码的AST表示形式.

I'm looking for a java library that allows me to parse a java source file and that gives me an AST representation of the code.

实际上,我只对带有注释的类和方法定义感兴趣.我不需要方法代码的AST.

Actually I'm only interested in the class and method definitions with their annotations. I don't need the AST of the method code.

我正在使用此信息来生成代码.这就是为什么我不能首先编译源文件以从生成的类文件中获取信息的原因.在生成其他类之前,代码不会没有错误地进行编译.

I'm using this information for code generation. This is why I can't compile the source file first to get the information from the resulting class file. The code wouldn't compile without errors until I generate some additional classes.

推荐答案

我找到了项目 javaparser ,它解析单个Java文件并返回格式正确的AST.

I found the project javaparser, which parses a single java file and returns a well formed AST.

这篇关于是否有Java语言的Java解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆