@Test public void testParameterValue() { AnnotationValue value = mock(AnnotationValue.class); when(value.getParameterValue()).thenReturn("valid"); Not expr = new Not(value); assertEquals("~valid", expr.getParameterValue()); }
/** * Parses an annotation element * * @param elementDoc * @return */ protected static AnnotationElement ParseAnnotationElement(AnnotationTypeElementDoc elementDoc) { // AnnotationTypeElementDoc's are basically methods. AnnotationElement element = new AnnotationElement(); element.name = elementDoc.name(); AnnotationValue value = elementDoc.defaultValue(); if (value != null) { element.defaultValue = value.toString(); } element.qualifiedName = elementDoc.qualifiedName(); element.type = elementDoc.returnType().qualifiedTypeName(); return element; }
/** * Destructively add a parameter annotation. * * @param param parameter (0 == first parameter) * @param annotationValue an AnnotationValue representing a parameter annotation */ public void addParameterAnnotation(int param, AnnotationValue annotationValue) { HashMap<Integer, Map<ClassDescriptor, AnnotationValue>> updatedAnnotations = new HashMap<Integer, Map<ClassDescriptor, AnnotationValue>>(methodParameterAnnotations); Map<ClassDescriptor, AnnotationValue> paramMap = updatedAnnotations.get(param); if (paramMap == null) { paramMap = new HashMap<ClassDescriptor, AnnotationValue>(); updatedAnnotations.put(param, paramMap); } paramMap.put(annotationValue.getAnnotationClass(), annotationValue); methodParameterAnnotations = updatedAnnotations; }
private String getValue(AnnotationMirror am) { Map<? extends ExecutableElement, ? extends AnnotationValue> map = am.getElementValues(); if (map.size() != 1) throw new IllegalArgumentException(); AnnotationValue v = map.values().iterator().next(); return (String) v.getValue(); }
/** * Destructively add an annotation. We do this for "built-in" annotations that might not be * directly evident in the code. It's not a great idea in general, but we can get away with it as * long as it's done early enough (i.e., before anyone asks what annotations this method has.) * * @param annotationValue an AnnotationValue representing a method annotation */ public void addAnnotation(AnnotationValue annotationValue) { HashMap<ClassDescriptor, AnnotationValue> updatedAnnotations = new HashMap<ClassDescriptor, AnnotationValue>(methodAnnotations); updatedAnnotations.put(annotationValue.getAnnotationClass(), annotationValue); methodAnnotations = updatedAnnotations; }