| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.javascript.jscomp.jsonml; |
| 18 |
|
| 19 |
import com.google.javascript.jscomp.CheckLevel; |
| 20 |
import com.google.javascript.jscomp.DiagnosticType; |
| 21 |
import com.google.javascript.jscomp.JSError; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class JsonMLError { |
| 29 |
|
| 30 |
|
| 31 |
public final String description; |
| 32 |
|
| 33 |
|
| 34 |
public final String sourceName; |
| 35 |
|
| 36 |
|
| 37 |
public final JsonML element; |
| 38 |
|
| 39 |
|
| 40 |
public final int lineNumber; |
| 41 |
|
| 42 |
|
| 43 |
public final ErrorLevel level; |
| 44 |
|
| 45 |
private JsonMLError(DiagnosticType type, String sourceName, JsonML element, |
| 46 |
int lineNumber, ErrorLevel level, String... arguments) { |
| 47 |
this.description = type.format.format(arguments); |
| 48 |
this.sourceName = sourceName; |
| 49 |
this.element = element; |
| 50 |
this.lineNumber = lineNumber; |
| 51 |
this.level = level; |
| 52 |
} |
| 53 |
|
| 54 |
private JsonMLError(String description, DiagnosticType type, |
| 55 |
String sourceName, JsonML element, int lineNumber, ErrorLevel level) { |
| 56 |
this.description = description; |
| 57 |
this.sourceName = sourceName; |
| 58 |
this.element = element; |
| 59 |
this.lineNumber = lineNumber; |
| 60 |
this.level = level; |
| 61 |
} |
| 62 |
|
| 63 |
public static JsonMLError make(DiagnosticType type, String sourceName, |
| 64 |
JsonML element, int lineNumber, ErrorLevel level, String... arguments) { |
| 65 |
return new JsonMLError(type, sourceName, element, lineNumber, level, |
| 66 |
arguments); |
| 67 |
} |
| 68 |
|
| 69 |
public static JsonMLError make(JSError error, JsonMLAst ast) { |
| 70 |
|
| 71 |
|
| 72 |
int n = error.lineNumber; |
| 73 |
JsonML element = ast.getElementPreOrder(n); |
| 74 |
|
| 75 |
ErrorLevel level = error.getDefaultLevel() == CheckLevel.ERROR |
| 76 |
? ErrorLevel.COMPILATION_ERROR |
| 77 |
: ErrorLevel.COMPILATION_WARNING; |
| 78 |
|
| 79 |
return new JsonMLError(error.getType(), error.sourceName, element, 0, |
| 80 |
level, error.description); |
| 81 |
} |
| 82 |
} |