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

Java Model #727

Open
vorburger opened this issue Jun 23, 2024 · 4 comments
Open

Java Model #727

vorburger opened this issue Jun 23, 2024 · 4 comments
Labels
model/☕ Models of Java

Comments

@vorburger
Copy link
Member

vorburger commented Jun 23, 2024

./enola -v get --load file:bazel-bin/java/dev/enola/cli/enola_deploy.jar enola:/ should list Java Class/Enum/etc. Type Things; get one of them should show its references.

In an integration test, use this.

This could then be used e.g. for #502.

@vorburger vorburger added the model/☕ Models of Java label Jun 24, 2024
@vorburger
Copy link
Member Author

should show its references

I have, so far, zoomed in to possibly using one of the following two libraries for this, but ... it's not super clear to me if either of them will find references to the types used in the implementation body of methods, and not just the methods' signatures, fields and class declarations... I should probably just try it out to see!

If they both do not provide this, then this probably requires BCEL or ByteBuddy or Javassist? That would likely be quite a bit more involved than I was thinking of doing here, only for this; and I de-prioritize this if that was the case.

@vorburger
Copy link
Member Author

vorburger commented Jun 24, 2024

ClassGraph: Has ignoreMethodVisibility, but glancing over its MethodInfo makes me think it cannot? @lukehutch am I getting this right - will ClassGraph provide metadata from signatures, but not method body implementations? Or is there another way (API) which I'm missing? (Hi! We've classgraph/classgraph#256.)

https://github.com/classgraph/classgraph/wiki/ClassInfo-API#generating-a-graphviz-dot-file-for-class-graph-visualization seems to partially answer what I'm after here - but I still don't understand which ClassGraph API would provide me said "relationships between classes that are based on code in method bodies".

@vorburger
Copy link
Member Author

but I still don't understand which ClassGraph API would provide me said ...

ClassGraph.enableInterClassDependencies() seems to explain it... I think I now see how this could be done!

@lukehutch
Copy link

Classgraph does not parse they bytecode in a classfile, it only parses the class metadata (including signatures of methods and fields, etc.). The bytecode format is complex and more likely to change than class metadata, so keeping up with the bytecode format is a non-goal for ClassGraph. The only reliable way to read bytecode is to use the ASM library.

So basically if the info you need is in the bytecode, ClassGraph can't help, and you have to use ASM. If it's not, ClassGraph can help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
model/☕ Models of Java
Projects
None yet
Development

No branches or pull requests

2 participants