@Override public int getMethodAccessFlags(@Nonnull PoolMethod method) { return method.getAccessFlags(); }
@Override public int getAccessFlags(@Nonnull PoolClassDef classDef) { return classDef.getAccessFlags(); }
/** * Writes a DexFile out to disk * * @param path The path to write the dex file to * @param dexFile a DexFile to write */ public static void writeDexFile(@Nonnull String path, @Nonnull DexFile dexFile) throws IOException { DexPool.writeTo(path, dexFile); }
public void intern(@Nonnull ClassDef classDef) { PoolClassDef poolClassDef = new PoolClassDef(classDef); PoolClassDef prev = internedItems.put(poolClassDef.getType(), poolClassDef); if (prev != null) { throw new ExceptionWithContext("Class %s has already been interned", poolClassDef.getType()); dexPool.typeSection.intern(poolClassDef.getType()); dexPool.typeSection.internNullable(poolClassDef.getSuperclass()); dexPool.typeListSection.intern(poolClassDef.getInterfaces()); dexPool.stringSection.internNullable(poolClassDef.getSourceFile()); for (Field field: poolClassDef.getFields()) { String fieldDescriptor = ReferenceUtil.getShortFieldDescriptor(field); if (!fields.add(fieldDescriptor)) { throw new ExceptionWithContext("Multiple definitions for field %s->%s", poolClassDef.getType(), fieldDescriptor); dexPool.fieldSection.intern(field); dexPool.internEncodedValue(initialValue); dexPool.annotationSetSection.intern(field.getAnnotations()); ArrayEncodedValue staticInitializers = getStaticInitializers(poolClassDef); if (staticInitializers != null) { dexPool.encodedArraySection.intern(staticInitializers); for (PoolMethod method: poolClassDef.getMethods()) { String methodDescriptor = ReferenceUtil.getMethodDescriptor(method, true);
protected void newDexPool() { curPool = new DexPool(opcodes); dexPools.add(curPool); }
@Override public int getRegisterCount(@Nonnull PoolMethod method) { MethodImplementation impl = method.getImplementation(); if (impl != null) { return impl.getRegisterCount(); } return 0; }
@Nonnull @Override public CharSequence getType(@Nonnull PoolClassDef classDef) { return classDef.getType(); }
@Nonnull @Override public Collection<? extends Field> getSortedStaticFields(@Nonnull PoolClassDef classDef) { return classDef.getStaticFields(); }
@Nonnull @Override public Collection<? extends Field> getSortedInstanceFields(@Nonnull PoolClassDef classDef) { return classDef.getInstanceFields(); }
@Nonnull @Override public Collection<PoolMethod> getSortedDirectMethods(@Nonnull PoolClassDef classDef) { return classDef.getDirectMethods(); }
@Nonnull @Override public Collection<? extends PoolMethod> getSortedMethods(@Nonnull PoolClassDef classDef) { return classDef.getMethods(); }
@Nonnull @Override public Collection<? extends Field> getSortedFields(@Nonnull PoolClassDef classDef) { return classDef.getFields(); }
@Nonnull @Override public Collection<PoolMethod> getSortedVirtualMethods(@Nonnull PoolClassDef classDef) { return classDef.getVirtualMethods(); }
@Nullable @Override public CharSequence getSuperclass(@Nonnull PoolClassDef classDef) { return classDef.getSuperclass(); }
@Nullable @Override public CharSequence getSourceFile(@Nonnull PoolClassDef classDef) { return classDef.getSourceFile(); }
@Nullable @Override public Iterable<CharSequence> getParameterNames(@Nonnull PoolMethod method) { return Iterables.transform(method.getParameters(), new Function<MethodParameter, CharSequence>() { @Nullable @Override public CharSequence apply(MethodParameter input) { return input.getName(); } }); }
@Nullable @Override public Set<? extends Annotation> getMethodAnnotations(@Nonnull PoolMethod method) { Set<? extends Annotation> annotations = method.getAnnotations(); if (annotations.size() == 0) { return null; } return annotations; }
@Nullable @Override public Set<? extends Annotation> getClassAnnotations(@Nonnull PoolClassDef classDef) { Set<? extends Annotation> annotations = classDef.getAnnotations(); if (annotations.size() == 0) { return null; } return annotations; }
@Nonnull @Override public MutableMethodImplementation makeMutableMethodImplementation(@Nonnull PoolMethod poolMethod) { return new MutableMethodImplementation(poolMethod.getImplementation()); }
@Nonnull @Override public List<? extends TryBlock<? extends ExceptionHandler>> getTryBlocks( @Nonnull PoolMethod method) { MethodImplementation impl = method.getImplementation(); if (impl != null) { return impl.getTryBlocks(); } return ImmutableList.of(); }