Accessing symbol table in .class files

↘锁芯ラ 提交于 2019-12-11 09:32:57

问题


For an arbitrary code base in Java, I want to create a table (conceptually) of USES and USED-BY relations between symbols and types. A symbol table has the information I need. However, writing a front end seems like a huge task and threatens to turn my project into an even bigger sub-project. There's no reason for this, it seems to me ,because bytecode, the Java .class file necessarily contains within it such a symbol table for each class so that it can resolve types and references.

My question is -

How can I programmaticly access the symbol table inside a set of .class files so that I can create the USES / USED-BY table I want? Has anyone already done this (surely the answer is yes) and is the tool to do this not already a library ?


回答1:


Take a look at ASM bytecode manipulation framework. This tutorial has an example of dependencies retrieval from the bytecode. Though it can be significantly simplified if you use more recently introduced RemappingClassAdapter.




回答2:


You can have the bytecode with javap , after that it is just text parsing.



来源:https://stackoverflow.com/questions/10979102/accessing-symbol-table-in-class-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!