private ArrayList<AnnotationElem> getElements(Set<? extends AnnotationElement> set) { ArrayList<AnnotationElem> aelemList = new ArrayList<AnnotationElem>(); for (AnnotationElement ae : set) { // Debug.printDbg("element: ", ae.getName() ," ", ae.getValue() ," // type: ", ae.getClass()); // Debug.printDbg("value type: ", ae.getValue().getValueType() ," // class: ", ae.getValue().getClass()); List<AnnotationElem> eList = handleAnnotationElement(ae, Collections.singletonList(ae.getValue())); if (eList != null) { aelemList.addAll(eList); } } return aelemList; }
private String buildASMSignature(ClassDef classDef) { String signature = null; outer: for (Annotation annotation : classDef.getAnnotations()) { if (!annotation.getType().equals("Ldalvik/annotation/Signature;")) { continue; } StringBuilder sb = new StringBuilder(); for (AnnotationElement e : annotation.getElements()) { BuilderEncodedValues.BuilderArrayEncodedValue ev = (BuilderEncodedValues.BuilderArrayEncodedValue) e .getValue(); for (EncodedValue v : ev.getValue()) { BuilderEncodedValues.BuilderStringEncodedValue value = (BuilderEncodedValues.BuilderStringEncodedValue) v; sb.append(value.getValue()); } } signature = sb.toString(); break; } return signature; }
private void visitClassAnnotations(Set<? extends Annotation> annotations, ClassWriter classWriter) { for (Annotation annotation : annotations) { switch (annotation.getType()) { case "Ldalvik/annotation/EnclosingMethod;": for (AnnotationElement e : annotation.getElements()) { BuilderEncodedValues.BuilderMethodEncodedValue v = (BuilderEncodedValues.BuilderMethodEncodedValue) e .getValue(); visitEnclosingMethod(v, classWriter); // There should only ever be one enclosing method. break; } break; case "Ldalvik/annotation/MemberClasses;": for (AnnotationElement e : annotation.getElements()) { BuilderEncodedValues.BuilderArrayEncodedValue ev = (BuilderEncodedValues.BuilderArrayEncodedValue) e .getValue(); for (EncodedValue v : ev.getValue()) { BuilderEncodedValues.BuilderTypeEncodedValue value = (BuilderEncodedValues.BuilderTypeEncodedValue) v; visitInnerClasses(value, classWriter); } } break; } } }
protected List<SootClass> getThrownExceptions(final Method method) { // the following snippet retrieves all exceptions that this method // throws by analyzing its annotations List<SootClass> thrownExceptions = new ArrayList<SootClass>(); for (Annotation a : method.getAnnotations()) { Type atype = DexType.toSoot(a.getType()); String atypes = atype.toString(); if (!(atypes.equals("dalvik.annotation.Throws"))) { continue; } for (AnnotationElement ae : a.getElements()) { EncodedValue ev = ae.getValue(); if (ev instanceof ArrayEncodedValue) { for (EncodedValue evSub : ((ArrayEncodedValue) ev).getValue()) { if (evSub instanceof TypeEncodedValue) { TypeEncodedValue valueType = (TypeEncodedValue) evSub; String exceptionName = valueType.getValue(); String dottedName = Util.dottedClassName(exceptionName); thrownExceptions.add(SootResolver.v().makeClassRef(dottedName)); } } } } } return thrownExceptions; } }
String outerClass = ((TypeEncodedValue) elem.getValue()).getValue(); outerClass = Util.dottedClassName(outerClass);
for (AnnotationElement newElem : v.getElements()) { List<EncodedValue> l = new ArrayList<EncodedValue>(); l.add(newElem.getValue()); List<AnnotationElem> aList = handleAnnotationElement(newElem, l); if (aList != null) {
@Nonnull @Override public EncodedValue getElementValue(@Nonnull AnnotationElement annotationElement) { return annotationElement.getValue(); } }
@Nonnull @Override public EncodedValue getElementValue(@Nonnull AnnotationElement annotationElement) { return annotationElement.getValue(); } }
private static void writeAnnotation(Writer writer, AnnotationEncodedValue annotation) throws IOException { writer.write("Annotation["); writer.write(annotation.getType()); Set<? extends AnnotationElement> elements = annotation.getElements(); for (AnnotationElement element: elements) { writer.write(", "); writer.write(element.getName()); writer.write('='); writeEncodedValue(writer, element.getValue()); } writer.write(']'); }
private static void writeAnnotation(Writer writer, AnnotationEncodedValue annotation) throws IOException { writer.write("Annotation["); writer.write(annotation.getType()); Set<? extends AnnotationElement> elements = annotation.getElements(); for (AnnotationElement element: elements) { writer.write(", "); writer.write(element.getName()); writer.write('='); writeEncodedValue(writer, element.getValue()); } writer.write(']'); }
public static ImmutableAnnotationElement of(AnnotationElement annotationElement) { if (annotationElement instanceof ImmutableAnnotationElement) { return (ImmutableAnnotationElement)annotationElement; } return new ImmutableAnnotationElement( annotationElement.getName(), annotationElement.getValue()); }
@Override public boolean equals(Object o) { if (o != null && o instanceof AnnotationElement) { AnnotationElement other = (AnnotationElement)o; return getName().equals(other.getName()) && getValue().equals(other.getValue()); } return false; }
@Override public boolean equals(Object o) { if (o != null && o instanceof AnnotationElement) { AnnotationElement other = (AnnotationElement)o; return getName().equals(other.getName()) && getValue().equals(other.getValue()); } return false; }
public static ImmutableAnnotationElement of(AnnotationElement annotationElement) { if (annotationElement instanceof ImmutableAnnotationElement) { return (ImmutableAnnotationElement)annotationElement; } return new ImmutableAnnotationElement( annotationElement.getName(), annotationElement.getValue()); }
@Override public int compareTo(AnnotationElement o) { int res = getName().compareTo(o.getName()); if (res != 0) return res; return getValue().compareTo(o.getValue()); }
@Override public int compareTo(AnnotationElement o) { int res = getName().compareTo(o.getName()); if (res != 0) return res; return getValue().compareTo(o.getValue()); }
public static void writeElementsTo(@Nonnull IndentingWriter writer, @Nonnull Collection<? extends AnnotationElement> annotationElements, @Nullable String containingClass) throws IOException { writer.indent(4); for (AnnotationElement annotationElement: annotationElements) { writer.write(annotationElement.getName()); writer.write(" = "); EncodedValueAdaptor.writeTo(writer, annotationElement.getValue(), containingClass); writer.write('\n'); } writer.deindent(4); } }
public void intern(@Nonnull Annotation annotation) { Integer prev = internedItems.put(annotation, 0); if (prev == null) { typePool.intern(annotation.getType()); for (AnnotationElement element: annotation.getElements()) { stringPool.intern(element.getName()); DexPool.internEncodedValue(element.getValue(), stringPool, typePool, fieldPool, methodPool); } } }
public void intern(@Nonnull Annotation annotation) { Integer prev = internedItems.put(annotation, 0); if (prev == null) { dexPool.typeSection.intern(annotation.getType()); for (AnnotationElement element: annotation.getElements()) { dexPool.stringSection.intern(element.getName()); dexPool.internEncodedValue(element.getValue()); } } }
static Annotation getAnnotation(org.jf.dexlib2.iface.Annotation ea, ClassLoaderReference clr) { Map<String,ElementValue> values = HashMapFactory.make(); TypeReference at = getTypeRef(ea.getType(), clr); for(AnnotationElement elt : ea.getElements()) { String name = elt.getName(); EncodedValue v = elt.getValue(); ElementValue value = getValue(clr, v); values.put(name, value); } return Annotation.makeWithNamed(at, values); }