/** Returns the annotation associated with the specified * property, or null if not available. * * @param annotName the annotation name * @param propName the property name, e.g., "value". * If null, this method returns the annotation(s) associated with the * component (rather than a particular property). */ public Annotation getAnnotation(String propName, String annotName) { if (_annots != null) { final Map<String, List<Annotation>> anmap = _annots.get(propName); if (anmap != null) { List<Annotation> ans = anmap.get(annotName); if (ans != null) { if (ans.size() == 1) return ans.get(0); //merge annotations into a single annotation final AnnotImpl ai = new AnnotImpl(annotName, null); for (Annotation an : ans) { if (ai._loc == null) ai._loc = an.getLocation(); ai.addAttributes(an); } return ai; } } } return null; }
/** Adds a map of attributes, (String name, String value), to the annotation. */ private void addAttributes(Map<String, String[]> attrs) { if (attrs != null) for (Map.Entry<String, String[]> me : attrs.entrySet()) addAttribute(me.getKey(), me.getValue()); }
/** Adds an annotation. * * @param propName the property name. * If null, this method returns the annotation(s) associated with the * component (rather than a particular property). * @since 6.0.0 */ public void addAnnotation(String propName, String annotName, Map<String, String[]> annotAttrs, Location loc) { initAnnots(); Map<String, List<Annotation>> anmap = _annots.get(propName); if (anmap == null) _annots.put(propName, anmap = new LinkedHashMap<String, List<Annotation>>(4)); List<Annotation> ans = anmap.get(annotName); if (ans == null) anmap.put(annotName, ans = new LinkedList<Annotation>()); ans.add(new AnnotImpl(annotName, annotAttrs, loc)); }
/** Adds the attributes of the given annotation to this annotation. */ private void addAttributes(Annotation an) { if (an != null) addAttributes(((AnnotImpl) an)._attrs); }
private AnnotImpl(String name, Map<String, String[]> attrs, Location loc) { _name = name; _loc = loc; addAttributes(attrs); }