在方法及其引用中搜索对象
我想在类文件中搜索所有方法
,并在其引用
中搜索特定对象类型或关键字。
例如: 假设我有一个名为 myclassfile.java 的类文件,它包含如图所示的几种方法;
class myclassfile
{
void doSomeFoo()
{
someReferenceClass.doFoo();
}
..
}
正如
class someReferenceClass
{
static void doFoo()
{
for(int i=0; i <10; i++)
{
..
}
}
您所看到的,myclassfile
有一个方法调用 someReferenceClass
,然后调用其 doFoo()
函数。我想做的是创建一个程序,对 myclassfile
执行某种搜索:
- 找到对某个方法有引用调用的所有方法,该方法具有
for-loop
> 在其日常工作中。
因此,对于上面的示例,myclassfile
将提交 doSomeFoo()
作为匹配项。
有人知道该怎么做吗?
I want to search a class file for all Methods
and its references
for specific Object types or Keyword.
For Example:
Say I have class file called myclassfile.java
which holds several methods as shown;
class myclassfile
{
void doSomeFoo()
{
someReferenceClass.doFoo();
}
..
}
And
class someReferenceClass
{
static void doFoo()
{
for(int i=0; i <10; i++)
{
..
}
}
As you can see myclassfile
has a method which calls someReferenceClass
and then invoke its doFoo()
function. What I want to do, is create a program which peforms some kind of search against myclassfile
to:
- Locate all methods which has a reference call to some method, that has
for-loop
within its routine.
And so for the example above, myclassfile
will submit doSomeFoo()
as a match.
Do anyone know how to go about this?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要深入研究 AST 或字节代码,具体取决于您喜欢哪种类型的兔子洞。使用 AST 会容易得多。
You'll need to dig into either an AST or into byte code, depending on which type of rabbit hole you prefer. Working with an AST would be much easier.
不要相信有办法做到这一点。反射可以让您访问类的方法和字段,但不能访问其实现。
Don't believe there is a way to do this. Reflection will give you access to the methods and fields of a class but does not give access to the implementation.