Example #1
0
  public ClassDataItem internClassDataItem(DexFile dexFile) {
    EncodedField[] staticFieldsArray = null;
    EncodedField[] instanceFieldsArray = null;
    EncodedMethod[] directMethodsArray = null;
    EncodedMethod[] virtualMethodsArray = null;
    if (staticFields != null && staticFields.length != 0) {
      staticFieldsArray = new EncodedField[staticFields.length];
      for (int i = 0, len = staticFields.length; i < len; i++) {
        EncodedField field = staticFields[i];
        staticFieldsArray[i] =
            new EncodedField(field.field.internFieldIdItem(dexFile), field.accessFlags);
      }
    }
    if (instanceFields != null && instanceFields.length != 0) {
      instanceFieldsArray = new EncodedField[instanceFields.length];
      for (int i = 0, len = instanceFields.length; i < len; i++) {
        EncodedField field = instanceFields[i];
        instanceFieldsArray[i] =
            new EncodedField(field.field.internFieldIdItem(dexFile), field.accessFlags);
      }
    }
    if (directMethods != null && directMethods.length != 0) {
      directMethodsArray = new EncodedMethod[directMethods.length];
      for (int i = 0, len = directMethods.length; i < len; i++) {
        EncodedMethod method = directMethods[i];
        directMethodsArray[i] =
            new EncodedMethod(
                method.method.internMethodIdItem(dexFile),
                method.accessFlags,
                method.codeItem != null ? method.codeItem.internCodeItem(dexFile) : null);
      }
    }

    if (virtualMethods != null && virtualMethods.length != 0) {
      virtualMethodsArray = new EncodedMethod[virtualMethods.length];
      for (int i = 0, len = virtualMethods.length; i < len; i++) {
        EncodedMethod method = virtualMethods[i];
        virtualMethodsArray[i] =
            new EncodedMethod(
                method.method.internMethodIdItem(dexFile),
                method.accessFlags,
                method.codeItem != null ? method.codeItem.internCodeItem(dexFile) : null);
      }
    }

    ClassDataItem classDataItem =
        new ClassDataItem(
            dexFile,
            staticFieldsArray,
            instanceFieldsArray,
            directMethodsArray,
            virtualMethodsArray);
    return dexFile.ClassDataSection.intern(classDataItem);
  }
Example #2
0
  /**
   * Creates a new <code>ClassDataItem</code> with the given values
   *
   * @param dexFile The <code>DexFile</code> that this item belongs to
   * @param staticFields The static fields for this class
   * @param instanceFields The instance fields for this class
   * @param directMethods The direct methods for this class
   * @param virtualMethods The virtual methods for this class
   * @return a new <code>ClassDataItem</code> with the given values
   */
  public static ClassDataItem internClassDataItem(
      DexFile dexFile,
      List<EncodedField> staticFields,
      List<EncodedField> instanceFields,
      List<EncodedMethod> directMethods,
      List<EncodedMethod> virtualMethods) {
    EncodedField[] staticFieldsArray = null;
    EncodedField[] instanceFieldsArray = null;
    EncodedMethod[] directMethodsArray = null;
    EncodedMethod[] virtualMethodsArray = null;

    if (staticFields != null && staticFields.size() > 0) {
      Collections.sort(staticFields);
      staticFieldsArray = new EncodedField[staticFields.size()];
      staticFields.toArray(staticFieldsArray);
    }

    if (instanceFields != null && instanceFields.size() > 0) {
      Collections.sort(instanceFields);
      instanceFieldsArray = new EncodedField[instanceFields.size()];
      instanceFields.toArray(instanceFieldsArray);
    }

    if (directMethods != null && directMethods.size() > 0) {
      Collections.sort(directMethods);
      directMethodsArray = new EncodedMethod[directMethods.size()];
      directMethods.toArray(directMethodsArray);
    }

    if (virtualMethods != null && virtualMethods.size() > 0) {
      Collections.sort(virtualMethods);
      virtualMethodsArray = new EncodedMethod[virtualMethods.size()];
      virtualMethods.toArray(virtualMethodsArray);
    }

    ClassDataItem classDataItem =
        new ClassDataItem(
            dexFile,
            staticFieldsArray,
            instanceFieldsArray,
            directMethodsArray,
            virtualMethodsArray);
    return dexFile.ClassDataSection.intern(classDataItem);
  }