Open vorburger opened 1 week ago
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!
ArchUnit: Its Dependency looks like it might provide such details? ("class calls a method/constructor of another class")
ClassGraph: Has [ignoreMethodVisibility](https://javadoc.io/static/io.github.classgraph/classgraph/4.8.174/io/github/classgraph/ClassGraph.html#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 interacted in the past.)
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.
ClassGraph: Has [ignoreMethodVisibility](https://javadoc.io/static/io.github.classgraph/classgraph/4.8.174/io/github/classgraph/ClassGraph.html#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 https://github.com/classgraph/classgraph/issues/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".
but I still don't understand which ClassGraph API would provide me said ...
[ClassGraph.enableInterClassDependencies()](https://javadoc.io/static/io.github.classgraph/classgraph/4.8.174/io/github/classgraph/ClassGraph.html#enableInterClassDependencies()) seems to explain it... I think I now see how this could be done!
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.
./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.