KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > CheckReturnValueAnnotation


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2005, 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.ba;
21
22 import edu.umd.cs.findbugs.Detector;
23 import edu.umd.cs.findbugs.annotations.CheckForNull;
24
25 /**
26  * @author pugh
27  */

28 public class CheckReturnValueAnnotation extends AnnotationEnumeration<CheckReturnValueAnnotation> {
29
30      final int priority;
31     public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_UNKNOWN = new CheckReturnValueAnnotation(
32             "UnknownCheckReturnValue", 0, Detector.EXP_PRIORITY);
33
34     public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_HIGH = new CheckReturnValueAnnotation(
35             "CheckReturnValueHigh", 1, Detector.HIGH_PRIORITY);
36
37     public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_MEDIUM = new CheckReturnValueAnnotation(
38             "CheckReturnValue", 2, Detector.NORMAL_PRIORITY);
39     public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_LOW = new CheckReturnValueAnnotation(
40             "CheckReturnValueLow", 3, Detector.LOW_PRIORITY);
41     public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_IGNORE = new CheckReturnValueAnnotation(
42             "OkToIgnoreReturnValue", 4, Detector.IGNORE_PRIORITY);
43     public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_VERY_HIGH = new CheckReturnValueAnnotation(
44             "CheckReturnValueVeryHigh", 5, Detector.HIGH_PRIORITY-1);
45
46
47
48     private final static CheckReturnValueAnnotation[] myValues = { CHECK_RETURN_VALUE_UNKNOWN,
49         CHECK_RETURN_VALUE_HIGH,CHECK_RETURN_VALUE_MEDIUM, CHECK_RETURN_VALUE_LOW, CHECK_RETURN_VALUE_IGNORE };
50     
51
52     @CheckForNull public static CheckReturnValueAnnotation parse(String JavaDoc s, String JavaDoc priority) {
53         if (!s.endsWith("CheckReturnValue")) return null;
54         if (priority == null) return CHECK_RETURN_VALUE_MEDIUM;
55         if (priority.endsWith("HIGH"))
56             return CHECK_RETURN_VALUE_HIGH;
57         if (priority.endsWith("MEDIUM"))
58             return CHECK_RETURN_VALUE_MEDIUM;
59         if (priority.endsWith("LOW"))
60             return CHECK_RETURN_VALUE_LOW;
61         throw new IllegalArgumentException JavaDoc("Bad priority: " + priority);
62         
63     }
64     public static CheckReturnValueAnnotation[] values() {
65         return myValues.clone();
66     }
67
68     public int getPriority() {
69         return priority;
70     }
71     private CheckReturnValueAnnotation(String JavaDoc s, int i, int p) {
72         super(s,i);
73         priority = p;
74         
75     }
76
77     
78
79 }
80
Popular Tags