mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
[xbase][validation] Improve error ranges for conformance problems
This commit is contained in:
parent
a18d6b0051
commit
5b98d8db9a
2 changed files with 21 additions and 10 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue