1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.yaml.snakeyaml.error; |
18 | |
|
19 | |
public class MarkedYAMLException extends YAMLException { |
20 | |
|
21 | |
private static final long serialVersionUID = -9119388488683035101L; |
22 | |
private String context; |
23 | |
private Mark contextMark; |
24 | |
private String problem; |
25 | |
private Mark problemMark; |
26 | |
private String note; |
27 | |
|
28 | |
protected MarkedYAMLException(String context, Mark contextMark, String problem, |
29 | |
Mark problemMark, String note) { |
30 | 77 | this(context, contextMark, problem, problemMark, note, null); |
31 | 77 | } |
32 | |
|
33 | |
protected MarkedYAMLException(String context, Mark contextMark, String problem, |
34 | |
Mark problemMark, String note, Throwable cause) { |
35 | 187 | super(context + "; " + problem, cause); |
36 | 187 | this.context = context; |
37 | 187 | this.contextMark = contextMark; |
38 | 187 | this.problem = problem; |
39 | 187 | this.problemMark = problemMark; |
40 | 187 | this.note = note; |
41 | 187 | } |
42 | |
|
43 | |
protected MarkedYAMLException(String context, Mark contextMark, String problem, Mark problemMark) { |
44 | 14 | this(context, contextMark, problem, problemMark, null, null); |
45 | 14 | } |
46 | |
|
47 | |
protected MarkedYAMLException(String context, Mark contextMark, String problem, |
48 | |
Mark problemMark, Throwable cause) { |
49 | 58 | this(context, contextMark, problem, problemMark, null, cause); |
50 | 58 | } |
51 | |
|
52 | |
@Override |
53 | |
public String toString() { |
54 | 14 | StringBuilder lines = new StringBuilder(); |
55 | 14 | if (context != null) { |
56 | 11 | lines.append(context); |
57 | 11 | lines.append("\n"); |
58 | |
} |
59 | 14 | if (contextMark != null |
60 | |
&& (problem == null || problemMark == null |
61 | |
|| (contextMark.getName() != problemMark.getName()) |
62 | |
|| (contextMark.getLine() != problemMark.getLine()) || (contextMark |
63 | |
.getColumn() != problemMark.getColumn()))) { |
64 | 7 | lines.append(contextMark.toString()); |
65 | 7 | lines.append("\n"); |
66 | |
} |
67 | 14 | if (problem != null) { |
68 | 12 | lines.append(problem); |
69 | 12 | lines.append("\n"); |
70 | |
} |
71 | 14 | if (problemMark != null) { |
72 | 12 | lines.append(problemMark.toString()); |
73 | 12 | lines.append("\n"); |
74 | |
} |
75 | 14 | if (note != null) { |
76 | 1 | lines.append(note); |
77 | 1 | lines.append("\n"); |
78 | |
} |
79 | 14 | return lines.toString(); |
80 | |
} |
81 | |
|
82 | |
public String getContext() { |
83 | 1 | return context; |
84 | |
} |
85 | |
|
86 | |
public Mark getContextMark() { |
87 | 1 | return contextMark; |
88 | |
} |
89 | |
|
90 | |
public String getProblem() { |
91 | 1 | return problem; |
92 | |
} |
93 | |
|
94 | |
public Mark getProblemMark() { |
95 | 1 | return problemMark; |
96 | |
} |
97 | |
} |