Created
March 29, 2017 23:15
-
-
Save dehowell/72c1a410b4c4870ee36441336b34588e to your computer and use it in GitHub Desktop.
Visit Classes Used
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.bcel.Repository; | |
import org.apache.bcel.classfile.Constant; | |
import org.apache.bcel.classfile.ConstantClass; | |
import org.apache.bcel.classfile.ConstantPool; | |
import org.apache.bcel.classfile.JavaClass; | |
/** | |
* Prototype code to walk the graph of referenced classes, for use hunting down dead code. | |
*/ | |
public class Analyzer { | |
public static void main(String[] args) throws Exception { | |
JavaClass clazz = Repository.lookupClass("Foo"); | |
Analyzer analyzer = new Analyzer(); | |
analyzer.traverse(clazz); | |
} | |
public void traverse(JavaClass node) throws Exception { | |
ConstantPool pool = node.getConstantPool(); | |
for (Constant constant : pool.getConstantPool()) { | |
if (constant instanceof ConstantClass) { | |
String className = pool.constantToString(constant); | |
if (className != node.getClassName() && !className.startsWith("java")) { | |
System.out.println(className); | |
traverse(Repository.lookupClass(className)); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment