// try finding outer class name from InnerClasses attribute assigned to this class
for (Attribute attr : javaClass.getAttributes()) {
if (attr instanceof InnerClasses) {
// search for InnerClass entry that has current class as inner and some other class as outer
InnerClass[] innerClss = ((InnerClasses) attr).getInnerClasses();
ConstantPool cpool = javaClass.getConstantPool();
for (InnerClass innerCls : innerClss) {
// skip entries that miss any necessary component, 0 index means "undefined", from JVM Spec 2nd ed. par. 4.7.5
if (innerCls.getInnerClassIndex() == 0 || innerCls.getOuterClassIndex() == 0) {
continue;
}
// resolve inner class name, check if it matches current class name
ConstantClass innerClsInfo = (ConstantClass) cpool.getConstant(innerCls.getInnerClassIndex());
// class names in constant pool use '/' instead of '.', from JVM Spec 2nd ed. par. 4.2
String innerClsName = cpool.getConstantUtf8(innerClsInfo.getNameIndex()).getValue().replace('/', '.');
if (innerClsName.compareTo(className) == 0) {
// resolve outer class name
ConstantClass outerClsInfo = (ConstantClass) cpool.getConstant(innerCls.getOuterClassIndex());
// class names in constant pool use '/' instead of '.', from JVM Spec 2nd ed. par. 4.2
String outerClsName = cpool.getConstantUtf8(outerClsInfo.getNameIndex()).getValue().replace('/', '.');
UnresolvedType outer = UnresolvedType.forName(outerClsName);
return outer.resolve(getResolvedTypeX().getWorld());
}
}
}
}
for (Attribute attr : javaClass.getAttributes()) { // bug339300
ConstantPool cpool = javaClass.getConstantPool();
if (attr instanceof EnclosingMethod) {
EnclosingMethod enclosingMethodAttribute = (EnclosingMethod) attr;
if (enclosingMethodAttribute.getEnclosingClassIndex() != 0) {
ConstantClass outerClassInfo = enclosingMethodAttribute.getEnclosingClass();
String outerClassName = cpool.getConstantUtf8(outerClassInfo.getNameIndex()).getValue().replace('/', '.');
UnresolvedType outer = UnresolvedType.forName(outerClassName);
return outer.resolve(getResolvedTypeX().getWorld());
}
}
}