public int compare(AnnotationItem annotationItem, AnnotationItem annotationItem2) { int annotationItemIndex = annotationItem.getEncodedAnnotation().annotationType.getIndex(); int annotationItemIndex2 = annotationItem2.getEncodedAnnotation().annotationType.getIndex(); if (annotationItemIndex < annotationItemIndex2) { return -1; } else if (annotationItemIndex == annotationItemIndex2) { return 0; } return 1; } });
/** * Returns an <code>AnnotationItem</code> for the given values, and that has been interned into the given * <code>DexFile</code> * @param dexFile The <code>DexFile</code> that this item belongs to * @param visibility The visibility of this annotation * @param annotationValue The value of this annotation * @return an <code>AnnotationItem</code> for the given values, and that has been interned into the given * <code>DexFile</code> */ public static AnnotationItem internAnnotationItem(DexFile dexFile, AnnotationVisibility visibility, AnnotationEncodedSubValue annotationValue) { AnnotationItem annotationItem = new AnnotationItem(dexFile, visibility, annotationValue); return dexFile.AnnotationsSection.intern(annotationItem); }
@Override public int hashCode() { //there's a small possibility that the actual hash code will be 0. If so, we'll //just end up recalculating it each time if (hashCode == 0) calcHashCode(); return hashCode; }
/** {@inheritDoc} */ protected void writeItem(AnnotatedOutput out) { Arrays.sort(annotations, new Comparator<AnnotationItem>() { public int compare(AnnotationItem annotationItem, AnnotationItem annotationItem2) { int annotationItemIndex = annotationItem.getEncodedAnnotation().annotationType.getIndex(); int annotationItemIndex2 = annotationItem2.getEncodedAnnotation().annotationType.getIndex(); if (annotationItemIndex < annotationItemIndex2) { return -1; } else if (annotationItemIndex == annotationItemIndex2) { return 0; } return 1; } }); if (out.annotates()) { out.annotate(4, "size: 0x" + Integer.toHexString(annotations.length) + " (" + annotations.length + ")"); for (AnnotationItem annotationItem: annotations) { out.annotate(4, "annotation_off: 0x" + Integer.toHexString(annotationItem.getOffset()) + " - " + annotationItem.getEncodedAnnotation().annotationType.getTypeDescriptor()); } } out.writeInt(annotations.length); for (AnnotationItem annotationItem: annotations) { out.writeInt(annotationItem.getOffset()); } }
/** * calculate and cache the hashcode */ private void calcHashCode() { hashCode = 0; for (AnnotationItem annotationItem: annotations) { hashCode = hashCode * 31 + annotationItem.hashCode(); } }
/** {@inheritDoc} */ public String getConciseIdentity() { return "annotation_item @0x" + Integer.toHexString(getOffset()); }
/** {@inheritDoc} */ public int compareTo(AnnotationSetItem o) { if (o == null) { return 1; } int comp = annotations.length - o.annotations.length; if (comp == 0) { for (int i=0; i<annotations.length; i++) { comp = annotations[i].compareTo(o.annotations[i]); if (comp != 0) { return comp; } } } return comp; }
/** {@inheritDoc} */ protected void writeItem(AnnotatedOutput out) { Arrays.sort(annotations, new Comparator<AnnotationItem>() { public int compare(AnnotationItem annotationItem, AnnotationItem annotationItem2) { int annotationItemIndex = annotationItem.getEncodedAnnotation().annotationType.getIndex(); int annotationItemIndex2 = annotationItem2.getEncodedAnnotation().annotationType.getIndex(); if (annotationItemIndex < annotationItemIndex2) { return -1; } else if (annotationItemIndex == annotationItemIndex2) { return 0; } return 1; } }); if (out.annotates()) { out.annotate(4, "size: 0x" + Integer.toHexString(annotations.length) + " (" + annotations.length + ")"); for (AnnotationItem annotationItem: annotations) { out.annotate(4, "annotation_off: 0x" + Integer.toHexString(annotationItem.getOffset()) + " - " + annotationItem.getEncodedAnnotation().annotationType.getTypeDescriptor()); } } out.writeInt(annotations.length); for (AnnotationItem annotationItem: annotations) { out.writeInt(annotationItem.getOffset()); } }
/** * calculate and cache the hashcode */ private void calcHashCode() { hashCode = 0; for (AnnotationItem annotationItem: annotations) { hashCode = hashCode * 31 + annotationItem.hashCode(); } }
/** {@inheritDoc} */ public String getConciseIdentity() { return "annotation_item @0x" + Integer.toHexString(getOffset()); }
/** {@inheritDoc} */ public int compareTo(AnnotationSetItem o) { if (o == null) { return 1; } int comp = annotations.length - o.annotations.length; if (comp == 0) { for (int i=0; i<annotations.length; i++) { comp = annotations[i].compareTo(o.annotations[i]); if (comp != 0) { return comp; } } } return comp; }
public int compare(AnnotationItem annotationItem, AnnotationItem annotationItem2) { int annotationItemIndex = annotationItem.getEncodedAnnotation().annotationType.getIndex(); int annotationItemIndex2 = annotationItem2.getEncodedAnnotation().annotationType.getIndex(); if (annotationItemIndex < annotationItemIndex2) { return -1; } else if (annotationItemIndex == annotationItemIndex2) { return 0; } return 1; } });
return new DebugInfoItem(dexFile); case TYPE_ANNOTATION_ITEM: return new AnnotationItem(dexFile); case TYPE_ENCODED_ARRAY_ITEM: return new EncodedArrayItem(dexFile);
@Override public int hashCode() { //there's a small possibility that the actual hash code will be 0. If so, we'll //just end up recalculating it each time if (hashCode == 0) calcHashCode(); return hashCode; }
private String stringType(AnnotationItem annotation) { return annotation.getEncodedAnnotation().annotationType.getTypeDescriptor(); } }
/** * Returns an <code>AnnotationItem</code> for the given values, and that has been interned into the given * <code>DexFile</code> * @param dexFile The <code>DexFile</code> that this item belongs to * @param visibility The visibility of this annotation * @param annotationValue The value of this annotation * @return an <code>AnnotationItem</code> for the given values, and that has been interned into the given * <code>DexFile</code> */ public static AnnotationItem internAnnotationItem(DexFile dexFile, AnnotationVisibility visibility, AnnotationEncodedSubValue annotationValue) { AnnotationItem annotationItem = new AnnotationItem(dexFile, visibility, annotationValue); return dexFile.AnnotationsSection.intern(annotationItem); }
private List<String> getPermissionsToRevoke(AnnotationItem[] annotations) { return stream(annotations) .filter(annotationItem -> REVOKE_PERMISSION_ANNOTATION.equals(stringType(annotationItem))) .map(annotationItem -> annotationItem.getEncodedAnnotation().values) .flatMap(encodedValues -> stream(encodedValues) .flatMap(encodedValue -> stream(((ArrayEncodedValue) encodedValue).values) .map(stringEncoded -> ((StringEncodedValue) stringEncoded).value.getStringValue()))) .collect(toList()); }
return new DebugInfoItem(dexFile); case TYPE_ANNOTATION_ITEM: return new AnnotationItem(dexFile); case TYPE_ENCODED_ARRAY_ITEM: return new EncodedArrayItem(dexFile);