Eclipse 4.x中Command是如何映射到Handler的
来源:互联网 发布:鸭鸭网络数字点卡平台 编辑:程序博客网 时间:2024/06/09 08:37
1. Eclipse中的Command模式,使得具体的实现和Command定义分离,便于维护。
但是在Debug的时候,或者没有souce code的时候,我们想知道每一个commandId对应的Handler是什么,怎么办?
2. 在Eclipse 4.x中,其实当Eclipse启动完成后,它已经创建了commandId和对应Handler的Map,保存在EclipseContext中,
然后通过反射调用到对应的Handler。 见下图:
Eclipse是在上图中我框出来的地方,通过commandId在EclipseContext中查找到。
3. 如何将EclipseContext中的Handler都dump出来呢?
一句话,反射。
注意,以下代码我只在Eclipse 4.3.0上测试通过。
//try to print all handler in eclipse 4.xresult = ReflectionUtils.getField("e4Context", site);if(!isSuccess(result)) {return;}if(result instanceof IEclipseContext) {IEclipseContext context = (IEclipseContext)result;printHandlerForEclipseContext(context, 0);}
@SuppressWarnings("unchecked")private void printHandlerForEclipseContext(IEclipseContext context, int step) {Assert.isNotNull(context);Object result = null;if(step != 0) {result = ReflectionUtils.getField("localValueComputations", context);} else {result = ReflectionUtils.getField("localValues", context);}if(!isSuccess(result)) {return;}if(result instanceof Map) {String stepString = makeStep(step);Map<String, Object> localValueComputations = (Map<String, Object>)result;for (String string : localValueComputations.keySet()) {Object object = localValueComputations.get(string);String last = object.toString();if(string.startsWith("legacy::handler::")) {if(object instanceof ArrayList) {ArrayList list = (ArrayList)object;//TODO may be more than one item in listobject = list.get(0);if(object instanceof IHandlerActivation) {IHandlerActivation activation = (IHandlerActivation)object;last = activation.getHandler().toString();}}}System.out.println(stepString + string + ", " + last);}}result = null;result = ReflectionUtils.invokeMethod(context, "getChildren");if(!isSuccess(result)) {return;}if(result instanceof Set) {Set<IEclipseContext> children = (Set<IEclipseContext>)result;Iterator<IEclipseContext> iterator = children.iterator();IEclipseContext child = null;int moreStep = step + 1;while(iterator.hasNext()) {child = iterator.next();printHandlerForEclipseContext(child, moreStep);}step ++;}}
以下是我的屏幕输出的一部分,输出格式为:commandId, Handler
...
legacy::handler::org.eclipse.ui.edit.text.recenter, ActionHandler(org.eclipse.ui.texteditor.RecenterAction@7efaa9e2)
legacy::handler::org.eclipse.jdt.ui.edit.text.java.search.declarations.in.hierarchy, ActionHandler(org.eclipse.jdt.ui.actions.FindDeclarationsInHierarchyAction@14c26e4a)
legacy::handler::org.eclipse.jdt.ui.edit.text.java.search.declarations.in.project, ActionHandler(org.eclipse.jdt.ui.actions.FindDeclarationsInProjectAction@174043f5)
legacy::handler::org.eclipse.jdt.ui.edit.text.java.surround.with.try.multicatch, ActionHandler(org.eclipse.jdt.ui.actions.SurroundWithTryMultiCatchAction@49e3c996)
legacy::handler::org.eclipse.jdt.ui.edit.text.java.override.methods, ActionHandler(org.eclipse.jdt.ui.actions.OverrideMethodsAction@11e18e8c)
legacy::handler::org.eclipse.ui.edit.findPrevious, ActionHandler(org.eclipse.ui.texteditor.FindNextAction@69d5ee81)
handler::org.eclipse.jdt.ui.edit.text.java.remove.block.comment, org.eclipse.ui.internal.handlers.LegacyHandlerService$HandlerSelectionFunction@207462c0
...
- Eclipse 4.x中Command是如何映射到Handler的
- Eclipse RCP Command的Handler设置不起作用?
- cocos2d-x 的Eclipse工程中如何加入到c++源码文件夹
- 如何从Eclipse中导入第三方库(并且是带有JNI的)到Android Studio开发工具中?
- Cocos2d-x命令生成的工具导入到Eclipse中
- 如何绑定Command的快捷键到上下文
- 内核kernel以及根文件系统rootfs是如何映射到对应的nand flash的
- 内核kernel以及根文件系统rootfs是如何映射到对应的nand FLASH地址的
- 内核kernel以及根文件系统rootfs是如何映射到对应的nand flash的
- 内核kernel以及根文件系统rootfs是如何映射到对应的nand flash的
- 内核kernel以及根文件系统rootfs是如何映射到对应的nand flash的
- 内核kernel以及根文件系统rootfs是如何映射到对应的nand flash
- Eclipse 平台中是如何支持XML开发的
- 驱动中suspend函数是如何被调用到的。
- Eclipse 是如何启动的
- Tornado的url-handler映射中可以使用字符串
- 高级语言如何映射到汇编的映射
- 如何将Android Studio的工程导入到eclipse中
- Hessian介绍
- 产品新人如何入门,从需求分析开始!
- java实现最大子序列问题——————性能最优的算法
- bootstrap中的carosel
- 不同服务器,相同服务器,数据库之间数据的转移
- Eclipse 4.x中Command是如何映射到Handler的
- Cocos2d-x 2.2版本(及更高版本)创建项目方法
- memcached支持mybatis3
- MongoDB命令及SQL语法对比
- 百度爬关键词的排名
- putty中文乱码及颜色设置
- 监听SD卡插拔广播
- erlang win8.1中erlide 智能提示失效解决方法
- java基础学习—设计模式