Search in sources :

Example 6 with TextRegionWithLineInformation

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

the class TraceRegionTest method testLeafIterator_OneChild_LeftGap.

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

Example 7 with TextRegionWithLineInformation

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

the class TraceRegionTest method testLeafIterator_OneGrandChild_LeftGap.

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

Example 8 with TextRegionWithLineInformation

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

the class TraceRegionTest method testLeafIterator_OneChild_RightGap.

@Test
public void testLeafIterator_OneChild_RightGap() {
    final TraceRegion parent = new TraceRegion(0, 2, 0, 2, true, 2, 3, 0, 0, null, newURI());
    AbstractTraceRegion 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), parent) {
    };
    Iterator<AbstractTraceRegion> iter = parent.leafIterator();
    assertEquals(Arrays.asList(first, second).iterator(), iter);
}
Also used : TextRegionWithLineInformation(org.eclipse.xtext.util.TextRegionWithLineInformation) Test(org.junit.Test)

Example 9 with TextRegionWithLineInformation

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

the class AbstractNode method getTextRegionWithLineInformation.

/**
 * @since 2.5
 */
protected ITextRegionWithLineInformation getTextRegionWithLineInformation(int offset, int length) {
    INode rootNode = getRootNode();
    if (rootNode != null) {
        int startLine = basicGetLineOfOffset(rootNode, offset);
        int endLine = basicGetLineOfOffset(rootNode, offset + length);
        return new TextRegionWithLineInformation(offset, length, startLine, endLine);
    }
    return new TextRegionWithLineInformation(offset, length, 1, 1);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) TextRegionWithLineInformation(org.eclipse.xtext.util.TextRegionWithLineInformation)

Example 10 with TextRegionWithLineInformation

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

the class AbstractTraceRegion method getMergedAssociatedLocation.

/**
 * Returns the merged location of all associated locations if they belong to the same resource. Otherwise
 * <code>null</code> is returned.
 */
public ILocationData getMergedAssociatedLocation() {
    List<ILocationData> allData = getAssociatedLocations();
    if (allData.isEmpty()) {
        return null;
    }
    if (allData.size() == 1) {
        return allData.get(0);
    }
    boolean allNull = true;
    SourceRelativeURI path = null;
    ITextRegionWithLineInformation region = ITextRegionWithLineInformation.EMPTY_REGION;
    for (ILocationData data : allData) {
        if (path != null) {
            if (!path.equals(data.getSrcRelativePath())) {
                return null;
            }
        } else {
            if (data.getSrcRelativePath() == null) {
                if (!allNull)
                    throw new IllegalStateException("Iff multiple associated locations are present, the path has to be set");
            } else {
                allNull = false;
                path = data.getSrcRelativePath();
            }
        }
        region = region.merge(new TextRegionWithLineInformation(data.getOffset(), data.getLength(), data.getLineNumber(), data.getEndLineNumber()));
    }
    return new LocationData(region.getOffset(), region.getLength(), region.getLineNumber(), region.getEndLineNumber(), path);
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) TextRegionWithLineInformation(org.eclipse.xtext.util.TextRegionWithLineInformation) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation)

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