从用户工作区加载类 [英] Load a class from the users workspace

查看:126
本文介绍了从用户工作区加载类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个eclipse插件,它应该显示一个枚举类的一些信息。新视图应显示所有枚举常量和分配的值。枚举值在构造函数中以某种方式计算,编辑器在运行时将不会显示哪些值。所以这是插件的动机。
我试图访问在编辑器中由eclipse AST打开的类。这样我就可以得到该文件的枚举常量名称,而不是运行时分配的值。



那么如何获取枚举值呢?可以从用户的工作区加载类,并使用反射来访问该类的值吗?

解决方案

我已经解决了这个脏的方式:我正在从bin目录中查找 .class 文件,加载它并以这种方式获取值。


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?

解决方案

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.

这篇关于从用户工作区加载类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆