Debian Codegraph @

src/com/google/javascript/jscomp/DiagnosticType.java

raw symbols SCIP
1 /*
2 * Copyright 2008 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.google.javascript.jscomp;
17
18 import com.google.javascript.jscomp.CheckLevel;
19
20 import java.io.Serializable;
21 import java.text.MessageFormat;
22
23 /**
24 * The type of a compile or analysis error.
25 *
26 */
27 public class DiagnosticType
28 implements Comparable<DiagnosticType>, Serializable {
29 private static final long serialVersionUID = 1;
30
31 /**
32 * The error type. Used as the BugPattern and BugInstance types by
33 * BugBot's XML
34 */
35 public final String key;
36
37 /** The default way to format errors */
38 public final MessageFormat format;
39
40 /** Default level */
41 public final CheckLevel defaultLevel;
42
43 /** Reporting level, initially the defaultLevel but may be changed. */
44 public CheckLevel level;
45
46 /**
47 * Create a DiagnosticType at level CheckLevel.ERROR
48 *
49 * @param name An identifier
50 * @param descriptionFormat A format string
51 * @return A new DiagnosticType
52 */
53 public static DiagnosticType error(String name, String descriptionFormat) {
54 return make(name, CheckLevel.ERROR, descriptionFormat);
55 }
56
57 /**
58 * Create a DiagnosticType at level CheckLevel.WARNING
59 *
60 * @param name An identifier
61 * @param descriptionFormat A format string
62 * @return A new DiagnosticType
63 */
64 public static DiagnosticType warning(String name, String descriptionFormat) {
65 return make(name, CheckLevel.WARNING, descriptionFormat);
66 }
67
68 /**
69 * Create a DiagnosticType at level CheckLevel.OFF
70 *
71 * @param name An identifier
72 * @param descriptionFormat A format string
73 * @return A new DiagnosticType
74 */
75 public static DiagnosticType disabled(String name,
76 String descriptionFormat) {
77 return make(name, CheckLevel.OFF, descriptionFormat);
78 }
79
80 /**
81 * Create a DiagnosticType at a given CheckLevel.
82 *
83 * @param name An identifier
84 * @param level Either CheckLevel.ERROR or CheckLevel.WARNING
85 * @param descriptionFormat A format string
86 * @return A new DiagnosticType
87 */
88 public static DiagnosticType make(String name, CheckLevel level,
89 String descriptionFormat) {
90 return
91 new DiagnosticType(name, level, new MessageFormat(descriptionFormat));
92 }
93
94 /**
95 * Create a DiagnosticType. Private to force use of static factory methods.
96 */
97 private DiagnosticType(String key, CheckLevel level, MessageFormat format) {
98 this.key = key;
99 this.defaultLevel = level;
100 this.format = format;
101
102 this.level = this.defaultLevel;
103 }
104
105 /**
106 * Create a description from the MessageFormat and the arguments.
107 * Used by unit tests.
108 */
109 String format(Object ... arguments) {
110 return format.format(arguments);
111 }
112
113 @Override
114 public boolean equals(Object type) {
115 return type instanceof DiagnosticType &&
116 ((DiagnosticType) type).key.equals(key);
117 }
118
119 @Override
120 public int hashCode() {
121 return key.hashCode();
122 }
123
124 @Override
125 public int compareTo(DiagnosticType diagnosticType) {
126 return key.compareTo(diagnosticType.key);
127 }
128
129 @Override
130 public String toString() {
131 return key + ": " + format.toPattern();
132 }
133 }