[xbase][validation] Improve error ranges for conformance problems

This commit is contained in:
Sebastian Zarnekow 2013-03-01 10:38:33 +01:00
parent a18d6b0051
commit 5b98d8db9a
2 changed files with 21 additions and 10 deletions

View file

@ -22,6 +22,7 @@ import org.eclipse.xtext.validation.CheckMode;
import org.eclipse.xtext.validation.IResourceValidator;
import org.eclipse.xtext.validation.Issue;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
@ -146,6 +147,7 @@ public class ValidationTestHelper {
.append(eObject.eClass().getName())
.append("\n");
}
assertEquals(Joiner.on('\n').join(messageParts), message.toString());
fail(message.toString());
}
}

View file

@ -50,19 +50,28 @@ public class EObjectDiagnosticImpl extends AbstractDiagnostic {
@Override
protected INode getNode() {
if (problematicObject == null)
return doGetNode(problematicObject, problematicFeature, indexOfProblemanticValueInFeature);
}
protected INode doGetNode(EObject object, EStructuralFeature feature, int idx) {
if (object == null)
return null;
if (problematicFeature == null)
return NodeModelUtils.findActualNodeFor(problematicObject);
List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(problematicObject, problematicFeature);
if (nodesForFeature.isEmpty()) {
return NodeModelUtils.findActualNodeFor(problematicObject);
if (feature == null) {
INode result = NodeModelUtils.findActualNodeFor(object);
if (result != null) {
return result;
}
return doGetNode(object.eContainer(), object.eContainmentFeature(), -1);
}
if (nodesForFeature.size() == 1 && indexOfProblemanticValueInFeature == -1)
List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(object, feature);
if (nodesForFeature.isEmpty()) {
return doGetNode(object, null, -1);
}
if (nodesForFeature.size() == 1 && idx == -1)
return nodesForFeature.get(0);
if (nodesForFeature.size() > indexOfProblemanticValueInFeature ) {
return nodesForFeature.get(indexOfProblemanticValueInFeature);
if (nodesForFeature.size() > idx ) {
return nodesForFeature.get(idx);
}
return null;
}