KickJava   Java API By Example, From Geeks To Geeks.

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


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.visitclass.AnnotationVisitor;
33
34 public class NoteAnnotationRetention extends AnnotationVisitor implements
35         Detector, NonReportingDetector {
36
37         private boolean classfileRetention;
38
39     BugReporter bugReporter;
40
41     public NoteAnnotationRetention(BugReporter bugReporter) {
42         this.bugReporter = bugReporter;
43     }
44
45     @Override JavaDoc
46     public void visitAnnotation(String JavaDoc annotationClass,
47             Map JavaDoc<String JavaDoc, Object JavaDoc> map, boolean runtimeVisible) {
48
49         if (!annotationClass.equals("java.lang.annotation.Retention"))
50             return;
51         Object JavaDoc value = map.get("value");
52         if ("java.lang.annotation.RetentionPolicy.RUNTIME".equals(value)
53                 || "java.lang.annotation.RetentionPolicy.CLASSFILE"
54                         .equals(value))
55             classfileRetention = true;
56     }
57
58     @Override JavaDoc
59     public void visit(JavaClass obj) {
60         classfileRetention = false;
61     }
62
63     @Override JavaDoc
64     public void visitAfter(JavaClass obj) {
65         for (String JavaDoc i : obj.getInterfaceNames())
66             if (i.equals("java.lang.annotation.Annotation"))
67                 AnalysisContext.currentAnalysisContext()
68                 .getAnnotationRetentionDatabase().setClassfileRetention(getDottedClassName(),
69                         classfileRetention);
70
71     }
72
73     public void visitClassContext(ClassContext classContext) {
74         JavaClass javaClass = classContext.getJavaClass();
75         if (!FindUnreleasedLock.preTiger(javaClass)) javaClass.accept(this);
76         
77     }
78
79
80     public void report() {
81         
82     }
83     
84
85 }
86
Popular Tags