Search in sources :

Example 11 with AnnotationElement

use of org.jf.dexlib2.iface.AnnotationElement in project smali by JesusFreke.

the class DexPool method internEncodedValue.

void internEncodedValue(@Nonnull EncodedValue encodedValue) {
    switch(encodedValue.getValueType()) {
        case ValueType.ANNOTATION:
            AnnotationEncodedValue annotationEncodedValue = (AnnotationEncodedValue) encodedValue;
            typeSection.intern(annotationEncodedValue.getType());
            for (AnnotationElement element : annotationEncodedValue.getElements()) {
                stringSection.intern(element.getName());
                internEncodedValue(element.getValue());
            }
            break;
        case ValueType.ARRAY:
            for (EncodedValue element : ((ArrayEncodedValue) encodedValue).getValue()) {
                internEncodedValue(element);
            }
            break;
        case ValueType.STRING:
            stringSection.intern(((StringEncodedValue) encodedValue).getValue());
            break;
        case ValueType.TYPE:
            typeSection.intern(((TypeEncodedValue) encodedValue).getValue());
            break;
        case ValueType.ENUM:
            fieldSection.intern(((EnumEncodedValue) encodedValue).getValue());
            break;
        case ValueType.FIELD:
            fieldSection.intern(((FieldEncodedValue) encodedValue).getValue());
            break;
        case ValueType.METHOD:
            methodSection.intern(((MethodEncodedValue) encodedValue).getValue());
            break;
    }
}
Also used : AnnotationElement(org.jf.dexlib2.iface.AnnotationElement)

Example 12 with AnnotationElement

use of org.jf.dexlib2.iface.AnnotationElement in project smali by JesusFreke.

the class DexWriterTest method testAnnotationElementOrder.

@Test
public void testAnnotationElementOrder() {
    // Elements are out of order wrt to the element name
    ImmutableSet<ImmutableAnnotationElement> elements = ImmutableSet.of(new ImmutableAnnotationElement("zabaglione", ImmutableNullEncodedValue.INSTANCE), new ImmutableAnnotationElement("blah", ImmutableNullEncodedValue.INSTANCE));
    ImmutableAnnotation annotation = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lorg/test/anno;", elements);
    ImmutableClassDef classDef = new ImmutableClassDef("Lorg/test/blah;", 0, "Ljava/lang/Object;", null, null, ImmutableSet.of(annotation), null, null);
    MemoryDataStore dataStore = new MemoryDataStore();
    try {
        DexPool.writeTo(dataStore, new ImmutableDexFile(Opcodes.getDefault(), ImmutableSet.of(classDef)));
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getData());
    ClassDef dbClassDef = Iterables.getFirst(dexFile.getClasses(), null);
    Assert.assertNotNull(dbClassDef);
    Annotation dbAnnotation = Iterables.getFirst(dbClassDef.getAnnotations(), null);
    Assert.assertNotNull(dbAnnotation);
    List<AnnotationElement> dbElements = Lists.newArrayList(dbAnnotation.getElements());
    // Ensure that the elements were written out in sorted order
    Assert.assertEquals(2, dbElements.size());
    Assert.assertEquals("blah", dbElements.get(0).getName());
    Assert.assertEquals("zabaglione", dbElements.get(1).getName());
}
Also used : DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) ImmutableClassDef(org.jf.dexlib2.immutable.ImmutableClassDef) MemoryDataStore(org.jf.dexlib2.writer.io.MemoryDataStore) IOException(java.io.IOException) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) Annotation(org.jf.dexlib2.iface.Annotation) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) ImmutableClassDef(org.jf.dexlib2.immutable.ImmutableClassDef) ClassDef(org.jf.dexlib2.iface.ClassDef) ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) AnnotationElement(org.jf.dexlib2.iface.AnnotationElement) ImmutableDexFile(org.jf.dexlib2.immutable.ImmutableDexFile) Test(org.junit.Test)

Aggregations

AnnotationElement (org.jf.dexlib2.iface.AnnotationElement)10 Annotation (org.jf.dexlib2.iface.Annotation)5 EncodedValue (org.jf.dexlib2.iface.value.EncodedValue)4 ImmutableAnnotation (org.jf.dexlib2.immutable.ImmutableAnnotation)4 ImmutableAnnotationElement (org.jf.dexlib2.immutable.ImmutableAnnotationElement)4 ArrayEncodedValue (org.jf.dexlib2.iface.value.ArrayEncodedValue)3 StringEncodedValue (org.jf.dexlib2.iface.value.StringEncodedValue)3 TypeEncodedValue (org.jf.dexlib2.iface.value.TypeEncodedValue)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 BaseAnnotationElement (org.jf.dexlib2.base.BaseAnnotationElement)2 DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)2 ClassDef (org.jf.dexlib2.iface.ClassDef)2 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)2 MethodEncodedValue (org.jf.dexlib2.iface.value.MethodEncodedValue)2 ImmutableClassDef (org.jf.dexlib2.immutable.ImmutableClassDef)2 ImmutableDexFile (org.jf.dexlib2.immutable.ImmutableDexFile)2 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)2 ImmutableArrayEncodedValue (org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue)2