/
IDiagnosticReporter.java
108 lines (91 loc) · 2.58 KB
/
IDiagnosticReporter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Copyright (c) 2013, 2018 CEA and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Christian W. Damus (CEA) - initial API and implementation
* Christian W. Damus (CEA) - 286404
* Kenn Hussey - 535301
*
*/
package org.eclipse.uml2.ant.app;
import java.io.PrintStream;
import org.eclipse.emf.common.util.Diagnostic;
/**
* An interface for objects that can consume ("report") {@link Diagnostic}s
* produced by the UML-to-Ecore conversion of a profile.
*
* @see PrintStreamReporter
*/
public interface IDiagnosticReporter {
void report(Diagnostic diagnostic);
/**
* Partial implementation of a diagnostic reporter.
*/
abstract class AbstractReporter
implements IDiagnosticReporter {
public AbstractReporter() {
super();
}
public void report(Diagnostic diagnostic) {
report(0, diagnostic);
}
protected void report(int depth, Diagnostic diagnostic) {
doReport(depth, diagnostic.getSeverity(), diagnostic.getMessage(),
diagnostic.getException());
if (!diagnostic.getChildren().isEmpty()) {
for (Diagnostic next : diagnostic.getChildren()) {
report(depth + 1, next);
}
}
}
protected abstract void doReport(int depth, int severity,
String message, Throwable exception);
protected String toSeverityString(int severity) {
switch (severity) {
case Diagnostic.OK :
return "OK"; //$NON-NLS-1$
case Diagnostic.INFO :
return "INFO"; //$NON-NLS-1$
case Diagnostic.WARNING :
return "WARN"; //$NON-NLS-1$
default :
return "ERROR"; //$NON-NLS-1$
}
}
}
/**
* A diagnostic reporter that prints diagnostics to a stream.
*/
class PrintStreamReporter
extends AbstractReporter {
private final PrintStream stream;
public PrintStreamReporter(PrintStream stream) {
this.stream = stream;
}
@Override
protected void doReport(int depth, int severity, String message,
Throwable exception) {
stream.printf("%" + (2 * depth) + "s[%5s] %s%n", //$NON-NLS-1$ //$NON-NLS-2$
"", //$NON-NLS-1$
toSeverityString(severity), message);
}
@Override
protected String toSeverityString(int severity) {
switch (severity) {
case Diagnostic.OK :
return "OK"; //$NON-NLS-1$
case Diagnostic.INFO :
return "INFO"; //$NON-NLS-1$
case Diagnostic.WARNING :
return "WARN"; //$NON-NLS-1$
default :
return "ERROR"; //$NON-NLS-1$
}
}
}
}