Search in sources :

Example 16 with ITextRegionWithLineInformation

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

the class LocationInFileProviderTest method testBug353969_03.

@Test
public void testBug353969_03() throws Exception {
    Bus b = (Bus) model.getComponents().get(1);
    EList<Mode> modes = b.getMode();
    assertEquals(2, modes.size());
    Mode mb1 = modes.get(0);
    ITextRegionWithLineInformation mb1FullRegion = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(mb1);
    assertEquals(modelAsString.indexOf("mode mb1;"), mb1FullRegion.getOffset());
    assertEquals("mode mb1;".length(), mb1FullRegion.getLength());
    assertEquals(8, mb1FullRegion.getLineNumber());
    assertEquals(8, mb1FullRegion.getEndLineNumber());
    ITextRegionWithLineInformation mb1SignificantRegion = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(mb1);
    assertEquals(modelAsString.indexOf("mb1;"), mb1SignificantRegion.getOffset());
    assertEquals("mb1".length(), mb1SignificantRegion.getLength());
    assertEquals(8, mb1SignificantRegion.getLineNumber());
    assertEquals(8, mb1SignificantRegion.getEndLineNumber());
}
Also used : Bus(org.eclipse.xtext.resource.locationprovidertest.Bus) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) Mode(org.eclipse.xtext.resource.locationprovidertest.Mode) Test(org.junit.Test)

Example 17 with ITextRegionWithLineInformation

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

the class LocationInFileProviderTest method testAttributeSignificantLocation.

@Test
public void testAttributeSignificantLocation() {
    assertEquals(2, elements.size());
    ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(elements.get(0), LocationprovidertestPackage.Literals.ELEMENT__NAME, 0);
    assertEquals(modelAsString.indexOf("x"), location.getOffset());
    assertEquals(1, location.getLength());
    assertEquals(0, location.getLineNumber());
    assertEquals(0, location.getEndLineNumber());
    // index out of bounds -> return owner's significant region
    location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(elements.get(1), LocationprovidertestPackage.Literals.ELEMENT__NAME, 1);
    assertEquals(modelAsString.lastIndexOf("y"), location.getOffset());
    assertEquals(1, location.getLength());
    assertEquals(0, location.getLineNumber());
    assertEquals(0, location.getEndLineNumber());
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) Test(org.junit.Test)

Example 18 with ITextRegionWithLineInformation

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

the class LocationInFileProviderTest method testCrossRefSignificantLocation.

@Test
public void testCrossRefSignificantLocation() throws Exception {
    assertEquals(2, elements.size());
    int indexOfFirstY = modelAsString.indexOf("y");
    int indexOfSecondY = modelAsString.indexOf("y", indexOfFirstY + 1);
    ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(elements.get(0), LocationprovidertestPackage.Literals.ELEMENT__SINGLEREF, 0);
    assertEquals(indexOfFirstY, location.getOffset());
    assertEquals(1, location.getLength());
    assertEquals(0, location.getLineNumber());
    assertEquals(0, location.getEndLineNumber());
    // single feature index out of bounds -> ignore index
    location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(elements.get(0), LocationprovidertestPackage.Literals.ELEMENT__SINGLEREF, 1);
    assertEquals(indexOfFirstY, location.getOffset());
    assertEquals(1, location.getLength());
    assertEquals(0, location.getLineNumber());
    assertEquals(0, location.getEndLineNumber());
    location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(elements.get(0), LocationprovidertestPackage.Literals.ELEMENT__MULTIREFS, 0);
    assertEquals(indexOfSecondY, location.getOffset());
    assertEquals(1, location.getLength());
    assertEquals(0, location.getLineNumber());
    assertEquals(0, location.getEndLineNumber());
    // multi feature index out of bounds -> return owner's significant region
    location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(elements.get(0), LocationprovidertestPackage.Literals.ELEMENT__MULTIREFS, 1);
    assertEquals(modelAsString.indexOf("x"), location.getOffset());
    assertEquals(1, location.getLength());
    assertEquals(0, location.getLineNumber());
    assertEquals(0, location.getEndLineNumber());
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) Test(org.junit.Test)

Example 19 with ITextRegionWithLineInformation

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

the class LocationInFileProviderTest method testBug353969_04.

@Test
public void testBug353969_04() throws Exception {
    Bus b = (Bus) model.getComponents().get(1);
    EList<Mode> modes = b.getMode();
    assertEquals(2, modes.size());
    Mode mb2 = modes.get(1);
    ITextRegionWithLineInformation mb2FullRegion = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(mb2);
    assertEquals(modelAsString.indexOf("mode mb2;"), mb2FullRegion.getOffset());
    assertEquals("mode mb2;".length(), mb2FullRegion.getLength());
    assertEquals(9, mb2FullRegion.getLineNumber());
    assertEquals(9, mb2FullRegion.getEndLineNumber());
    ITextRegionWithLineInformation mb2SignificantRegion = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(mb2);
    assertEquals(modelAsString.indexOf("mb2;"), mb2SignificantRegion.getOffset());
    assertEquals("mb2".length(), mb2SignificantRegion.getLength());
    assertEquals(9, mb2SignificantRegion.getLineNumber());
    assertEquals(9, mb2SignificantRegion.getEndLineNumber());
}
Also used : Bus(org.eclipse.xtext.resource.locationprovidertest.Bus) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) Mode(org.eclipse.xtext.resource.locationprovidertest.Mode) Test(org.junit.Test)

Example 20 with ITextRegionWithLineInformation

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

the class LocationInFileProviderTest method testBug353969_01.

@Test
public void testBug353969_01() throws Exception {
    Processor p = (Processor) model.getComponents().get(0);
    EList<Mode> modes = p.getMode();
    assertEquals(2, modes.size());
    Mode m1 = modes.get(0);
    ITextRegionWithLineInformation m1FullRegion = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(m1);
    assertEquals(modelAsString.indexOf("mode m1;"), m1FullRegion.getOffset());
    assertEquals("mode m1;".length(), m1FullRegion.getLength());
    assertEquals(3, m1FullRegion.getLineNumber());
    assertEquals(3, m1FullRegion.getEndLineNumber());
    ITextRegionWithLineInformation m1SignificantRegion = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(m1);
    assertEquals(modelAsString.indexOf("m1;"), m1SignificantRegion.getOffset());
    assertEquals("m1".length(), m1SignificantRegion.getLength());
    assertEquals(3, m1SignificantRegion.getLineNumber());
    assertEquals(3, m1SignificantRegion.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)

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