01: /*
02: * FindBugs - Find Bugs in Java programs
03: * Copyright (C) 2005, University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19:
20: package edu.umd.cs.findbugs.ba;
21:
22: import java.util.HashMap;
23: import java.util.Map;
24:
25: public class JCIPAnnotationDatabase {
26: Map<ClassMember, Map<String, Object>> memberAnnotations = new HashMap<ClassMember, Map<String, Object>>();
27:
28: Map<String, Map<String, Object>> classAnnotations = new HashMap<String, Map<String, Object>>();
29:
30: public Object getClassAnnotation(String dottedClassName,
31: String annotationClass) {
32: assert dottedClassName.indexOf('/') == -1;
33: return getEntryForClass(dottedClassName).get(annotationClass);
34: }
35:
36: public boolean hasClassAnnotation(String dottedClassName,
37: String annotationClass) {
38: assert dottedClassName.indexOf('/') == -1;
39: return getEntryForClass(dottedClassName).containsKey(
40: annotationClass);
41: }
42:
43: public Object getFieldAnnotation(XField field,
44: String annotationClass) {
45: return getEntryForClassMember(field).get(annotationClass);
46: }
47:
48: public boolean hasFieldAnnotation(XField field,
49: String annotationClass) {
50: return getEntryForClassMember(field).containsKey(
51: annotationClass);
52: }
53:
54: public Object getMethodAnnotation(XMethod method,
55: String annotationClass) {
56: return getEntryForClassMember(method).get(annotationClass);
57: }
58:
59: public boolean hasMethodAnnotation(XMethod method,
60: String annotationClass) {
61: return getEntryForClassMember(method).containsKey(
62: annotationClass);
63: }
64:
65: public Map<String, Object> getEntryForClassMember(ClassMember member) {
66: Map<String, Object> map = memberAnnotations.get(member);
67: if (map == null) {
68: map = new HashMap<String, Object>();
69: memberAnnotations.put(member, map);
70: }
71: return map;
72: }
73:
74: public Map<String, Object> getEntryForClass(String dottedClassName) {
75: assert dottedClassName.indexOf('/') == -1;
76: Map<String, Object> map = classAnnotations.get(dottedClassName);
77: if (map == null) {
78: map = new HashMap<String, Object>();
79: classAnnotations.put(dottedClassName, map);
80: }
81: return map;
82: }
83:
84: }
|