KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > detect > NoteJCIPAnnotation


1 /*
2  * FindBugs - Find bugs in Java programs
3  * Copyright (C) 2004-2006 University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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.detect;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.apache.bcel.classfile.JavaClass;
26
27 import edu.umd.cs.findbugs.BugReporter;
28 import edu.umd.cs.findbugs.Detector;
29 import edu.umd.cs.findbugs.NonReportingDetector;
30 import edu.umd.cs.findbugs.ba.AnalysisContext;
31 import edu.umd.cs.findbugs.ba.ClassContext;
32 import edu.umd.cs.findbugs.ba.ClassMember;
33 import edu.umd.cs.findbugs.ba.XFactory;
34 import edu.umd.cs.findbugs.ba.XField;
35 import edu.umd.cs.findbugs.ba.XMethod;
36 import edu.umd.cs.findbugs.visitclass.AnnotationVisitor;
37
38 public class NoteJCIPAnnotation extends AnnotationVisitor implements
39         Detector, NonReportingDetector {
40
41     private static final String JavaDoc NET_JCIP_ANNOTATIONS = "net.jcip.annotations.";
42     BugReporter bugReporter;
43
44     public NoteJCIPAnnotation(BugReporter bugReporter) {
45         this.bugReporter = bugReporter;
46     }
47
48     
49     @Override JavaDoc
50     public void visitAnnotation(String JavaDoc annotationClass,
51             Map JavaDoc<String JavaDoc, Object JavaDoc> map, boolean runtimeVisible) {
52
53         if (!annotationClass.startsWith(NET_JCIP_ANNOTATIONS))
54             return;
55         annotationClass = annotationClass.substring(NET_JCIP_ANNOTATIONS
56                 .length());
57         Object JavaDoc value = map.get("value");
58         ClassMember member;
59         if (visitingField())
60             member = XFactory.createXField(this);
61         else if (visitingMethod())
62             member = XFactory.createXMethod(this);
63         else {
64             Map JavaDoc<String JavaDoc, Object JavaDoc> annotationsOfThisClass = AnalysisContext.currentAnalysisContext()
65             .getJCIPAnnotationDatabase().getEntryForClass(getDottedClassName());
66             annotationsOfThisClass.put(annotationClass, value);
67             return;
68         }
69         Map JavaDoc<String JavaDoc, Object JavaDoc> annotationsOfThisMember = AnalysisContext.currentAnalysisContext()
70         .getJCIPAnnotationDatabase().getEntryForClassMember(member);
71         annotationsOfThisMember.put(annotationClass, value);
72     }
73
74     public void visitClassContext(ClassContext classContext) {
75         JavaClass javaClass = classContext.getJavaClass();
76         if (!FindUnreleasedLock.preTiger(javaClass)) javaClass.accept(this);
77
78     }
79
80     public void report() {
81
82     }
83
84 }
85
Popular Tags