Annotations annotations = new Annotations(); for (NameValuePair nvp : elements.values()) { annotation.add(nvp); annotations.add(annotation); classDefItem.addMethodAnnotations(cstMethodRef, annotations, dexMaker.getDexFile());
private boolean hasRuntimeVisibleAnnotation(HasAttribute element) { Attribute att = element.getAttributes().findFirst( AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME); return (att != null && ((AttRuntimeVisibleAnnotations)att).getAnnotations().size()>0); } }
/** * Constructs an immutable instance which is the combination of the * given instance with the given additional annotation. The latter's * type must not already appear in the former. * * @param annotations {@code non-null;} the instance to augment * @param annotation {@code non-null;} the additional annotation * @return {@code non-null;} the combination * @throws IllegalArgumentException thrown if there is a duplicate type */ public static Annotations combine(Annotations annotations, Annotation annotation) { Annotations result = new Annotations(); result.addAll(annotations); result.add(annotation); result.setImmutable(); return result; }
/** * Constructs an immutable instance which is the combination of the * two given instances. The two instances must contain disjoint sets * of types. * * @param a1 {@code non-null;} an instance * @param a2 {@code non-null;} the other instance * @return {@code non-null;} the combination * @throws IllegalArgumentException thrown if there is a duplicate type */ public static Annotations combine(Annotations a1, Annotations a2) { Annotations result = new Annotations(); result.addAll(a1); result.addAll(a2); result.setImmutable(); return result; }
/** * Adds all of the elements of the given instance to this one. The * instances must not have any duplicate types. * * @param toAdd {@code non-null;} the annotations to add * @throws IllegalArgumentException thrown if there is a duplicate type */ public void addAll(Annotations toAdd) { throwIfImmutable(); if (toAdd == null) { throw new NullPointerException("toAdd == null"); } for (Annotation a : toAdd.annotations.values()) { add(a); } }
/** * Constructs an instance. * * @param annotations {@code non-null;} set of annotations */ public AnnotationSetItem(Annotations annotations) { super(ALIGNMENT, writeSize(annotations)); this.annotations = annotations; this.items = new AnnotationItem[annotations.size()]; int at = 0; for (Annotation a : annotations.getAnnotations()) { items[at] = new AnnotationItem(a); at++; } }
/** * Parses an annotation list. * * @param visibility {@code non-null;} visibility of the parsed annotations * @return {@code non-null;} the list of annotations read from the attribute * data */ private Annotations parseAnnotations(AnnotationVisibility visibility) throws IOException { int count = input.readUnsignedShort(); if (observer != null) { parsed(2, "num_annotations: " + Hex.u2(count)); } Annotations annotations = new Annotations(); for (int i = 0; i < count; i++) { if (observer != null) { parsed(0, "annotations[" + i + "]:"); changeIndent(1); } Annotation annotation = parseAnnotation(visibility); annotations.add(annotation); if (observer != null) { observer.changeIndent(-1); } } annotations.setImmutable(); return annotations; }
/** * Gets the annotations out of a given {@link AttributeList}. This * combines both visible and invisible annotations into a single * result set and also adds in a system annotation for the * {@code Signature} attribute if present. * * @param attribs {@code non-null;} the attributes list to search in * @return {@code non-null;} the set of annotations, which may be empty */ public static Annotations getAnnotations(AttributeList attribs) { Annotations result = getAnnotations0(attribs); Annotation signature = getSignature(attribs); Annotation sourceDebugExtension = getSourceDebugExtension(attribs); if (signature != null) { result = Annotations.combine(result, signature); } if (sourceDebugExtension != null) { result = Annotations.combine(result, sourceDebugExtension); } return result; }
/** * Inspects a class annotation. * * @param cf {@code non-null;} class file * @param ann {@code non-null;} annotation */ private void visitClassAnnotation(DirectClassFile cf, BaseAnnotations ann) { if (!args.eTypes.contains(ElementType.TYPE)) { return; } for (Annotation anAnn : ann.getAnnotations().getAnnotations()) { String annClassName = anAnn.getType().getClassType().getClassName(); if (args.aclass.equals(annClassName)) { printMatch(cf); } } }
/** {@inheritDoc} */ @Override protected int compareTo0(OffsettedItem other) { AnnotationSetItem otherSet = (AnnotationSetItem) other; return annotations.compareTo(otherSet.annotations); }
/** {@inheritDoc} */ @Override public int hashCode() { return annotations.hashCode(); }
/** * Adds an element to this instance. There must not already be an * element of the same type. * * @param annotation {@code non-null;} the element to add * @throws IllegalArgumentException thrown if there is a duplicate type */ public void add(Annotation annotation) { throwIfImmutable(); if (annotation == null) { throw new NullPointerException("annotation == null"); } CstType type = annotation.getType(); if (annotations.containsKey(type)) { throw new IllegalArgumentException("duplicate type: " + type.toHuman()); } annotations.put(type, annotation); }
/** * Constructs an immutable instance which is the combination of the * given instance with the given additional annotation. The latter's * type must not already appear in the former. * * @param annotations {@code non-null;} the instance to augment * @param annotation {@code non-null;} the additional annotation * @return {@code non-null;} the combination * @throws IllegalArgumentException thrown if there is a duplicate type */ public static Annotations combine(Annotations annotations, Annotation annotation) { Annotations result = new Annotations(); result.addAll(annotations); result.add(annotation); result.setImmutable(); return result; }
/** * Constructs an immutable instance which is the combination of the * two given instances. The two instances must contain disjoint sets * of types. * * @param a1 {@code non-null;} an instance * @param a2 {@code non-null;} the other instance * @return {@code non-null;} the combination * @throws IllegalArgumentException thrown if there is a duplicate type */ public static Annotations combine(Annotations a1, Annotations a2) { Annotations result = new Annotations(); result.addAll(a1); result.addAll(a2); result.setImmutable(); return result; }
/** * Adds all of the elements of the given instance to this one. The * instances must not have any duplicate types. * * @param toAdd {@code non-null;} the annotations to add * @throws IllegalArgumentException thrown if there is a duplicate type */ public void addAll(Annotations toAdd) { throwIfImmutable(); if (toAdd == null) { throw new NullPointerException("toAdd == null"); } for (Annotation a : toAdd.annotations.values()) { add(a); } }
/** * Constructs an instance. * * @param annotations {@code non-null;} set of annotations */ public AnnotationSetItem(Annotations annotations) { super(ALIGNMENT, writeSize(annotations)); this.annotations = annotations; this.items = new AnnotationItem[annotations.size()]; int at = 0; for (Annotation a : annotations.getAnnotations()) { items[at] = new AnnotationItem(a); at++; } }
/** * Parses an annotation list. * * @param visibility {@code non-null;} visibility of the parsed annotations * @return {@code non-null;} the list of annotations read from the attribute * data */ private Annotations parseAnnotations(AnnotationVisibility visibility) throws IOException { int count = input.readUnsignedShort(); if (observer != null) { parsed(2, "num_annotations: " + Hex.u2(count)); } Annotations annotations = new Annotations(); for (int i = 0; i < count; i++) { if (observer != null) { parsed(0, "annotations[" + i + "]:"); changeIndent(1); } Annotation annotation = parseAnnotation(visibility); annotations.add(annotation); if (observer != null) { observer.changeIndent(-1); } } annotations.setImmutable(); return annotations; }
/** * Gets the annotations out of a given {@link AttributeList}. This * combines both visible and invisible annotations into a single * result set and also adds in a system annotation for the * {@code Signature} attribute if present. * * @param attribs {@code non-null;} the attributes list to search in * @return {@code non-null;} the set of annotations, which may be empty */ public static Annotations getAnnotations(AttributeList attribs) { Annotations result = getAnnotations0(attribs); Annotation signature = getSignature(attribs); Annotation sourceDebugExtension = getSourceDebugExtension(attribs); if (signature != null) { result = Annotations.combine(result, signature); } if (sourceDebugExtension != null) { result = Annotations.combine(result, sourceDebugExtension); } return result; }
/** * Inspects a class annotation. * * @param cf {@code non-null;} class file * @param ann {@code non-null;} annotation */ private void visitClassAnnotation(DirectClassFile cf, BaseAnnotations ann) { if (!args.eTypes.contains(ElementType.TYPE)) { return; } for (Annotation anAnn : ann.getAnnotations().getAnnotations()) { String annClassName = anAnn.getType().getClassType().getClassName(); if (args.aclass.equals(annClassName)) { printMatch(cf); } } }
/** {@inheritDoc} */ @Override protected int compareTo0(OffsettedItem other) { AnnotationSetItem otherSet = (AnnotationSetItem) other; return annotations.compareTo(otherSet.annotations); }