/** {@inheritDoc} */ public int compareTo(ClassDefItem o) { //The actual sorting for this class is implemented in SortClassDefItemSection. //This method is just used for sorting the associated ClassDataItem items, so //we can just do the comparison based on the offsets of the items return this.getOffset() - o.getOffset(); }
public int placeAt(int offset) { if (DexFile.this.getInplace()) { return super.placeAt(offset); } int ret = ClassDefItem.placeClassDefItems(this, offset); Collections.sort(this.items, new Comparator<ClassDefItem>() { public int compare(ClassDefItem a, ClassDefItem b) { return a.getOffset() - b.getOffset(); } }); this.offset = items.get(0).getOffset(); return ret; } };
private void placeClass(ClassDefItem classDefItem) { if (classDefItem.getOffset() == -1) { TypeIdItem superType = classDefItem.superType; ClassDefItem superClassDefItem = unplacedClassDefsByType.get(superType); if (superClassDefItem != null) { placeClass(superClassDefItem); } TypeListItem interfaces = classDefItem.implementedInterfaces; if (interfaces != null) { for (TypeIdItem interfaceType: interfaces.getTypes()) { ClassDefItem interfaceClass = unplacedClassDefsByType.get(interfaceType); if (interfaceClass != null) { placeClass(interfaceClass); } } } currentOffset = classDefItem.placeAt(currentOffset, currentIndex++); unplacedClassDefsByType.remove(classDefItem.classType); } } }
public int placeAt(int offset) { if (DexFile.this.getInplace()) { return super.placeAt(offset); } int ret = ClassDefItem.placeClassDefItems(this, offset); Collections.sort(this.items); this.offset = items.get(0).getOffset(); return ret; }
/** {@inheritDoc} */ protected void writeItem(AnnotatedOutput out) { if (out.annotates()) { out.annotate(4, "class_type: " + classType.getTypeDescriptor()); out.annotate(4, "access_flags: " + AccessFlags.formatAccessFlagsForClass(accessFlags)); out.annotate(4, "superclass_type: " + (superType==null?"":superType.getTypeDescriptor())); out.annotate(4, "interfaces: " + (implementedInterfaces==null?"":implementedInterfaces.getTypeListString(" "))); out.annotate(4, "source_file: " + (sourceFile==null?"":sourceFile.getStringValue())); out.annotate(4, "annotations_off: " + (annotations==null?"":"0x"+Integer.toHexString(annotations.getOffset()))); out.annotate(4, "class_data_off:" + (classData==null?"":"0x"+Integer.toHexString(classData.getOffset()))); out.annotate(4, "static_values_off: " + (staticFieldInitializers==null?"":"0x"+Integer.toHexString(staticFieldInitializers.getOffset()))); } out.writeInt(classType.getIndex()); out.writeInt(accessFlags); out.writeInt(superType==null?-1:superType.getIndex()); out.writeInt(implementedInterfaces==null?0:implementedInterfaces.getOffset()); out.writeInt(sourceFile==null?-1:sourceFile.getIndex()); out.writeInt(annotations==null?0:annotations.getOffset()); out.writeInt(classData==null?0:classData.getOffset()); out.writeInt(staticFieldInitializers==null?0:staticFieldInitializers.getOffset()); }