/
ESONDiagnosticConverter.java
58 lines (52 loc) · 1.81 KB
/
ESONDiagnosticConverter.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
/*
* #%L
* org.eclipse.emf.eson
* %%
* Copyright (C) 2016 Michael Vorburger and others.
* %%
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* #L%
*/
package org.eclipse.emf.eson.validation;
import org.eclipse.emf.eson.eFactory.NewObject;
import org.eclipse.xtext.validation.DiagnosticConverterImpl;
import org.eclipse.xtext.validation.FeatureBasedDiagnostic;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
/**
* Custom converter of diagnostic to avoid underlying too much info in file
*
* @author David Aguirre
*/
public class ESONDiagnosticConverter extends DiagnosticConverterImpl {
@Override
protected IssueLocation getLocationData(
org.eclipse.emf.common.util.Diagnostic diagnostic) {
IssueLocation issueLocation = super.getLocationData(diagnostic);
if (null != diagnostic) {
if (diagnostic instanceof FeatureBasedDiagnostic) {
fixLocationLength((FeatureBasedDiagnostic) diagnostic,
issueLocation);
}
}
return issueLocation;
}
private void fixLocationLength(FeatureBasedDiagnostic featDiag,
IssueLocation issueLocation) {
if (null != featDiag) {
if (featDiag.getSourceEObject() instanceof NewObject && featDiag
.getIndex() == ValidationMessageAcceptor.INSIGNIFICANT_INDEX) {
NewObject newObject = (NewObject) featDiag.getSourceEObject();
if (newObject.eClass() != null
&& newObject.eClass().getName() != null) {
// ~first line if we have an error without an index
// hence at new object level
issueLocation.length = newObject.eClass().getName().length()
+ 2;
}
}
}
}
}