Search in sources :

Example 11 with ITextRegionWithLineInformation

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

the class LocationInFileProviderTest method testContainmentRefFullLocation.

@Test
public void testContainmentRefFullLocation() throws Exception {
    assertEquals(2, elements.size());
    ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(model, LocationprovidertestPackage.Literals.MODEL__ELEMENTS, 0);
    assertEquals(0, location.getOffset());
    assertEquals(modelAsString.indexOf(" element y"), location.getLength());
    assertEquals(0, location.getLineNumber());
    assertEquals(0, location.getEndLineNumber());
    location = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(model, LocationprovidertestPackage.Literals.MODEL__ELEMENTS, 1);
    assertEquals(modelAsString.lastIndexOf("element"), location.getOffset());
    assertEquals("element y".length(), location.getLength());
    assertEquals(0, location.getLineNumber());
    assertEquals(0, location.getEndLineNumber());
    // multi feature index out of bounds -> return owner's full region
    location = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(model, LocationprovidertestPackage.Literals.MODEL__ELEMENTS, 2);
    assertEquals(0, location.getOffset());
    assertEquals(modelAsString.length(), location.getLength());
    assertEquals(0, location.getLineNumber());
    assertEquals(10, location.getEndLineNumber());
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) Test(org.junit.Test)

Example 12 with ITextRegionWithLineInformation

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

the class LocationInFileProviderTest method testLineNumbers_01.

@Test
public void testLineNumbers_01() throws Exception {
    Processor p = (Processor) model.getComponents().get(0);
    ITextRegionWithLineInformation fullRegion = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(p);
    int b1Index = modelAsString.indexOf("processor p1");
    assertEquals(b1Index, fullRegion.getOffset());
    assertEquals(modelAsString.indexOf("end;") - b1Index + "end;".length(), fullRegion.getLength());
    assertEquals(1, fullRegion.getLineNumber());
    assertEquals(5, fullRegion.getEndLineNumber());
}
Also used : Processor(org.eclipse.xtext.resource.locationprovidertest.Processor) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) Test(org.junit.Test)

Example 13 with ITextRegionWithLineInformation

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

the class CompilerTraceTest method tracesTo.

public void tracesTo(final CharSequence xtend, final CharSequence java) {
    try {
        final String xtendWithSpaces = ((" " + xtend) + " ");
        final Matcher xtendMatcher = this.p.matcher(xtendWithSpaces);
        Assert.assertTrue("xtendMatcher.matches", xtendMatcher.matches());
        final String xtendGroup1 = xtendMatcher.group(1);
        final String xtendGroup2 = xtendMatcher.group(2);
        final String xtendGroup3 = xtendMatcher.group(3);
        final String actualXtendCode = ((xtendGroup1 + xtendGroup2) + xtendGroup3);
        final XtendFile file = this.file(actualXtendCode, true);
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        final JvmGenericType inferredType = this._iXtendJvmAssociations.getInferredType(((XtendClass) _head));
        CharSequence compiledCode = this.generator.generateType(inferredType, this.generatorConfigProvider.get(inferredType));
        compiledCode = this.postProcessor.postProcess(null, compiledCode);
        final Matcher javaMatcher = this.p.matcher(java.toString());
        Assert.assertTrue("javaMatcher.matches", javaMatcher.matches());
        final String javaGroup1 = javaMatcher.group(1);
        final String javaGroup2 = javaMatcher.group(2);
        final String javaGroup3 = javaMatcher.group(3);
        final String actualJavaExpectation = ((javaGroup1 + javaGroup2) + javaGroup3);
        Assert.assertEquals(actualJavaExpectation, compiledCode.toString());
        AbstractTraceRegion _traceRegion = ((ITraceRegionProvider) compiledCode).getTraceRegion();
        URI _createURI = URI.createURI(file.eResource().getURI().path());
        SourceRelativeURI _sourceRelativeURI = new SourceRelativeURI(_createURI);
        URI _createURI_1 = URI.createURI(file.eResource().getURI().path());
        SourceRelativeURI _sourceRelativeURI_1 = new SourceRelativeURI(_createURI_1);
        AbstractTraceRegion _merge = this.merge(_traceRegion.invertFor(_sourceRelativeURI, _sourceRelativeURI_1));
        final SimpleTrace trace = new SimpleTrace(_merge);
        int _length = xtendGroup1.length();
        int _length_1 = xtendGroup2.length();
        TextRegion _textRegion = new TextRegion(_length, _length_1);
        final Iterable<? extends ILocationInResource> locations = trace.getAllAssociatedLocations(_textRegion);
        int _length_2 = javaGroup1.length();
        int _length_3 = javaGroup2.length();
        final TextRegion expectedRegion = new TextRegion(_length_2, _length_3);
        Assert.assertFalse(IterableExtensions.isEmpty(locations));
        for (final ILocationInResource location : locations) {
            ITextRegionWithLineInformation _textRegion_1 = location.getTextRegion();
            boolean _equals = Objects.equal(_textRegion_1, expectedRegion);
            if (_equals) {
                return;
            }
        }
        Assert.fail(((("locations did not match expectation: " + locations) + " / ") + expectedRegion));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) TextRegion(org.eclipse.xtext.util.TextRegion) Matcher(java.util.regex.Matcher) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) SimpleTrace(org.eclipse.xtend.core.tests.compiler.SimpleTrace) URI(org.eclipse.emf.common.util.URI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) ILocationInResource(org.eclipse.xtext.generator.trace.ILocationInResource) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Example 14 with ITextRegionWithLineInformation

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

the class LocationInFileProviderTest method testLineNumbers_02.

@Test
public void testLineNumbers_02() throws Exception {
    Bus b = (Bus) model.getComponents().get(1);
    ITextRegionWithLineInformation fullRegion = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(b);
    int b1Index = modelAsString.indexOf("bus b1");
    assertEquals(b1Index, fullRegion.getOffset());
    assertEquals(modelAsString.length() - b1Index, fullRegion.getLength());
    assertEquals(6, fullRegion.getLineNumber());
    assertEquals(10, fullRegion.getEndLineNumber());
}
Also used : Bus(org.eclipse.xtext.resource.locationprovidertest.Bus) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) Test(org.junit.Test)

Example 15 with ITextRegionWithLineInformation

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

the class LocationInFileProviderTest method testEObjectFullLocation.

@Test
public void testEObjectFullLocation() throws Exception {
    assertEquals(2, elements.size());
    ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(elements.get(0));
    assertEquals(modelAsString.indexOf("element x"), location.getOffset());
    assertEquals(modelAsString.indexOf(" element y"), location.getLength());
    assertEquals(0, location.getLineNumber());
    assertEquals(0, location.getEndLineNumber());
    location = (ITextRegionWithLineInformation) locationInFileProvider.getFullTextRegion(elements.get(1));
    assertEquals(modelAsString.indexOf("element y"), location.getOffset());
    assertEquals("element y".length(), location.getLength());
    assertEquals(0, location.getLineNumber());
    assertEquals(0, location.getEndLineNumber());
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) 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