Exemplo n.º 1
0
  /**
   * Performs the main act of translation. This method is separated from {@link #translate} just to
   * keep things a bit simpler in terms of exception handling.
   *
   * @param filePath {@code non-null;} the file path for the class, excluding any base directory
   *     specification
   * @param bytes {@code non-null;} contents of the file
   * @param cfOptions options for class translation
   * @param dexOptions options for dex output
   * @return {@code non-null;} the translated class
   */
  private static ClassDefItem translate0(
      String filePath, byte[] bytes, CfOptions cfOptions, DexOptions dexOptions) {
    DirectClassFile cf = new DirectClassFile(bytes, filePath, cfOptions.strictNameCheck);

    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    cf.getMagic();

    OptimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile, cfOptions.dontOptimizeListFile);

    // Build up a class to output.

    CstType thisClass = cf.getThisClass();
    int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
    CstString sourceFile =
        (cfOptions.positionInfo == PositionList.NONE) ? null : cf.getSourceFile();
    ClassDefItem out =
        new ClassDefItem(
            thisClass, classAccessFlags, cf.getSuperclass(), cf.getInterfaces(), sourceFile);

    Annotations classAnnotations = AttributeTranslator.getClassAnnotations(cf, cfOptions);
    if (classAnnotations.size() != 0) {
      out.setClassAnnotations(classAnnotations);
    }

    processFields(cf, out);
    processMethods(cf, cfOptions, dexOptions, out);

    return out;
  }