ClassDefsSectionpublic final class ClassDefsSection extends UniformItemSection Class definitions list section of a {@code .dex} file. |
Fields Summary |
---|
private final TreeMap | classDefs{@code non-null;} map from type constants for classes to {@link
ClassDefItem} instances that define those classes | private ArrayList | orderedDefs{@code null-ok;} ordered list of classes; set in {@link #orderItems} |
Constructors Summary |
---|
public ClassDefsSection(DexFile file)Constructs an instance. The file offset is initially unknown.
super("class_defs", file, 4);
classDefs = new TreeMap<Type, ClassDefItem>();
orderedDefs = null;
|
Methods Summary |
---|
public void | add(ClassDefItem clazz)Adds an element to this instance. It is illegal to attempt to add more
than one class with the same name.
Type type;
try {
type = clazz.getThisClass().getClassType();
} catch (NullPointerException ex) {
// Elucidate the exception.
throw new NullPointerException("clazz == null");
}
throwIfPrepared();
if (classDefs.get(type) != null) {
throw new IllegalArgumentException("already added: " + type);
}
classDefs.put(type, clazz);
| public IndexedItem | get(com.android.dx.rop.cst.Constant cst){@inheritDoc}
if (cst == null) {
throw new NullPointerException("cst == null");
}
throwIfNotPrepared();
Type type = ((CstType) cst).getClassType();
IndexedItem result = classDefs.get(type);
if (result == null) {
throw new IllegalArgumentException("not found");
}
return result;
| public java.util.Collection | items(){@inheritDoc}
if (orderedDefs != null) {
return orderedDefs;
}
return classDefs.values();
| protected void | orderItems(){@inheritDoc}
int sz = classDefs.size();
int idx = 0;
orderedDefs = new ArrayList<ClassDefItem>(sz);
/*
* Iterate over all the classes, recursively assigning an
* index to each, implicitly skipping the ones that have
* already been assigned by the time this (top-level)
* iteration reaches them.
*/
for (Type type : classDefs.keySet()) {
idx = orderItems0(type, idx, sz - idx);
}
| private int | orderItems0(com.android.dx.rop.type.Type type, int idx, int maxDepth)Helper for {@link #orderItems}, which recursively assigns indices
to classes.
ClassDefItem c = classDefs.get(type);
if ((c == null) || (c.hasIndex())) {
return idx;
}
if (maxDepth < 0) {
throw new RuntimeException("class circularity with " + type);
}
maxDepth--;
CstType superclassCst = c.getSuperclass();
if (superclassCst != null) {
Type superclass = superclassCst.getClassType();
idx = orderItems0(superclass, idx, maxDepth);
}
TypeList interfaces = c.getInterfaces();
int sz = interfaces.size();
for (int i = 0; i < sz; i++) {
idx = orderItems0(interfaces.getType(i), idx, maxDepth);
}
c.setIndex(idx);
orderedDefs.add(c);
return idx + 1;
| public void | writeHeaderPart(com.android.dx.util.AnnotatedOutput out)Writes the portion of the file header that refers to this instance.
throwIfNotPrepared();
int sz = classDefs.size();
int offset = (sz == 0) ? 0 : getFileOffset();
if (out.annotates()) {
out.annotate(4, "class_defs_size: " + Hex.u4(sz));
out.annotate(4, "class_defs_off: " + Hex.u4(offset));
}
out.writeInt(sz);
out.writeInt(offset);
|
|