/** * @ast method * @aspect AnnotationsCodegen * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/AnnotationsCodegen.jrag:110 */ public void addRuntimeVisibleAnnotationsAttribute(Collection c) { Collection annotations = runtimeVisibleAnnotations(); if(!annotations.isEmpty()) { soot.tagkit.VisibilityAnnotationTag tag = new soot.tagkit.VisibilityAnnotationTag(soot.tagkit.AnnotationConstants.RUNTIME_VISIBLE); for(Iterator iter = annotations.iterator(); iter.hasNext(); ) { Annotation annotation = (Annotation)iter.next(); ArrayList elements = new ArrayList(1); annotation.appendAsAttributeTo(elements); tag.addAnnotation((soot.tagkit.AnnotationTag)elements.get(0)); } c.add(tag); } } /**
public String toString() { StringBuffer sb = new StringBuffer("Visibility Param Annotation: num params: " + num_params + " kind: " + kind); if (visibilityAnnotations != null) { for (VisibilityAnnotationTag tag : visibilityAnnotations) { sb.append("\n"); if (tag != null) { sb.append(tag.toString()); } } } sb.append("\n"); return sb.toString(); }
private String getVisibilityAnnotationAttr(VisibilityAnnotationTag tag) { StringBuffer sb = new StringBuffer(); if (tag == null) { return ""; } else if (tag.getVisibility() == AnnotationConstants.RUNTIME_VISIBLE) { sb.append(".runtime_visible_annotation\n"); } else if (tag.getVisibility() == AnnotationConstants.RUNTIME_INVISIBLE) { sb.append(".runtime_invisible_annotation\n"); } else { // source level annotation return ""; } if (tag.hasAnnotations()) { Iterator<AnnotationTag> it = tag.getAnnotations().iterator(); while (it.hasNext()) { AnnotationTag annot = it.next(); sb.append(".annotation "); sb.append(soot.util.StringTools.getQuotedStringOf(annot.getType()) + "\n"); for (AnnotationElem ae : annot.getElems()) { sb.append(getElemAttr(ae)); } sb.append(".end .annotation\n"); } } sb.append(".end .annotation_attr\n"); return sb.toString(); }
/** * Finds a VisibilityAnnotationTag attached to a given Host with the appropriate visibility, or adds one if no such tag is * attached. * * @param h * an Host * @param visibility * a visibility level, taken from soot.tagkit.AnnotationConstants * @return */ private VisibilityAnnotationTag findOrAdd(Host h, int visibility) { ArrayList<VisibilityAnnotationTag> va_tags = new ArrayList<VisibilityAnnotationTag>(); for (Tag t : h.getTags()) { if (t instanceof VisibilityAnnotationTag) { VisibilityAnnotationTag vat = (VisibilityAnnotationTag) t; if (vat.getVisibility() == visibility) { va_tags.add(vat); } } } if (va_tags.isEmpty()) { VisibilityAnnotationTag vat = new VisibilityAnnotationTag(visibility); h.addTag(vat); return vat; } // return the first visibility annotation with the right visibility return (va_tags.get(0)); }
private VisibilityAnnotationTag getSafeVisibilityAnnotationTag(int kind) { VisibilityAnnotationTag safeVat = safeVats.get(kind); if (safeVat == null) { safeVats.put(kind, safeVat = new VisibilityAnnotationTag(kind)); } return safeVat; }
VisibilityAnnotationTag paramVat = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_VISIBLE); tag.addVisibilityAnnotation(paramVat); vat = ((VisibilityAnnotationTag) t).getAnnotations().get(0); paramVat.addAnnotation(vat);
@Override public void visitEnd() { AnnotationTag annotTag = new AnnotationTag(desc, elems); _vat.addAnnotation(annotTag); } };
private List<ImmutableAnnotation> buildVisibilityAnnotationTag(VisibilityAnnotationTag t, Set<String> skipList) { if (t.getAnnotations() == null) { return Collections.emptyList(); for (AnnotationTag at : t.getAnnotations()) { String type = at.getType(); if (!skipList.add(type)) { ImmutableAnnotation ann = new ImmutableAnnotation(getVisibility(t.getVisibility()), typeName, elements); annotations.add(ann);
private void addAnnotationVisibilityAttribute(Host host, attribute_info attribute, ClassFile coffiClass, Collection<Type> references) { VisibilityAnnotationTag tag; if (attribute instanceof RuntimeVisibleAnnotations_attribute) { tag = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_VISIBLE); RuntimeVisibleAnnotations_attribute attr = (RuntimeVisibleAnnotations_attribute) attribute; addAnnotations(attr.number_of_annotations, attr.annotations, coffiClass, tag, references); } else { tag = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_INVISIBLE); RuntimeInvisibleAnnotations_attribute attr = (RuntimeInvisibleAnnotations_attribute) attribute; addAnnotations(attr.number_of_annotations, attr.annotations, coffiClass, tag, references); } host.addTag(tag); }
@Override public void visitEnd() { AnnotationTag annotTag = new AnnotationTag(desc, elems); _tag.addAnnotation(annotTag); } };
List<ImmutableAnnotation> annotations = new ArrayList<ImmutableAnnotation>(); for (VisibilityAnnotationTag vat : t.getVisibilityAnnotations()) { if (paramTagIdx == paramIdx && vat != null && vat.getAnnotations() != null) { for (AnnotationTag at : vat.getAnnotations()) { String type = at.getType(); if (!skipList.add(type)) { ImmutableAnnotation ann = new ImmutableAnnotation(getVisibility(vat.getVisibility()), SootToDexUtils.getDexClassName(at.getType()), elements); annotations.add(ann);
/** * @ast method * @aspect AnnotationsCodegen * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/AnnotationsCodegen.jrag:125 */ public void addRuntimeInvisibleAnnotationsAttribute(Collection c) { Collection annotations = runtimeInvisibleAnnotations(); if(!annotations.isEmpty()) { soot.tagkit.VisibilityAnnotationTag tag = new soot.tagkit.VisibilityAnnotationTag(soot.tagkit.AnnotationConstants.RUNTIME_INVISIBLE); for(Iterator iter = annotations.iterator(); iter.hasNext(); ) { Annotation annotation = (Annotation)iter.next(); ArrayList elements = new ArrayList(1); annotation.appendAsAttributeTo(elements); tag.addAnnotation((soot.tagkit.AnnotationTag)elements.get(0)); } c.add(tag); } } /**
vat = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_VISIBLE); vats[parameter] = vat; vat = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_INVISIBLE); vats[parameter] = vat;
private void addAnnotations(int numAnnots, annotation[] annotations, ClassFile coffiClass, VisibilityAnnotationTag tag, Collection<Type> references) { for (int i = 0; i < numAnnots; i++) { annotation annot = annotations[i]; String annotType = ((CONSTANT_Utf8_info) coffiClass.constant_pool[annot.type_index]).convert(); String ref = annotType.substring(1, annotType.length() - 1); ref = ref.replace('/', '.'); references.add(RefType.v(ref)); AnnotationTag annotTag = new AnnotationTag(annotType, createElementTags(annot.num_element_value_pairs, coffiClass, annot.element_value_pairs)); tag.addAnnotation(annotTag); } }
public String toString() { StringBuffer sb = new StringBuffer("Visibility Param Annotation: num params: "+num_params+" kind: "+kind); if (visibilityAnnotations != null){ Iterator<VisibilityAnnotationTag> it = visibilityAnnotations.iterator(); while (it.hasNext()){ sb.append("\n"); sb.append(it.next().toString()); } } sb.append("\n"); return sb.toString(); }
continue; for (AnnotationTag at : va.getAnnotations()) { AnnotationVisitor av = mv.visitParameterAnnotation(j, at.getType(), (va.getVisibility() == AnnotationConstants.RUNTIME_VISIBLE)); generateAnnotationElems(av, at.getElems(), true);
if (!a.isEmpty()) foundVisibleAnnotations = true; soot.tagkit.VisibilityAnnotationTag tag = new soot.tagkit.VisibilityAnnotationTag( soot.tagkit.AnnotationConstants.RUNTIME_INVISIBLE); for (Iterator iter = a.iterator(); iter.hasNext();) { ArrayList elements = new ArrayList(1); annotation.appendAsAttributeTo(elements); tag.addAnnotation((soot.tagkit.AnnotationTag) elements.get(0));
/** * @see FieldVisitor#visitAnnotation(String, boolean) * @see MethodVisitor#visitAnnotation(String, boolean) * @see ClassVisitor#visitAnnotation(String, boolean) */ public AnnotationVisitor visitAnnotation(final String desc, boolean visible) { VisibilityAnnotationTag tag; if (visible) { tag = visibleTag; if (tag == null) { visibleTag = tag = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_VISIBLE); host.addTag(tag); } } else { tag = invisibleTag; if (tag == null) { invisibleTag = tag = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_INVISIBLE); host.addTag(tag); } } scb.addDep(AsmUtil.toQualifiedName(desc.substring(1, desc.length() - 1))); final VisibilityAnnotationTag _tag = tag; return new AnnotationElemBuilder() { @Override public void visitEnd() { AnnotationTag annotTag = new AnnotationTag(desc, elems); _tag.addAnnotation(annotTag); } }; }
/** * Applies a Java 1.5-style annotation to a given Host. The Host must be of type {@link SootClass}, {@link SootMethod} or * {@link SootField}. * * @param h * a method, field, or class * @param annotationName * the qualified name of the annotation class * @param visibility * any of the constants in {@link AnnotationConstants} * @param elems * a (possibly empty) sequence of AnnotationElem objects corresponding to the elements that should be contained in * this annotation */ public void annotate(Host h, String annotationName, int visibility, List<AnnotationElem> elems) { annotationName = annotationName.replace('.', '/'); if (!annotationName.endsWith(";")) { annotationName = "L" + annotationName + ';'; } VisibilityAnnotationTag tagToAdd = findOrAdd(h, visibility); AnnotationTag at = new AnnotationTag(annotationName, elems); tagToAdd.addAnnotation(at); }
public String toString() { StringBuffer sb = new StringBuffer("Visibility Param Annotation: num params: "+num_params+" kind: "+kind); if (visibilityAnnotations != null){ Iterator<VisibilityAnnotationTag> it = visibilityAnnotations.iterator(); while (it.hasNext()){ sb.append("\n"); sb.append(it.next().toString()); } } sb.append("\n"); return sb.toString(); }