/** {@inheritDoc} */ @Override public void addContents(DexFile file) { for (OffsettedItem i : items) { i.addContents(file); } }
/** * {@inheritDoc} * * Comparisons for this class are defined to be type-major (if the * types don't match then the objects are not equal), with * {@link #compareTo0} deciding same-type comparisons. */ @Override public final boolean equals(Object other) { if (this == other) { return true; } OffsettedItem otherItem = (OffsettedItem) other; ItemType thisType = itemType(); ItemType otherType = otherItem.itemType(); if (thisType != otherType) { return false; } return (compareTo0(otherItem) == 0); }
/** {@inheritDoc} */ @Override public int getAbsoluteItemOffset(Item item) { OffsettedItem oi = (OffsettedItem) item; return oi.getAbsoluteOffset(); }
/** {@inheritDoc} */ @Override protected void place0(Section addedTo, int offset) { offset += headerSize(); boolean first = true; int theSize = -1; int theAlignment = -1; for (OffsettedItem i : items) { int size = i.writeSize(); if (first) { theSize = size; theAlignment = i.getAlignment(); first = false; } else { if (size != theSize) { throw new UnsupportedOperationException( "item size mismatch"); } if (i.getAlignment() != theAlignment) { throw new UnsupportedOperationException( "item alignment mismatch"); } } offset = i.place(addedTo, offset) + size; } }
/** * Writes an index of contents of the items in this instance of the * given type. If there are none, this writes nothing. If there are any, * then the index is preceded by the given intro string. * * @param out {@code non-null;} where to write to * @param itemType {@code non-null;} the item type of interest * @param intro {@code non-null;} the introductory string for non-empty indices */ public void writeIndexAnnotation(AnnotatedOutput out, ItemType itemType, String intro) { throwIfNotPrepared(); TreeMap<String, OffsettedItem> index = new TreeMap<String, OffsettedItem>(); for (OffsettedItem item : items) { if (item.itemType() == itemType) { String label = item.toHuman(); index.put(label, item); } } if (index.size() == 0) { return; } out.annotate(0, intro); for (Map.Entry<String, OffsettedItem> entry : index.entrySet()) { String label = entry.getKey(); OffsettedItem item = entry.getValue(); out.annotate(0, item.offsetString() + ' ' + label + '\n'); } }
/** * Helper for {@link #UniformListItem}, which returns the alignment * requirement implied by the given list. See the header comment for * more details. * * @param items {@code non-null;} list of items being represented * @return {@code >= 4;} the alignment requirement */ private static int getAlignment(List<? extends OffsettedItem> items) { try { // Since they all must have the same alignment, any one will do. return Math.max(HEADER_SIZE, items.get(0).getAlignment()); } catch (IndexOutOfBoundsException ex) { // Translate the exception. throw new IllegalArgumentException("items.size() == 0"); } catch (NullPointerException ex) { // Translate the exception. throw new NullPointerException("items == null"); } }
int shortyIdx = file.getStringIds().indexOf(shortForm); int returnIdx = file.getTypeIds().indexOf(prototype.getReturnType()); int paramsOff = OffsettedItem.getAbsoluteOffsetOr0(parameterTypes);
/** {@inheritDoc} */ @Override public final String toHuman() { StringBuffer sb = new StringBuffer(100); boolean first = true; sb.append("{"); for (OffsettedItem i : items) { if (first) { first = false; } else { sb.append(", "); } sb.append(i.toHuman()); } sb.append("}"); return sb.toString(); }
/** * Indicates that this item has been added to the given section at * the given offset. It is only valid to call this method once per * instance. * * @param addedTo {@code non-null;} the section this instance has * been added to * @param offset {@code >= 0;} the desired offset from the start of the * section where this instance was placed * @return {@code >= 0;} the offset that this instance should be placed at * in order to meet its alignment constraint */ public final int place(Section addedTo, int offset) { if (addedTo == null) { throw new NullPointerException("addedTo == null"); } if (offset < 0) { throw new IllegalArgumentException("offset < 0"); } if (this.addedTo != null) { throw new RuntimeException("already written"); } int mask = alignment - 1; offset = (offset + mask) & ~mask; this.addedTo = addedTo; this.offset = offset; place0(addedTo, offset); return offset; }
/** {@inheritDoc} */ @Override protected void place0(Section addedTo, int offset) { offset += headerSize(); boolean first = true; int theSize = -1; int theAlignment = -1; for (OffsettedItem i : items) { int size = i.writeSize(); if (first) { theSize = size; theAlignment = i.getAlignment(); first = false; } else { if (size != theSize) { throw new UnsupportedOperationException( "item size mismatch"); } if (i.getAlignment() != theAlignment) { throw new UnsupportedOperationException( "item alignment mismatch"); } } offset = i.place(addedTo, offset) + size; } }
/** * Writes an index of contents of the items in this instance of the * given type. If there are none, this writes nothing. If there are any, * then the index is preceded by the given intro string. * * @param out {@code non-null;} where to write to * @param itemType {@code non-null;} the item type of interest * @param intro {@code non-null;} the introductory string for non-empty indices */ public void writeIndexAnnotation(AnnotatedOutput out, ItemType itemType, String intro) { throwIfNotPrepared(); TreeMap<String, OffsettedItem> index = new TreeMap<String, OffsettedItem>(); for (OffsettedItem item : items) { if (item.itemType() == itemType) { String label = item.toHuman(); index.put(label, item); } } if (index.size() == 0) { return; } out.annotate(0, intro); for (Map.Entry<String, OffsettedItem> entry : index.entrySet()) { String label = entry.getKey(); OffsettedItem item = entry.getValue(); out.annotate(0, item.offsetString() + ' ' + label + '\n'); } }
/** * Helper for {@link #UniformListItem}, which returns the alignment * requirement implied by the given list. See the header comment for * more details. * * @param items {@code non-null;} list of items being represented * @return {@code >= 4;} the alignment requirement */ private static int getAlignment(List<? extends OffsettedItem> items) { try { // Since they all must have the same alignment, any one will do. return Math.max(HEADER_SIZE, items.get(0).getAlignment()); } catch (IndexOutOfBoundsException ex) { // Translate the exception. throw new IllegalArgumentException("items.size() == 0"); } catch (NullPointerException ex) { // Translate the exception. throw new NullPointerException("items == null"); } }
int shortyIdx = file.getStringIds().indexOf(shortForm); int returnIdx = file.getTypeIds().indexOf(prototype.getReturnType()); int paramsOff = OffsettedItem.getAbsoluteOffsetOr0(parameterTypes);
/** {@inheritDoc} */ @Override public final String toHuman() { StringBuffer sb = new StringBuffer(100); boolean first = true; sb.append("{"); for (OffsettedItem i : items) { if (first) { first = false; } else { sb.append(", "); } sb.append(i.toHuman()); } sb.append("}"); return sb.toString(); }
/** * Indicates that this item has been added to the given section at * the given offset. It is only valid to call this method once per * instance. * * @param addedTo {@code non-null;} the section this instance has * been added to * @param offset {@code >= 0;} the desired offset from the start of the * section where this instance was placed * @return {@code >= 0;} the offset that this instance should be placed at * in order to meet its alignment constraint */ public final int place(Section addedTo, int offset) { if (addedTo == null) { throw new NullPointerException("addedTo == null"); } if (offset < 0) { throw new IllegalArgumentException("offset < 0"); } if (this.addedTo != null) { throw new RuntimeException("already written"); } int mask = alignment - 1; offset = (offset + mask) & ~mask; this.addedTo = addedTo; this.offset = offset; place0(addedTo, offset); return offset; }
/** {@inheritDoc} */ @Override protected void place0(Section addedTo, int offset) { offset += headerSize(); boolean first = true; int theSize = -1; int theAlignment = -1; for (OffsettedItem i : items) { int size = i.writeSize(); if (first) { theSize = size; theAlignment = i.getAlignment(); first = false; } else { if (size != theSize) { throw new UnsupportedOperationException( "item size mismatch"); } if (i.getAlignment() != theAlignment) { throw new UnsupportedOperationException( "item alignment mismatch"); } } offset = i.place(addedTo, offset) + size; } }