1 /**
2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 */
4 package net.sourceforge.pmd;
5
6 /**
7 * These are the possible Rule priority values.
8 *
9 * For backward compatibility, priorities range in value from 1 to 5, with 5
10 * being the lowest priority. This means the ordinal value of the Enum should be
11 * avoided in favor of {@link RulePriority#getPriority()} and
12 * {@link RulePriority#valueOf(int)}
13 *
14 * @see <a href="http://pmd.sourceforge.net/pmd-5.1.2/rule-guidelines.html">How to define rules priority</a>
15 */
16 public enum RulePriority {
17
18 /** High: Change absolutely required. Behavior is critically broken/buggy */
19 HIGH(1, "High"),
20 /** Medium to high: Change highly recommended. Behavior is quite likely to be broken/buggy. */
21 MEDIUM_HIGH(2, "Medium High"),
22 /** Medium: Change recommended. Behavior is confusing, perhaps buggy, and/or against standards/best practices. */
23 MEDIUM(3, "Medium"),
24 /** Medium to low: Change optional. Behavior is not likely to be buggy, but more just flies in the face of standards/style/good taste. */
25 MEDIUM_LOW(4, "Medium Low"),
26 /** Low: Change highly optional. Nice to have, such as a consistent naming policy for package/class/fields... */
27 LOW(5, "Low");
28
29 private final int priority;
30 private final String name;
31
32 private RulePriority(int priority, String name) {
33 this.priority = priority;
34 this.name = name;
35 }
36
37 /**
38 * Get the priority value as a number. This is the value to be used in the
39 * externalized form of a priority (e.g. in RuleSet XML).
40 *
41 * @return The <code>int</code> value of the priority.
42 */
43 public int getPriority() {
44 return priority;
45 }
46
47 /**
48 * Get the descriptive name of this priority.
49 *
50 * @return The descriptive name.
51 */
52 public String getName() {
53 return name;
54 }
55
56 /**
57 * Returns the descriptive name of the priority.
58 * @return descriptive name of the priority
59 * @see #getName()
60 */
61 @Override
62 public String toString() {
63 return name;
64 }
65
66 /**
67 * Get the priority which corresponds to the given number as returned by
68 * {@link RulePriority#getPriority()}. If the number is an invalid value,
69 * then {@link RulePriority#LOW} will be returned.
70 *
71 * @param priority The numeric priority value.
72 * @return The priority.
73 */
74 public static RulePriority valueOf(int priority) {
75 try {
76 return RulePriority.values()[priority - 1];
77 } catch (ArrayIndexOutOfBoundsException e) {
78 return LOW;
79 }
80 }
81 }