/** * 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; }
/** Does the dumping. */ public void dump() { byte[] bytes = getBytes(); ByteArray ba = new ByteArray(bytes); /* * First, parse the file completely, so we can safely refer to * attributes, etc. */ classFile = new DirectClassFile(ba, getFilePath(), getStrictParse()); classFile.setAttributeFactory(StdAttributeFactory.THE_ONE); classFile.getMagic(); // Force parsing to happen. // Next, reparse it and observe the process. DirectClassFile liveCf = new DirectClassFile(ba, getFilePath(), getStrictParse()); liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE); liveCf.setObserver(this); liveCf.getMagic(); // Force parsing to happen. }