Debian Codegraph @

src/com/google/javascript/jscomp/jsonml/JsonMLError.java

raw symbols SCIP
1 /*
2 * Copyright 2009 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
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 * Class used to represent errors which correspond to JsonML elements.
25 *
26 * @author [email protected] (Daniel Hans)
27 */
28 public class JsonMLError {
29
30 /** Description of the error */
31 public final String description;
32
33 /** Name of the source */
34 public final String sourceName;
35
36 /** Node where the warning occurred. */
37 public final JsonML element;
38
39 /** Line number of the source */
40 public final int lineNumber;
41
42 /** Level */
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 // try to find the corresponding JsonML element
71 // it is stored as line number of the JSError
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 }