| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 25 |
|
| 26 |
|
| 27 |
public class DiagnosticType |
| 28 |
implements Comparable<DiagnosticType>, Serializable { |
| 29 |
private static final long serialVersionUID = 1; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public final String key; |
| 36 |
|
| 37 |
|
| 38 |
public final MessageFormat format; |
| 39 |
|
| 40 |
|
| 41 |
public final CheckLevel defaultLevel; |
| 42 |
|
| 43 |
|
| 44 |
public CheckLevel level; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public static DiagnosticType error(String name, String descriptionFormat) { |
| 54 |
return make(name, CheckLevel.ERROR, descriptionFormat); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public static DiagnosticType warning(String name, String descriptionFormat) { |
| 65 |
return make(name, CheckLevel.WARNING, descriptionFormat); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public static DiagnosticType disabled(String name, |
| 76 |
String descriptionFormat) { |
| 77 |
return make(name, CheckLevel.OFF, descriptionFormat); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 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 |
|
| 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 |
|
| 107 |
|
| 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 |
} |