[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
This commit is contained in:
Knut Wannheden 2013-02-17 10:56:15 +01:00
parent df18d11326
commit 3e52d685c4

View file

@ -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) {