Methods Summary |
---|
void | addClass(java.lang.String classname)Add a classname to the list of dependency classes
dependencies.put(classname, classname);
|
private void | addClasses(java.lang.String string)Add all the classes from a descriptor string.
StringTokenizer tokens = new StringTokenizer(string, ";");
while (tokens.hasMoreTokens()) {
String descriptor = tokens.nextToken();
int pos = descriptor.indexOf('L");
if (pos != -1) {
addSlashClass(descriptor.substring(pos + 1));
}
}
|
private void | addSlashClass(java.lang.String classname)Adds a class name in slash format
(for example org/apache/tools/ant/Main).
addClass(classname.replace('/", '."));
|
public void | clearDependencies()Clear the curretn set of collected dependencies.
dependencies.clear();
|
public java.util.Enumeration | getDependencies()Get the dependencies collected by this visitor
return dependencies.keys();
|
public void | visitConstantClass(org.apache.bcel.classfile.ConstantClass constantClass)Visit a class reference
String classname
= constantClass.getConstantValue(constantPool).toString();
addSlashClass(classname);
|
public void | visitConstantNameAndType(org.apache.bcel.classfile.ConstantNameAndType obj)Visit a name and type ref
Look for class references in this
String name = obj.getName(constantPool);
if (obj.getSignature(constantPool).equals("Ljava/lang/Class;")
&& name.startsWith("class$")) {
String classname = name.substring(6).replace('$", '.");
// does the class have a package structure
int index = classname.lastIndexOf(".");
if (index > 0) {
char start;
// check if the package structure is more than 1 level deep
int index2 = classname.lastIndexOf(".", index - 1);
if (index2 != -1) {
// class name has more than 1 package level 'com.company.Class'
start = classname.charAt(index2 + 1);
} else {
// class name has only 1 package level 'package.Class'
start = classname.charAt(0);
}
// Check to see if it's an inner class 'com.company.Class$Inner'
if ((start > 0x40) && (start < 0x5B)) {
// first letter of the previous segment of the class name 'Class'
// is upper case ascii. so according to the spec it's an inner class
classname = classname.substring(0, index) + "$"
+ classname.substring(index + 1);
addClass(classname);
} else {
// Add the class in dotted notation 'com.company.Class'
addClass(classname);
}
} else {
// Add a class with no package 'Class'
addClass(classname);
}
}
|
public void | visitConstantPool(org.apache.bcel.classfile.ConstantPool constantPool)Visit the constant pool of a class
this.constantPool = constantPool;
|
public void | visitField(org.apache.bcel.classfile.Field field)Visit a field of the class.
addClasses(field.getSignature());
|
public void | visitJavaClass(org.apache.bcel.classfile.JavaClass javaClass)Visit a Java class
addClass(javaClass.getClassName());
|
public void | visitMethod(org.apache.bcel.classfile.Method method)Visit a method of the current class
String signature = method.getSignature();
int pos = signature.indexOf(")");
addClasses(signature.substring(1, pos));
addClasses(signature.substring(pos + 1));
|