Пример #1
0
 /**
  * This is used internally to construct a new <code>EncodedMethod</code> while reading in a
  * <code>DexFile</code>
  *
  * @param dexFile The <code>DexFile</code> that is being read in
  * @param readContext a <code>ReadContext</code> object to hold information that is only needed
  *     while reading in a file
  * @param in the Input object to read the <code>EncodedMethod</code> from
  * @param previousEncodedMethod The previous <code>EncodedMethod</code> in the list containing
  *     this <code>EncodedMethod</code>.
  */
 public EncodedMethod(
     DexFile dexFile, ReadContext readContext, Input in, EncodedMethod previousEncodedMethod) {
   int previousIndex =
       previousEncodedMethod == null ? 0 : previousEncodedMethod.method.getIndex();
   method = dexFile.MethodIdsSection.getItemByIndex(in.readUnsignedLeb128() + previousIndex);
   accessFlags = in.readUnsignedLeb128();
   if (dexFile.skipInstructions()) {
     in.readUnsignedLeb128();
     codeItem = null;
   } else {
     codeItem =
         (CodeItem)
             readContext.getOptionalOffsettedItemByOffset(
                 ItemType.TYPE_CODE_ITEM, in.readUnsignedLeb128());
   }
   if (codeItem != null) {
     codeItem.setParent(this);
   }
 }
  /** {@inheritDoc} */
  protected void readItem(Input in, ReadContext readContext) {
    classAnnotations =
        (AnnotationSetItem)
            readContext.getOptionalOffsettedItemByOffset(
                ItemType.TYPE_ANNOTATION_SET_ITEM, in.readInt());

    int fieldAnnotationCount = in.readInt();
    if (fieldAnnotationCount > 0) {
      fieldAnnotations = new FieldAnnotation[fieldAnnotationCount];
    } else {
      fieldAnnotations = null;
    }

    int methodAnnotationCount = in.readInt();
    if (methodAnnotationCount > 0) {
      methodAnnotations = new MethodAnnotation[methodAnnotationCount];
    } else {
      methodAnnotations = null;
    }

    int parameterAnnotationCount = in.readInt();
    if (parameterAnnotationCount > 0) {
      parameterAnnotations = new ParameterAnnotation[parameterAnnotationCount];
    } else {
      parameterAnnotations = null;
    }

    if (fieldAnnotations != null) {
      for (int i = 0; i < fieldAnnotations.length; i++) {
        try {
          FieldIdItem fieldIdItem = dexFile.FieldIdsSection.getItemByIndex(in.readInt());
          AnnotationSetItem fieldAnnotationSet =
              (AnnotationSetItem)
                  readContext.getOffsettedItemByOffset(
                      ItemType.TYPE_ANNOTATION_SET_ITEM, in.readInt());
          fieldAnnotations[i] = new FieldAnnotation(fieldIdItem, fieldAnnotationSet);
        } catch (Exception ex) {
          throw ExceptionWithContext.withContext(
              ex, "Error occured while reading FieldAnnotation at index " + i);
        }
      }
    }

    if (methodAnnotations != null) {
      for (int i = 0; i < methodAnnotations.length; i++) {
        try {
          MethodIdItem methodIdItem = dexFile.MethodIdsSection.getItemByIndex(in.readInt());
          AnnotationSetItem methodAnnotationSet =
              (AnnotationSetItem)
                  readContext.getOffsettedItemByOffset(
                      ItemType.TYPE_ANNOTATION_SET_ITEM, in.readInt());
          methodAnnotations[i] = new MethodAnnotation(methodIdItem, methodAnnotationSet);
        } catch (Exception ex) {
          throw ExceptionWithContext.withContext(
              ex, "Error occured while reading MethodAnnotation at index " + i);
        }
      }
    }

    if (parameterAnnotations != null) {
      for (int i = 0; i < parameterAnnotations.length; i++) {
        try {
          MethodIdItem methodIdItem = dexFile.MethodIdsSection.getItemByIndex(in.readInt());
          AnnotationSetRefList paramaterAnnotationSet =
              (AnnotationSetRefList)
                  readContext.getOffsettedItemByOffset(
                      ItemType.TYPE_ANNOTATION_SET_REF_LIST, in.readInt());
          parameterAnnotations[i] = new ParameterAnnotation(methodIdItem, paramaterAnnotationSet);
        } catch (Exception ex) {
          throw ExceptionWithContext.withContext(
              ex, "Error occured while reading ParameterAnnotation at index " + i);
        }
      }
    }
  }