/** * Changes the annotations. A call to this method is equivalent to: * <pre>setAnnotations(new Annotation[] { annotation })</pre> * * @param annotation the data structure representing * the new annotation. */ public void setAnnotation(Annotation annotation) { setAnnotations(new Annotation[] { annotation }); }
/** * Changes the annotations. A call to this method is equivalent to: * <pre>setAnnotations(new Annotation[] { annotation })</pre> * * @param annotation the data structure representing * the new annotation. */ public void setAnnotation(Annotation annotation) { setAnnotations(new Annotation[] { annotation }); }
/** * Adds an annotation. If there is an annotation with the same type, * it is removed before the new annotation is added. * * @param annotation the added annotation. */ public void addAnnotation(Annotation annotation) { String type = annotation.getTypeName(); Annotation[] annotations = getAnnotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].getTypeName().equals(type)) { annotations[i] = annotation; setAnnotations(annotations); return; } } Annotation[] newlist = new Annotation[annotations.length + 1]; System.arraycopy(annotations, 0, newlist, 0, annotations.length); newlist[annotations.length] = annotation; setAnnotations(newlist); }
/** * Removes an annotation by type. * After removing an annotation, if {@link #numAnnotations()} returns 0, * this annotations attribute has to be removed. * * @param type of annotation to remove * @return whether an annotation with the given type has been removed * @since 3.21 */ public boolean removeAnnotation(String type) { Annotation[] annotations = getAnnotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].getTypeName().equals(type)) { Annotation[] newlist = new Annotation[annotations.length - 1]; System.arraycopy(annotations, 0, newlist, 0, i); if (i < annotations.length - 1) { System.arraycopy(annotations, i + 1, newlist, i, annotations.length - i - 1); } setAnnotations(newlist); return true; } } return false; }
/** * Adds an annotation. If there is an annotation with the same type, * it is removed before the new annotation is added. * * @param annotation the added annotation. */ public void addAnnotation(Annotation annotation) { String type = annotation.getTypeName(); Annotation[] annotations = getAnnotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].getTypeName().equals(type)) { annotations[i] = annotation; setAnnotations(annotations); return; } } Annotation[] newlist = new Annotation[annotations.length + 1]; System.arraycopy(annotations, 0, newlist, 0, annotations.length); newlist[annotations.length] = annotation; setAnnotations(newlist); }
/** * Removes an annotation by type. * After removing an annotation, if {@link #numAnnotations()} returns 0, * this annotations attribute has to be removed. * * @param type of annotation to remove * @return whether an annotation with the given type has been removed * @since 3.21 */ public boolean removeAnnotation(String type) { Annotation[] annotations = getAnnotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].getTypeName().equals(type)) { Annotation[] newlist = new Annotation[annotations.length - 1]; System.arraycopy(annotations, 0, newlist, 0, i); if (i < annotations.length - 1) { System.arraycopy(annotations, i + 1, newlist, i, annotations.length - i - 1); } setAnnotations(newlist); return true; } } return false; }
attr.setAnnotations(newItems.toArray(new Annotation[newItems.size()]));
attr.setAnnotations(items); break;
((AnnotationsAttribute) attribute).setAnnotations(annotations); } else { ((AnnotationsAttribute) attribute).setAnnotations(new Annotation[] {});
/** * Changes the annotations. A call to this method is equivalent to: * <ul><pre>setAnnotations(new Annotation[] { annotation })</pre></ul> * * @param annotation the data structure representing * the new annotation. */ public void setAnnotation(Annotation annotation) { setAnnotations(new Annotation[] { annotation }); }
/** * Changes the annotations. A call to this method is equivalent to: * <ul><pre>setAnnotations(new Annotation[] { annotation })</pre></ul> * * @param annotation the data structure representing * the new annotation. */ public void setAnnotation(Annotation annotation) { setAnnotations(new Annotation[] { annotation }); }
/** * Changes the annotations. A call to this method is equivalent to: * <ul><pre>setAnnotations(new Annotation[] { annotation })</pre></ul> * * @param annotation the data structure representing * the new annotation. */ public void setAnnotation(Annotation annotation) { setAnnotations(new Annotation[] { annotation }); }
/** * Changes the annotations. A call to this method is equivalent to: * <ul><pre>setAnnotations(new Annotation[] { annotation })</pre></ul> * * @param annotation the data structure representing * the new annotation. */ public void setAnnotation(Annotation annotation) { setAnnotations(new Annotation[] { annotation }); }
/** * Changes the annotations. A call to this method is equivalent to: * <ul><pre>setAnnotations(new Annotation[] { annotation })</pre></ul> * * @param annotation the data structure representing * the new annotation. */ public void setAnnotation(Annotation annotation) { setAnnotations(new Annotation[] { annotation }); }
/** * Adds an annotation. If there is an annotation with the same type, * it is removed before the new annotation is added. * * @param annotation the added annotation. */ public void addAnnotation(Annotation annotation) { String type = annotation.getTypeName(); Annotation[] annotations = getAnnotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].getTypeName().equals(type)) { annotations[i] = annotation; setAnnotations(annotations); return; } } Annotation[] newlist = new Annotation[annotations.length + 1]; System.arraycopy(annotations, 0, newlist, 0, annotations.length); newlist[annotations.length] = annotation; setAnnotations(newlist); }
/** * Adds an annotation. If there is an annotation with the same type, * it is removed before the new annotation is added. * * @param annotation the added annotation. */ public void addAnnotation(Annotation annotation) { String type = annotation.getTypeName(); Annotation[] annotations = getAnnotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].getTypeName().equals(type)) { annotations[i] = annotation; setAnnotations(annotations); return; } } Annotation[] newlist = new Annotation[annotations.length + 1]; System.arraycopy(annotations, 0, newlist, 0, annotations.length); newlist[annotations.length] = annotation; setAnnotations(newlist); }
/** * Adds an annotation. If there is an annotation with the same type, * it is removed before the new annotation is added. * * @param annotation the added annotation. */ public void addAnnotation(Annotation annotation) { String type = annotation.getTypeName(); Annotation[] annotations = getAnnotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].getTypeName().equals(type)) { annotations[i] = annotation; setAnnotations(annotations); return; } } Annotation[] newlist = new Annotation[annotations.length + 1]; System.arraycopy(annotations, 0, newlist, 0, annotations.length); newlist[annotations.length] = annotation; setAnnotations(newlist); }
public static AnnotationsAttribute copyAnnotations(AnnotationsAttribute annotations, ConstPool constPool) throws NotFoundException { if (annotations != null) { Annotation[] origAnnotations = annotations.getAnnotations(); Annotation[] newClassAnnotations = new Annotation[origAnnotations.length]; for (int i = 0; i < newClassAnnotations.length; ++i) { newClassAnnotations[i] = cloneAnnotation(origAnnotations[i], constPool); } AnnotationsAttribute newAnnotations = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag); newAnnotations.setAnnotations(newClassAnnotations); return newAnnotations; } return null; }
private static AnnotationsAttribute copyAnnotations(AnnotationsAttribute annotations, ConstPool constPool) throws NotFoundException { if (annotations != null) { Annotation[] origAnnotations = annotations.getAnnotations(); Annotation[] newClassAnnotations = new Annotation[origAnnotations.length]; for (int i = 0; i < newClassAnnotations.length; ++i) { newClassAnnotations[i] = cloneAnnotation(origAnnotations[i], constPool); } AnnotationsAttribute newAnnotations = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag); newAnnotations.setAnnotations(newClassAnnotations); return newAnnotations; } return null; }
private void removeTestMethodAnnotationFrom(CtMethod m) { final AnnotationsAttribute attr = (AnnotationsAttribute) m.getMethodInfo().getAttribute(AnnotationsAttribute.visibleTag); javassist.bytecode.annotation.Annotation[] newAnnotations = new javassist.bytecode.annotation.Annotation[attr.numAnnotations() - 1]; int i = -1; for (javassist.bytecode.annotation.Annotation a : attr.getAnnotations()) { if (a.getTypeName().equals(getTestMethodAnnotationType().getName())) { continue; } newAnnotations[++i] = a; } attr.setAnnotations(newAnnotations); }