|
27 | 27 | * to Spotless, then it is by definition.
|
28 | 28 | */
|
29 | 29 | public final class Lint implements Serializable {
|
30 |
| - /** Returns a runtime exception which, if thrown, will lint the entire file. */ |
31 |
| - public static ShortcutException entireFile(String code, String msg) { |
32 |
| - return new ShortcutException(Lint.create(code, msg, -1)); |
| 30 | + /** Returns a runtime exception which, if thrown, will create a lint at an undefined line. */ |
| 31 | + public static ShortcutException atUndefinedLine(String code, String msg) { |
| 32 | + return new ShortcutException(Lint.create(code, msg, LINE_UNDEFINED)); |
33 | 33 | }
|
34 | 34 |
|
35 | 35 | /** Returns a runtime exception which, if thrown, will lint a specific line. */
|
36 | 36 | public static ShortcutException atLine(int line, String code, String msg) {
|
37 | 37 | return new ShortcutException(Lint.create(code, msg, line));
|
38 | 38 | }
|
39 | 39 |
|
| 40 | + /** Returns a runtime exception which, if thrown, will lint a specific line range. */ |
| 41 | + public static ShortcutException atLineRange(int lineStart, int lineEnd, String code, String msg) { |
| 42 | + return new ShortcutException(Lint.create(code, msg, lineStart, lineEnd)); |
| 43 | + } |
| 44 | + |
40 | 45 | /** Any exception which implements this interface will have its lints extracted and reported cleanly to the user. */
|
41 | 46 | public interface Has {
|
42 | 47 | List<Lint> getLints();
|
@@ -103,7 +108,11 @@ public String getMsg() {
|
103 | 108 | @Override
|
104 | 109 | public String toString() {
|
105 | 110 | if (lineStart == lineEnd) {
|
106 |
| - return lineStart + ": (" + code + ") " + msg; |
| 111 | + if (lineStart == LINE_UNDEFINED) { |
| 112 | + return "LINE_UNDEFINED: (" + code + ") " + msg; |
| 113 | + } else { |
| 114 | + return lineStart + ": (" + code + ") " + msg; |
| 115 | + } |
107 | 116 | } else {
|
108 | 117 | return lineStart + "-" + lineEnd + ": (" + code + ") " + msg;
|
109 | 118 | }
|
@@ -163,4 +172,6 @@ private static String msgFrom(String message) {
|
163 | 172 | }
|
164 | 173 | return "";
|
165 | 174 | }
|
| 175 | + |
| 176 | + public static final int LINE_UNDEFINED = -1; |
166 | 177 | }
|
0 commit comments