Search in sources :

Example 1 with TextRegionWithLineInformation

use of org.eclipse.xtext.util.TextRegionWithLineInformation in project xtext-xtend by eclipse.

the class XtendLocationInFileProvider method getSignificantTextRegion.

@Override
public ITextRegion getSignificantTextRegion(EObject element) {
    if (element instanceof RichStringLiteral) {
        ICompositeNode elementNode = findNodeFor(element);
        if (elementNode == null) {
            return ITextRegion.EMPTY_REGION;
        }
        ITextRegion result = ITextRegion.EMPTY_REGION;
        for (INode node : elementNode.getLeafNodes()) {
            if (isHidden(node)) {
                continue;
            }
            EObject grammarElement = node.getGrammarElement();
            if (!(grammarElement instanceof RuleCall)) {
                continue;
            }
            RuleCall ruleCall = (RuleCall) grammarElement;
            ITextRegionWithLineInformation region = node.getTextRegionWithLineInformation();
            int offset = region.getOffset();
            int length = region.getLength();
            if (grammarAccess.getRICH_TEXTRule() == ruleCall.getRule()) {
                offset += 3;
                length -= 6;
            } else if (grammarAccess.getRICH_TEXT_STARTRule() == ruleCall.getRule()) {
                offset += 3;
                length -= 4;
            } else if (grammarAccess.getRICH_TEXT_ENDRule() == ruleCall.getRule()) {
                offset += 1;
                length -= 4;
            } else if (grammarAccess.getRICH_TEXT_INBETWEENRule() == ruleCall.getRule()) {
                offset += 1;
                length -= 2;
            } else if (grammarAccess.getCOMMENT_RICH_TEXT_ENDRule() == ruleCall.getRule()) {
                offset += 2;
                length -= 5;
            } else if (grammarAccess.getCOMMENT_RICH_TEXT_INBETWEENRule() == ruleCall.getRule()) {
                offset += 2;
                length -= 3;
            } else {
                continue;
            }
            result = result.merge(toZeroBasedRegion(new TextRegionWithLineInformation(offset, length, region.getLineNumber(), region.getEndLineNumber())));
        }
        return result;
    }
    return super.getSignificantTextRegion(element);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) RuleCall(org.eclipse.xtext.RuleCall) TextRegionWithLineInformation(org.eclipse.xtext.util.TextRegionWithLineInformation) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation)

Example 2 with TextRegionWithLineInformation

use of org.eclipse.xtext.util.TextRegionWithLineInformation in project xtext-xtend by eclipse.

the class CompilerTraceTest method merge.

public AbstractTraceRegion merge(final List<AbstractTraceRegion> regions) {
    boolean _isEmpty = regions.isEmpty();
    boolean _not = (!_isEmpty);
    Assert.assertTrue(_not);
    int _size = regions.size();
    boolean _greaterThan = (_size > 1);
    if (_greaterThan) {
        ITextRegionWithLineInformation rootLocation = ITextRegionWithLineInformation.EMPTY_REGION;
        ITextRegionWithLineInformation associated = ITextRegionWithLineInformation.EMPTY_REGION;
        for (final AbstractTraceRegion child : regions) {
            {
                int _myOffset = child.getMyOffset();
                int _myLength = child.getMyLength();
                int _myLineNumber = child.getMyLineNumber();
                int _myEndLineNumber = child.getMyEndLineNumber();
                TextRegionWithLineInformation _textRegionWithLineInformation = new TextRegionWithLineInformation(_myOffset, _myLength, _myLineNumber, _myEndLineNumber);
                rootLocation = rootLocation.merge(_textRegionWithLineInformation);
                ILocationData childAssociation = child.getMergedAssociatedLocation();
                if ((childAssociation != null)) {
                    associated = associated.merge(childAssociation);
                }
            }
        }
        final RootTraceRegionForTesting root = new RootTraceRegionForTesting(rootLocation, associated);
        for (final AbstractTraceRegion child_1 : regions) {
            child_1.setParent(root);
        }
        return root;
    } else {
        return IterableExtensions.<AbstractTraceRegion>head(regions);
    }
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) RootTraceRegionForTesting(org.eclipse.xtend.core.tests.compiler.RootTraceRegionForTesting) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) TextRegionWithLineInformation(org.eclipse.xtext.util.TextRegionWithLineInformation) ILocationData(org.eclipse.xtext.generator.trace.ILocationData)

Example 3 with TextRegionWithLineInformation

use of org.eclipse.xtext.util.TextRegionWithLineInformation in project xtext-core by eclipse.

the class DefaultHierarchyNodeLocationProvider method toTextRegionWithLineInformation.

protected ITextRegionWithLineInformation toTextRegionWithLineInformation(final EObject obj, final ITextRegion textRegion) {
    if ((textRegion == null)) {
        return ITextRegionWithLineInformation.EMPTY_REGION;
    }
    if ((textRegion instanceof ITextRegionWithLineInformation)) {
        return ((ITextRegionWithLineInformation) textRegion);
    }
    final ICompositeNode node = NodeModelUtils.getNode(obj);
    if ((node == null)) {
        int _offset = textRegion.getOffset();
        int _length = textRegion.getLength();
        return new TextRegionWithLineInformation(_offset, _length, 0, 0);
    }
    int _line = NodeModelUtils.getLineAndColumn(node, textRegion.getOffset()).getLine();
    final int startLine = (_line - 1);
    int _offset_1 = textRegion.getOffset();
    int _length_1 = textRegion.getLength();
    int _plus = (_offset_1 + _length_1);
    int _line_1 = NodeModelUtils.getLineAndColumn(node, _plus).getLine();
    final int endLine = (_line_1 - 1);
    int _offset_2 = textRegion.getOffset();
    int _length_2 = textRegion.getLength();
    return new TextRegionWithLineInformation(_offset_2, _length_2, startLine, endLine);
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) TextRegionWithLineInformation(org.eclipse.xtext.util.TextRegionWithLineInformation) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation)

Example 4 with TextRegionWithLineInformation

use of org.eclipse.xtext.util.TextRegionWithLineInformation in project xtext-core by eclipse.

the class TraceRegionTest method testLeafIterator_TwoChildren_WithGaps.

@Test
public void testLeafIterator_TwoChildren_WithGaps() {
    final TraceRegion parent = new TraceRegion(0, 3, 0, 3, true, 2, 3, 0, 0, null, newURI());
    TraceRegion first = new TraceRegion(0, 1, 0, 1, true, 2, 3, 0, 0, parent, null);
    AbstractTraceRegion second = new AbstractStatefulTraceRegion(new TextRegionWithLineInformation(1, 1, 1, 2), true, new LocationData(2, 3, 0, 0, null), parent) {
    };
    AbstractTraceRegion third = new TraceRegion(2, 1, 2, 3, true, 3, 4, 0, 0, parent, null);
    Iterator<AbstractTraceRegion> iter = parent.leafIterator();
    assertEquals(Arrays.asList(first, second, third).iterator(), iter);
}
Also used : TextRegionWithLineInformation(org.eclipse.xtext.util.TextRegionWithLineInformation) Test(org.junit.Test)

Example 5 with TextRegionWithLineInformation

use of org.eclipse.xtext.util.TextRegionWithLineInformation in project xtext-core by eclipse.

the class TraceRegionTest method testLeafIterator_OneGrandChild_RightGap.

@Test
public void testLeafIterator_OneGrandChild_RightGap() {
    final TraceRegion root = new TraceRegion(0, 2, 0, 2, true, 2, 3, 0, 0, null, newURI());
    TraceRegion parent = new TraceRegion(0, 1, 0, 1, true, 3, 4, 0, 0, root, null);
    TraceRegion first = new TraceRegion(0, 1, 0, 1, true, 3, 4, 0, 0, parent, null);
    AbstractTraceRegion second = new AbstractStatefulTraceRegion(new TextRegionWithLineInformation(1, 1, 1, 2), true, new LocationData(2, 3, 0, 0, null), root) {
    };
    Iterator<AbstractTraceRegion> iter = root.leafIterator();
    assertEquals(Arrays.asList(first, second).iterator(), iter);
}
Also used : TextRegionWithLineInformation(org.eclipse.xtext.util.TextRegionWithLineInformation) Test(org.junit.Test)

Aggregations

TextRegionWithLineInformation (org.eclipse.xtext.util.TextRegionWithLineInformation)10 ITextRegionWithLineInformation (org.eclipse.xtext.util.ITextRegionWithLineInformation)5 Test (org.junit.Test)5 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 INode (org.eclipse.xtext.nodemodel.INode)2 EObject (org.eclipse.emf.ecore.EObject)1 RootTraceRegionForTesting (org.eclipse.xtend.core.tests.compiler.RootTraceRegionForTesting)1 RichStringLiteral (org.eclipse.xtend.core.xtend.RichStringLiteral)1 RuleCall (org.eclipse.xtext.RuleCall)1 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)1 ILocationData (org.eclipse.xtext.generator.trace.ILocationData)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1