使用ASM来查找“隐式”的通用签名。变量 [英] Using ASM to find generic signatures of "implicit" variables

查看:283
本文介绍了使用ASM来查找“隐式”的通用签名。变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASM 4.0构建一个依赖搜索工具,并且发现了一个我一直无法解决的角落案例。我遇到的问题与在下面的代码中识别MyClass的用法有关。

  public void aMethod(){
新的ArrayList<扩展MyClass>();



$ b

ArrayList的用法可以使用MethodVisitor.visitTypeInst()来标识,但不能签名方法在该范围内可用于标识泛型类型参数中的用法。 MethodVisitor.visitLocalVariable()也不是解决方案,因为没有创建本地变量。如果一个局部变量被显式声明为这样:

  public void aMethod(){
ArrayList<扩展MyClass> list = new ArrayList <?扩展MyClass>();
}

MethodVistor.visitLocalVariable()可以正常工作,因为它提供对通用通过签名参数输入信息。只有在隐式 的情况下,没有声明局部变量,我找不到访问泛型类型参数的方法。



我假设有一些方法可以通过此代码的通用信息访问类属性,但我不确定如何执行此操作。



感谢您的帮助!!

解决方案 在方法体中输入参数信息被丢弃在字节代码生成期间。您将无法通过分析字节码来获取它。


I am building a dependency search tool using ASM 4.0 and I have found a corner case which I have been unable to solve. The problem I'm having has to do with identifing usages of MyClass in the code below.

public void aMethod() {
   new ArrayList<? extends MyClass>();
}

The usage of ArrayList can be identified using MethodVisitor.visitTypeInst(), but no signature method is available in that scope to identify the usage in the generic type parameter. MethodVisitor.visitLocalVariable() is not the solution either, since no local var is created. If a local var is explicitly declared as such:

public void aMethod() {
    ArrayList<? extends MyClass> list = new ArrayList<? extends MyClass>();
}

The MethodVistor.visitLocalVariable() works fine, as it provides access to the generic type information via the signature param. It is only in the implicit case, where no local var is declared, that I cannot find a way to access the generic type parameters.

I'm assuming there is some way to access the class attribute with the generic information for this code, but I'm am unsure how to do this.

Thanks for any help!!

解决方案

Type argument information in method bodies is discarded during byte code generation. You won't be able to get at it by analyzing byte code.

这篇关于使用ASM来查找“隐式”的通用签名。变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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