Load a class from the users workspace

2019-07-17 05:21发布

问题:

I´m writing an eclipse plugin which should show some information of an enum class. The new view should show all enum constants and the assigned values. The enum values are calculated in the constructor somehow and it is not obvious in the editor which value they will have at runtime. So that´s the motivation for the plugin. I have tried to access the class which is opened in the editor by the eclipse AST. That way I´m getting the enum constant names of that file but not the assigned values at runtime.

So how can I get the enum values? Is it possible to load a class from the user´s workspace and use reflection to access the values of that class?

回答1:

I have solved this on the dirty way: I am looking up the .class file from the bin directory, loading it and grabbing the values on this way.