From 3e52d685c439b741c1a2eaaaf7b961b7b6847742 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Sun, 17 Feb 2013 10:56:15 +0100 Subject: [PATCH] [validation][bug 400989] Get issue location from parent node DiagnosticConverterImpl#getLocationData() can only retrieve the location data (line number, offset, and length) if there is any node in the parse tree directly corresponding to the semantic object. This commit changes this by retrieving the location data for the container object in that case. Additionally there is a last fallback which will return location data (0, 0, 0) to make sure that there will always be an annotation displayed in the editor. Change-Id: Ied45b9dcaa402e32de94da496601116b6c4c3293 --- .../xtext/validation/DiagnosticConverterImpl.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/validation/DiagnosticConverterImpl.java b/plugins/org.eclipse.xtext/src/org/eclipse/xtext/validation/DiagnosticConverterImpl.java index 8106473ba..6141240c5 100644 --- a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/validation/DiagnosticConverterImpl.java +++ b/plugins/org.eclipse.xtext/src/org/eclipse/xtext/validation/DiagnosticConverterImpl.java @@ -11,6 +11,7 @@ import static com.google.common.collect.Lists.*; import java.util.List; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.resource.Resource.Diagnostic; @@ -216,8 +217,18 @@ public class DiagnosticConverterImpl implements IDiagnosticConverter { parserNode = nodes.get(index); } return getLocationForNode(parserNode); + } else if (obj.eContainer() != null) { + EObject container = obj.eContainer(); + EStructuralFeature containingFeature = obj.eContainingFeature(); + return getLocationData(container, containingFeature, + containingFeature.isMany() ? ((EList) container.eGet(containingFeature)).indexOf(obj) + : ValidationMessageAcceptor.INSIGNIFICANT_INDEX); } - return null; + IssueLocation result = new IssueLocation(); + result.lineNumber = 0; + result.offset = 0; + result.length = 0; + return result; } protected IssueLocation getLocationForNode(INode node) {