Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add easy method to get the parsed information from java.lang.reflection #4312

Open
LarsEckart opened this issue Feb 5, 2024 · 2 comments
Open
Labels
Question (JP usage) How to use JP to inspect/modify the AST - please close your question once answered!

Comments

@LarsEckart
Copy link

Intention

We generate documentation to list all of the entry points people might be interested for our project. In this documentation, we also want to link to the source code. To do this, we used JavaParser as the default java reflection API will not give us line numbers. This meant being able to take a method found via reflection and find the corresponding one when parsing the source file.

Overall, this worked very well and we're greatful for java parser but it did require a bit of work to get there. We thought about publishing it as a separate utility, but believe it would be better as part of java parser.

What it is

There are two main functionalities, which we needed, and think could be contributed back.

  1. MethodDeclaration getMethodDeclaration(Method method)
  2. boolean isParsedMethodEqualToCompiledMethod(Method compiledMethod, MethodDeclaration parsedMethod)

Number 2 greatly enables number 1 but number 1 will also find the corresponding source file and parse it as well.

Ways to contribute back

Thanks!

Lars, Llewellyn, Oliver

@jlerbsc jlerbsc added the Question (JP usage) How to use JP to inspect/modify the AST - please close your question once answered! label Feb 5, 2024
@jlerbsc
Copy link
Collaborator

jlerbsc commented Feb 5, 2024

Thank you for your suggestion, but it seems to me that what you're describing is very specific to your project and doesn't need to be integrated into JP.

@LarsEckart
Copy link
Author

The main functionality this offers is checking that a parsed type is equal to a compiled type found via reflection, can you clarify why this is specific to us and wouldn't fit into JP?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question (JP usage) How to use JP to inspect/modify the AST - please close your question once answered!
Projects
None yet
Development

No branches or pull requests

2 participants