使用反射获取方法的调用层次结构 [英] getting call hierarchy of a method using reflections

查看:67
本文介绍了使用反射获取方法的调用层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Java反射从一个类中获取方法(已加载这些类).现在我想获取这些方法的调用层次结构.如何在Eclipse IDE中使用调用层次结构选项呢?任何示例或链接???

解决方案

提出的解决方案是使用 Thread.currentThread().getStackTrace()以获得调用者的当前跟踪./p>

但是,您想要获取的信息不是针对当前正在执行的方法,而是针对任何类上的任何方法.这不容易做到.我认为您必须使用字节码实用程序检查类路径上的所有类,并匹配调用指令.您会花很多时间在某些事情上,而且我敢肯定它是不需要的,除非您正在开发IDE.

无论如何,您都可以获取Eclipse或NetBeans源,并查看其实现方式.

i used java reflections to get methods from a class(loaded those classes).Now i want to get the call hierarchy of those methods.How can i use call hierarchy option in eclipse IDE for that?any examples or links????

解决方案

The solutions proposed is to use Thread.currentThread().getStackTrace() in order to obtain the current trace of callers.

However, you want to get this information not for the currently executing method, but for any method on any class. This can't be done easily. I think you have to inspect all classes on the classpath with a bytecode utility and match the calling instructions. Something you will spend too much time on, and I'm pretty sure it isn't needed, unless you are developing an IDE.

Anyway, you can get Eclipse or NetBeans sources and see how it is implemented there.

这篇关于使用反射获取方法的调用层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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