Search in sources :

Example 1 with BidiTreeIterator

use of org.eclipse.xtext.nodemodel.BidiTreeIterator in project xtext-core by eclipse.

the class Range method mergeAllSyntaxErrors.

public void mergeAllSyntaxErrors(INode node) {
    if (node.getSyntaxErrorMessage() != null)
        merge(node);
    else {
        // first syntax error
        boolean errorSeen = false;
        {
            BidiTreeIterator<INode> iterator = node.getAsTreeIterable().iterator();
            while (!errorSeen && iterator.hasNext()) {
                INode next = iterator.next();
                if (next.getSyntaxErrorMessage() != null) {
                    merge(next);
                    errorSeen = true;
                }
            }
        }
        // last syntax error
        if (errorSeen) {
            BidiTreeIterator<INode> iterator = node.getAsTreeIterable().iterator();
            errorSeen = false;
            while (!errorSeen && iterator.hasPrevious()) {
                INode prev = iterator.previous();
                if (prev.getSyntaxErrorMessage() != null) {
                    merge(prev);
                    errorSeen = true;
                } else if (prev instanceof ILeafNode) {
                    // do not have a grammar element assigned
                    if (prev.getGrammarElement() == null) {
                        merge(prev);
                        errorSeen = true;
                    }
                }
            }
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) BidiTreeIterator(org.eclipse.xtext.nodemodel.BidiTreeIterator) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode)

Aggregations

BidiTreeIterator (org.eclipse.xtext.nodemodel.BidiTreeIterator)1 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)1 INode (org.eclipse.xtext.nodemodel.INode)1