001: /*
002: * FindBugs - Find Bugs in Java programs
003: * Copyright (C) 2005, University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.ba;
021:
022: import edu.umd.cs.findbugs.Detector;
023: import edu.umd.cs.findbugs.annotations.CheckForNull;
024:
025: /**
026: * @author pugh
027: */
028: public class CheckReturnValueAnnotation extends
029: AnnotationEnumeration<CheckReturnValueAnnotation> {
030:
031: final int priority;
032: final String pattern;
033: public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_UNKNOWN = new CheckReturnValueAnnotation(
034: "UnknownCheckReturnValue", 0, Detector.EXP_PRIORITY);
035:
036: public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_HIGH = new CheckReturnValueAnnotation(
037: "CheckReturnValueHigh", 1, Detector.HIGH_PRIORITY);
038:
039: public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_MEDIUM = new CheckReturnValueAnnotation(
040: "CheckReturnValue", 2, Detector.NORMAL_PRIORITY);
041: public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_LOW = new CheckReturnValueAnnotation(
042: "CheckReturnValueLow", 3, Detector.LOW_PRIORITY);
043:
044: public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_IGNORE = new CheckReturnValueAnnotation(
045: "OkToIgnoreReturnValue", 4, Detector.IGNORE_PRIORITY);
046: public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_VERY_HIGH = new CheckReturnValueAnnotation(
047: "CheckReturnValueVeryHigh", 5, Detector.HIGH_PRIORITY - 1);
048: public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_LOW_BAD_PRACTICE = new CheckReturnValueAnnotation(
049: "CheckReturnValueLow", 6,
050: "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE",
051: Detector.LOW_PRIORITY);
052: public final static CheckReturnValueAnnotation CHECK_RETURN_VALUE_MEDIUM_BAD_PRACTICE = new CheckReturnValueAnnotation(
053: "CheckReturnValueLow", 7,
054: "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE",
055: Detector.NORMAL_PRIORITY);
056:
057: private final static CheckReturnValueAnnotation[] myValues = {
058: CHECK_RETURN_VALUE_UNKNOWN, CHECK_RETURN_VALUE_HIGH,
059: CHECK_RETURN_VALUE_MEDIUM, CHECK_RETURN_VALUE_LOW,
060: CHECK_RETURN_VALUE_IGNORE };
061:
062: @CheckForNull
063: public static CheckReturnValueAnnotation parse(String s,
064: String priority) {
065: if (!s.endsWith("CheckReturnValue"))
066: return null;
067: if (priority == null)
068: return CHECK_RETURN_VALUE_MEDIUM;
069: if (priority.endsWith("HIGH"))
070: return CHECK_RETURN_VALUE_HIGH;
071: if (priority.endsWith("MEDIUM"))
072: return CHECK_RETURN_VALUE_MEDIUM;
073: if (priority.endsWith("LOW"))
074: return CHECK_RETURN_VALUE_LOW;
075: throw new IllegalArgumentException("Bad priority: " + priority);
076:
077: }
078:
079: public static CheckReturnValueAnnotation[] values() {
080: return myValues.clone();
081: }
082:
083: public int getPriority() {
084: return priority;
085: }
086:
087: public String getPattern() {
088: return pattern;
089: }
090:
091: private CheckReturnValueAnnotation(String s, int i, int p) {
092: super (s, i);
093: pattern = "RV_RETURN_VALUE_IGNORED";
094: priority = p;
095: }
096:
097: private CheckReturnValueAnnotation(String s, int i, String pattern,
098: int p) {
099: super(s, i);
100: this.pattern = pattern;
101: priority = p;
102: }
103:
104: }
|