<legend id='pwJHf'><style id='pwJHf'><dir id='pwJHf'><q id='pwJHf'></q></dir></style></legend>
<i id='pwJHf'><tr id='pwJHf'><dt id='pwJHf'><q id='pwJHf'><span id='pwJHf'><b id='pwJHf'><form id='pwJHf'><ins id='pwJHf'></ins><ul id='pwJHf'></ul><sub id='pwJHf'></sub></form><legend id='pwJHf'></legend><bdo id='pwJHf'><pre id='pwJHf'><center id='pwJHf'></center></pre></bdo></b><th id='pwJHf'></th></span></q></dt></tr></i><div id='pwJHf'><tfoot id='pwJHf'></tfoot><dl id='pwJHf'><fieldset id='pwJHf'></fieldset></dl></div>

<tfoot id='pwJHf'></tfoot>
      1. <small id='pwJHf'></small><noframes id='pwJHf'>

        • <bdo id='pwJHf'></bdo><ul id='pwJHf'></ul>

        查找 Java 类中的所有依赖项

        Find all dependencies in a Java class(查找 Java 类中的所有依赖项)

        • <i id='l2HPf'><tr id='l2HPf'><dt id='l2HPf'><q id='l2HPf'><span id='l2HPf'><b id='l2HPf'><form id='l2HPf'><ins id='l2HPf'></ins><ul id='l2HPf'></ul><sub id='l2HPf'></sub></form><legend id='l2HPf'></legend><bdo id='l2HPf'><pre id='l2HPf'><center id='l2HPf'></center></pre></bdo></b><th id='l2HPf'></th></span></q></dt></tr></i><div id='l2HPf'><tfoot id='l2HPf'></tfoot><dl id='l2HPf'><fieldset id='l2HPf'></fieldset></dl></div>

              <tfoot id='l2HPf'></tfoot>
              • <legend id='l2HPf'><style id='l2HPf'><dir id='l2HPf'><q id='l2HPf'></q></dir></style></legend>
                  <bdo id='l2HPf'></bdo><ul id='l2HPf'></ul>
                    <tbody id='l2HPf'></tbody>

                  <small id='l2HPf'></small><noframes id='l2HPf'>

                  本文介绍了查找 Java 类中的所有依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试获取 Java 类中的所有依赖项,包括用于泛型参数化和局部变量类型的类.到目前为止,我发现的最好的框架是 apache bcel.使用它,我可以轻松地从字节码中找到所有字段、方法参数和局部变量.基本上除了泛型和局部变量类型之外的所有内容.例如,从 List 行开始.points = new ArrayList(); 我只能找到一个依赖项 - 使用 bcel 中的 JavaClass.getConstantPool() 方法的 ArrayList.它既检测不到 List 接口也检测不到 Point 类.我还尝试了 tattletale 和 CDA,不幸的是没有成功(结果相同).检查导入是不够的——我还需要来自同一个包的依赖项,而且我不能接受通配符.如果有任何帮助,我将不胜感激.

                  I'm trying to get all dependencies in a Java class, including classes used for generics parametrization and local variables types. So far best framework I've found is apache bcel. Using it I can easily find all fields, method arguments and local variables from byte code. Basically everything except of generics and local variables types. For example, from line List<Point> points = new ArrayList<Point>(); I can only find one dependency - ArrayList using JavaClass.getConstantPool() method from bcel. It can't detect neither List interface nor Point class. I also tried tattletale and CDA, unfortunately without success (the same results). Examining imports is not enough - I need also dependencies from the same package and I can't accept wildcards. I would be grateful for any help.

                  推荐答案

                  我终于找到了解决方案.ASM 字节码框架 是正确的工具.使用官方 tutorial 和对 example 很容易获得所有需要的依赖项.在示例中,已经有一个访问者类 DependencyVisitor 可以满足我的要求.为了获得正确的格式,我只需要更改 DependencyVistitor 示例代码中的一种方法,因此它添加了完整的类名而不是只添加包:

                  I've finally found solution. ASM Bytecode Framework is the right tool to use. Using official tutorial and right example it's quite easy to get all needed dependencies. In the example there is already a visitor class DependencyVisitor which does what I want. To get right formatting I had to change only one method in DependencyVistitor example code, so it adds full class names instead of packages only:

                  private String getGroupKey(String name)
                  {
                          //Just comment that block so you can get full class names instead of package only
                          /*
                          int n = name.lastIndexOf('/');
                          if (n > -1)
                          {
                              name = name.substring(0, n);
                          }
                         */
                          // Replace resource char with package separator char        
                          packages.add(name.replace("/", "."));
                          //packages.add(name);
                          return name;
                  }
                  

                  查看 DependencyVisitor 代码,您可以轻松了解它的作用并根据需要对其进行修改.在我的示例类上运行它会给我很好的、有用的输出:[java.util.ArrayList, java.lang.Object, java.util.List, java.awt.Point, goobar.test.asmhello.TestClass, java.lang.String, java.lang.Integer, java.awt.Graphics,goobar.test.asmhello.TestClass2].它包含我使用过的每个类和接口以及用于泛型参数化的每个类型.

                  Looking at DependencyVisitor code you can easily understand what it does and modify it to your needs. Running it on my example class it gives me nice, useful output: [java.util.ArrayList, java.lang.Object, java.util.List, java.awt.Point, goobar.test.asmhello.TestClass, java.lang.String, java.lang.Integer, java.awt.Graphics, goobar.test.asmhello.TestClass2]. It contains every class and interface I've used and every type used for generics parameterization.

                  这篇关于查找 Java 类中的所有依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Maven JAVA_HOME environment variable is not defined correctly, but it is(Maven JAVA_HOME 环境变量未正确定义,但它是)
                  Java System Environment Variable(Java 系统环境变量)
                  Java -classpath option(Java -classpath 选项)
                  Read environment variable in SpringBoot(在 SpringBoot 中读取环境变量)
                  Tomcat 8 - context.xml use Environment Variable in Datasource(Tomcat 8 - context.xml 在数据源中使用环境变量)
                  Issue with JAVA_HOME(JAVA_HOME 的问题)

                    <tbody id='KeIIZ'></tbody>

                  <small id='KeIIZ'></small><noframes id='KeIIZ'>

                      <bdo id='KeIIZ'></bdo><ul id='KeIIZ'></ul>

                      1. <i id='KeIIZ'><tr id='KeIIZ'><dt id='KeIIZ'><q id='KeIIZ'><span id='KeIIZ'><b id='KeIIZ'><form id='KeIIZ'><ins id='KeIIZ'></ins><ul id='KeIIZ'></ul><sub id='KeIIZ'></sub></form><legend id='KeIIZ'></legend><bdo id='KeIIZ'><pre id='KeIIZ'><center id='KeIIZ'></center></pre></bdo></b><th id='KeIIZ'></th></span></q></dt></tr></i><div id='KeIIZ'><tfoot id='KeIIZ'></tfoot><dl id='KeIIZ'><fieldset id='KeIIZ'></fieldset></dl></div>
                      2. <tfoot id='KeIIZ'></tfoot>

                          <legend id='KeIIZ'><style id='KeIIZ'><dir id='KeIIZ'><q id='KeIIZ'></q></dir></style></legend>