/** * Adds a class to this instance. It is illegal to attempt to add more * than one class with the same name. * * @param clazz {@code non-null;} the class to add */ public void add(ClassDefItem clazz) { classDefs.add(clazz); }
/** {@inheritDoc} */ @Override protected void orderItems() { 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); } }
/** {@inheritDoc} */ @Override public IndexedItem get(Constant cst) { 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; }
/** * Writes the portion of the file header that refers to this instance. * * @param out {@code non-null;} where to write */ public void writeHeaderPart(AnnotatedOutput out) { 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); }
/** * Gets the class definition with the given name, if any. * * @param name {@code non-null;} the class name to look for * @return {@code null-ok;} the class with the given name, or {@code null} * if there is no such class */ public ClassDefItem getClassOrNull(String name) { try { Type type = Type.internClassName(name); return (ClassDefItem) classDefs.get(new CstType(type)); } catch (IllegalArgumentException ex) { // Translate exception, per contract. return null; } }
/** * Adds an element to this instance. It is illegal to attempt to add more * than one class with the same name. * * @param clazz {@code non-null;} the class def to add */ public void add(ClassDefItem clazz) { 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); }
/** * Constructs an instance. It is initially empty. */ public DexFile(DexOptions dexOptions) { this.dexOptions = dexOptions; header = new HeaderSection(this); typeLists = new MixedItemSection(null, this, 4, SortType.NONE); wordData = new MixedItemSection("word_data", this, 4, SortType.TYPE); stringData = new MixedItemSection("string_data", this, 1, SortType.INSTANCE); classData = new MixedItemSection(null, this, 1, SortType.NONE); byteData = new MixedItemSection("byte_data", this, 1, SortType.TYPE); stringIds = new StringIdsSection(this); typeIds = new TypeIdsSection(this); protoIds = new ProtoIdsSection(this); fieldIds = new FieldIdsSection(this); methodIds = new MethodIdsSection(this); classDefs = new ClassDefsSection(this); map = new MixedItemSection("map", this, 4, SortType.NONE); /* * This is the list of sections in the order they appear in * the final output. */ sections = new Section[] { header, stringIds, typeIds, protoIds, fieldIds, methodIds, classDefs, wordData, typeLists, stringData, byteData, classData, map }; fileSize = -1; dumpWidth = 79; }
file.getFieldIds().writeHeaderPart(out); file.getMethodIds().writeHeaderPart(out); file.getClassDefs().writeHeaderPart(out);
classDefs.prepare(); classData.prepare(); wordData.prepare();
/** * Returns true if this dex doesn't contain any class defs. */ public boolean isEmpty() { return classDefs.items().isEmpty(); }
/** * Writes the portion of the file header that refers to this instance. * * @param out {@code non-null;} where to write */ public void writeHeaderPart(AnnotatedOutput out) { 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); }
/** * Gets the class definition with the given name, if any. * * @param name {@code non-null;} the class name to look for * @return {@code null-ok;} the class with the given name, or {@code null} * if there is no such class */ public ClassDefItem getClassOrNull(String name) { try { Type type = Type.internClassName(name); return (ClassDefItem) classDefs.get(new CstType(type)); } catch (IllegalArgumentException ex) { // Translate exception, per contract. return null; } }
/** * Adds an element to this instance. It is illegal to attempt to add more * than one class with the same name. * * @param clazz {@code non-null;} the class def to add */ public void add(ClassDefItem clazz) { 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); }
/** * Constructs an instance. It is initially empty. */ public DexFile(DexOptions dexOptions) { this.dexOptions = dexOptions; header = new HeaderSection(this); typeLists = new MixedItemSection(null, this, 4, SortType.NONE); wordData = new MixedItemSection("word_data", this, 4, SortType.TYPE); stringData = new MixedItemSection("string_data", this, 1, SortType.INSTANCE); classData = new MixedItemSection(null, this, 1, SortType.NONE); byteData = new MixedItemSection("byte_data", this, 1, SortType.TYPE); stringIds = new StringIdsSection(this); typeIds = new TypeIdsSection(this); protoIds = new ProtoIdsSection(this); fieldIds = new FieldIdsSection(this); methodIds = new MethodIdsSection(this); classDefs = new ClassDefsSection(this); map = new MixedItemSection("map", this, 4, SortType.NONE); /* * This is the list of sections in the order they appear in * the final output. */ sections = new Section[] { header, stringIds, typeIds, protoIds, fieldIds, methodIds, classDefs, wordData, typeLists, stringData, byteData, classData, map }; fileSize = -1; dumpWidth = 79; }
file.getFieldIds().writeHeaderPart(out); file.getMethodIds().writeHeaderPart(out); file.getClassDefs().writeHeaderPart(out);
classDefs.prepare(); classData.prepare(); wordData.prepare();
/** * Returns true if this dex doesn't contain any class defs. */ public boolean isEmpty() { return classDefs.items().isEmpty(); }
/** * Writes the portion of the file header that refers to this instance. * * @param out {@code non-null;} where to write */ public void writeHeaderPart(AnnotatedOutput out) { 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); }
/** {@inheritDoc} */ @Override protected void orderItems() { 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); } }
/** * Adds a class to this instance. It is illegal to attempt to add more * than one class with the same name. * * @param clazz {@code non-null;} the class to add */ public void add(ClassDefItem clazz) { classDefs.add(clazz); }