Search in sources :

Example 21 with ITextRegionWithLineInformation

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

the class LocationInFileProviderTest method testBug353969_02.

@Test
public void testBug353969_02() throws Exception {
    Processor p = (Processor) model.getComponents().get(0);
    EList<Mode> modes = p.getMode();
    assertEquals(2, modes.size());
    Mode m2 = modes.get(1);
    ITextRegionWithLineInformation m2FullRegion = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(m2);
    assertEquals(modelAsString.indexOf("mode m2;"), m2FullRegion.getOffset());
    assertEquals("mode m2;".length(), m2FullRegion.getLength());
    assertEquals(4, m2FullRegion.getLineNumber());
    assertEquals(4, m2FullRegion.getEndLineNumber());
    ITextRegionWithLineInformation m2SignificantRegion = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(m2);
    assertEquals(modelAsString.indexOf("m2;"), m2SignificantRegion.getOffset());
    assertEquals("m2".length(), m2SignificantRegion.getLength());
    assertEquals(4, m2SignificantRegion.getLineNumber());
    assertEquals(4, m2SignificantRegion.getEndLineNumber());
}
Also used : Processor(org.eclipse.xtext.resource.locationprovidertest.Processor) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) Mode(org.eclipse.xtext.resource.locationprovidertest.Mode) Test(org.junit.Test)

Example 22 with ITextRegionWithLineInformation

use of org.eclipse.xtext.util.ITextRegionWithLineInformation 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 23 with ITextRegionWithLineInformation

use of org.eclipse.xtext.util.ITextRegionWithLineInformation 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)

Example 24 with ITextRegionWithLineInformation

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

the class CharSequenceTraceWrapper method wrapWithTraceData.

public CharSequence wrapWithTraceData(CharSequence sequence, EObject origin) {
    ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(origin);
    AbsoluteURI absoluteURI = new AbsoluteURI(origin.eResource().getURI());
    IProjectConfig projectConfig = projectConfigProvider.getProjectConfig(EcoreUtil2.getResourceSet(origin));
    SourceRelativeURI sourceRelativeURI = absoluteURI.deresolve(projectConfig);
    return wrapWithTraceData(sequence, sourceRelativeURI, location.getOffset(), location.getLength(), location.getLineNumber(), location.getEndLineNumber());
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) IProjectConfig(org.eclipse.xtext.workspace.IProjectConfig)

Example 25 with ITextRegionWithLineInformation

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

the class TracingSugar method location.

/**
 * @return ILocationData covering the <code>fullTextRegion</code> of the given EObject.
 */
public ILocationData location(final EObject obj) {
    final ITextRegion region = this.locationProvider.getFullTextRegion(obj);
    final SourceRelativeURI uri = this.traceURIConverter.getURIForTrace(obj.eResource());
    return new LocationData(((ITextRegionWithLineInformation) region), uri);
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) LocationData(org.eclipse.xtext.generator.trace.LocationData) ILocationData(org.eclipse.xtext.generator.trace.ILocationData) ITextRegion(org.eclipse.xtext.util.ITextRegion) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Aggregations

ITextRegionWithLineInformation (org.eclipse.xtext.util.ITextRegionWithLineInformation)26 Test (org.junit.Test)14 TextRegionWithLineInformation (org.eclipse.xtext.util.TextRegionWithLineInformation)5 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)4 Mode (org.eclipse.xtext.resource.locationprovidertest.Mode)4 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)3 ILocationData (org.eclipse.xtext.generator.trace.ILocationData)3 INode (org.eclipse.xtext.nodemodel.INode)3 Bus (org.eclipse.xtext.resource.locationprovidertest.Bus)3 Processor (org.eclipse.xtext.resource.locationprovidertest.Processor)3 ITextRegion (org.eclipse.xtext.util.ITextRegion)3 EObject (org.eclipse.emf.ecore.EObject)2 LocationData (org.eclipse.xtext.generator.trace.LocationData)2 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 URI (org.eclipse.emf.common.util.URI)1 RootTraceRegionForTesting (org.eclipse.xtend.core.tests.compiler.RootTraceRegionForTesting)1 SimpleTrace (org.eclipse.xtend.core.tests.compiler.SimpleTrace)1