AnnotationDirectoryItem annotationDirectoryItem = new AnnotationDirectoryItem(dexFile, classAnnotations, fieldAnnotationFields, fieldAnnotationsArray, methodAnnotationMethods, methodAnnotationsArray, parameterAnnotationMethods, parameterAnnotationsArray);
/** * Iterates over the field annotations, calling delegate.processFieldAnnotations for each * @param delegate the delegate to call */ public void iterateFieldAnnotations(FieldAnnotationIteratorDelegate delegate) { for (int i=0; i<fieldAnnotationFields.length; i++) { try { delegate.processFieldAnnotations(fieldAnnotationFields[i], fieldAnnotations[i]); } catch (Exception ex) { throw addExceptionContext(ExceptionWithContext.withContext(ex, "Error occured while processing field annotations for field: " + fieldAnnotationFields[i].getFieldString())); } } }
/** {@inheritDoc} */ public int compareTo(AnnotationDirectoryItem o) { if (!isInternable()) { if (!o.isInternable()) { return parent.compareTo(o.parent); } return -1; } if (!o.isInternable()) { return 1; } return classAnnotations.compareTo(o.classAnnotations); }
annotations.setParent(this);
@Override public boolean equals(Object o) { if (this==o) { return true; } if (o==null || !this.getClass().equals(o.getClass())) { return false; } AnnotationDirectoryItem other = (AnnotationDirectoryItem)o; return (this.compareTo(other) == 0); }
@Nonnull private List<TestCaseEvent> convertClassToTestCaseEvents(ClassDefItem classDefItem) { AnnotationDirectoryItem annotationDirectoryItem = classDefItem.getAnnotations(); if (annotationDirectoryItem == null) { return emptyList(); } List<TestCaseEvent> testCaseEvents = new ArrayList<>(); for (AnnotationDirectoryItem.MethodAnnotation method : annotationDirectoryItem.getMethodAnnotations()) { stream(method.annotationSet.getAnnotations()) .filter(annotation -> TEST_ANNOTATION.equals(stringType(annotation))) .map(annotation -> convertToTestCaseEvent(classDefItem, annotationDirectoryItem, method)) .forEach(testCaseEvents::add); } return testCaseEvents; }
private boolean isClassIgnored(AnnotationDirectoryItem annotationDirectoryItem) { AnnotationSetItem classAnnotations = annotationDirectoryItem.getClassAnnotations(); if (classAnnotations == null) { return false; } return containsAnnotation(IGNORE_ANNOTATION, classAnnotations.getAnnotations()); }
@Override public int hashCode() { //an instance is only internable if it has only class annotations, but //no other type of annotation if (!isInternable()) { return super.hashCode(); } return classAnnotations.hashCode(); }
/** {@inheritDoc} */ protected void readItem(Input in, ReadContext readContext) { classType = dexFile.TypeIdsSection.getItemByIndex(in.readInt()); accessFlags = in.readInt(); superType = dexFile.TypeIdsSection.getOptionalItemByIndex(in.readInt()); implementedInterfaces = (TypeListItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_TYPE_LIST, in.readInt()); sourceFile = dexFile.StringIdsSection.getOptionalItemByIndex(in.readInt()); annotations = (AnnotationDirectoryItem)readContext.getOptionalOffsettedItemByOffset( ItemType.TYPE_ANNOTATIONS_DIRECTORY_ITEM, in.readInt()); classData = (ClassDataItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_CLASS_DATA_ITEM, in.readInt()); staticFieldInitializers = (EncodedArrayItem)readContext.getOptionalOffsettedItemByOffset( ItemType.TYPE_ENCODED_ARRAY_ITEM, in.readInt()); if (classData != null) { classData.setParent(this); } if (annotations != null) { annotations.setParent(this); } }
/** {@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()); }
return new EncodedArrayItem(dexFile); case TYPE_ANNOTATIONS_DIRECTORY_ITEM: return new AnnotationDirectoryItem(dexFile); default: assert false;
if (!isInternable() && parent != null) { out.annotate(0, parent.getClassType().getTypeDescriptor());
/** * Iterates over the method annotations, calling delegate.processMethodAnnotations for each * @param delegate the delegate to call */ public void iterateMethodAnnotations(MethodAnnotationIteratorDelegate delegate) { for (int i=0; i<methodAnnotationMethods.length; i++) { try { delegate.processMethodAnnotations(methodAnnotationMethods[i], methodAnnotations[i]); } catch (Exception ex) { throw addExceptionContext(ExceptionWithContext.withContext(ex, "Error occured while processing method annotations for method: " + methodAnnotationMethods[i].getMethodString())); } } }
/** * Returns an <code>AnnotationDirectoryItem</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 classAnnotations The annotations associated with the class * @param fieldAnnotations A list of <code>FieldAnnotation</code> objects containing the field annotations * @param methodAnnotations A list of <code>MethodAnnotation</code> objects containing the method annotations * @param parameterAnnotations A list of <code>ParameterAnnotation</code> objects containin the parameter * annotations * @return an <code>AnnotationItem</code> for the given values, and that has been interned into the given * <code>DexFile</code> */ public static AnnotationDirectoryItem internAnnotationDirectoryItem(DexFile dexFile, AnnotationSetItem classAnnotations, List<FieldAnnotation> fieldAnnotations, List<MethodAnnotation> methodAnnotations, List<ParameterAnnotation> parameterAnnotations) { AnnotationDirectoryItem annotationDirectoryItem = new AnnotationDirectoryItem(dexFile, classAnnotations, fieldAnnotations, methodAnnotations, parameterAnnotations); return dexFile.AnnotationDirectoriesSection.intern(annotationDirectoryItem); }
/** * Iterates over the parameter annotations, calling delegate.processParameterAnnotations for each * @param delegate the delegate to call */ public void iterateParameterAnnotations(ParameterAnnotationIteratorDelegate delegate) { for (int i=0; i<parameterAnnotationMethods.length; i++) { try { delegate.processParameterAnnotations(parameterAnnotationMethods[i], parameterAnnotations[i]); } catch (Exception ex) { throw addExceptionContext(ExceptionWithContext.withContext(ex, "Error occured while processing parameter annotations for method: " + parameterAnnotationMethods[i].getMethodString())); } } }
for (ParameterAnnotation parameterAnnotation: parameterAnnotations) { out.writeInt(parameterAnnotation.method.getIndex()); out.writeInt(parameterAnnotation.annotationSet.getOffset());
return new EncodedArrayItem(dexFile); case TYPE_ANNOTATIONS_DIRECTORY_ITEM: return new AnnotationDirectoryItem(dexFile); default: assert false;