use of com.jopdesign.common.type.ClassRef in project jop by jop-devel.
the class InnerClassesInfo method buildInnerClasses.
/**
* Build a map of InnerClasses containing all entries for all inner classes in the 'classes'
* parameter and all their enclosing inner classes.
*
* @param classes a collection of classes the result should contain.
* @return the map of className->InnerClass containing all inner classes in the 'classes' parameter.
*/
private Collection<InnerClass> buildInnerClasses(Collection<ClassRef> classes) {
List<ClassRef> queue = new LinkedList<ClassRef>(classes);
Set<String> visited = new HashSet<String>();
List<InnerClass> inner = new LinkedList<InnerClass>();
ConstantPoolGen cpg = classGen.getConstantPool();
InnerClasses ic = getInnerClassesAttribute();
while (!queue.isEmpty()) {
ClassRef ref = queue.remove(0);
ClassInfo cls = ref.getClassInfo();
int innerClassIdx;
int outerClassIdx = 0;
int innerNameIdx = 0;
int flags = 0;
String enclosingClass = null;
if (cls != null) {
InnerClassesInfo info = cls.getInnerClassesInfo();
// only nested classes have an entry
if (!info.isNestedClass()) {
continue;
}
enclosingClass = info.getEnclosingClassName();
innerClassIdx = cpg.addClass(ref.getClassName());
if (!info.isLocalInnerClass()) {
// class is a member, add outer class reference
outerClassIdx = cpg.addClass(enclosingClass);
}
if (!info.isAnonymousInnerClass()) {
// class has a simple name
innerNameIdx = cpg.addUtf8(info.getInnerName());
}
flags = cls.getAccessFlags();
} else {
// unknown class, need to check the existing InnerClass array, if it exists
InnerClass i = findInnerClass(ic, ref.getClassName());
if (i == null) {
// class is not an innerclass according to our old InnerClasses table
continue;
}
innerClassIdx = i.getInnerClassIndex();
outerClassIdx = i.getOuterClassIndex();
innerNameIdx = i.getInnerNameIndex();
flags = i.getInnerAccessFlags();
}
// will add a reference to the enclosing class anyway
if (enclosingClass != null && !visited.contains(enclosingClass)) {
queue.add(classInfo.getAppInfo().getClassRef(enclosingClass));
}
visited.add(ref.getClassName());
inner.add(new InnerClass(innerClassIdx, outerClassIdx, innerNameIdx, flags));
}
return inner;
}
Aggregations