Search in sources :

Example 56 with ITextRegion

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

the class TracingSugar method location.

/**
 * @param obj the EObject containing the feature
 * @param feature the EStructuralFeature to trace
 * @param idx the index of the value to trace, in case the feature contains a list, should be <code>-1</code> otherwise.
 *
 * @return ILocationData covering the <code>fullTextRegion</code> of the given feature in the given EObject.
 */
public ILocationData location(final EObject obj, final EStructuralFeature feature, final int idx) {
    final ITextRegion region = this.locationProvider.getFullTextRegion(obj, feature, idx);
    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)

Example 57 with ITextRegion

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

the class AbstractFormatter2 method isInRequestedRange.

protected boolean isInRequestedRange(EObject obj) {
    Collection<ITextRegion> regions = request.getRegions();
    if (regions.isEmpty())
        return true;
    ITextRegionAccess access = request.getTextRegionAccess();
    IEObjectRegion objRegion = access.regionForEObject(obj);
    if (objRegion == null)
        return false;
    IHiddenRegion previousHidden = objRegion.getPreviousHiddenRegion();
    IHiddenRegion nextHidden = objRegion.getNextHiddenRegion();
    int objOffset = previousHidden != null ? previousHidden.getOffset() : 0;
    int objEnd = nextHidden != null ? nextHidden.getEndOffset() : access.regionForRootEObject().getEndOffset();
    for (ITextRegion region : regions) {
        int regionOffset = region.getOffset();
        int regionEnd = regionOffset + region.getLength();
        if (regionOffset <= objEnd && regionEnd >= objOffset)
            return true;
    }
    return false;
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 58 with ITextRegion

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

the class FormattableDocumentTest method shouldFormat.

@Test
public void shouldFormat() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        Collection<ITextRegion> _regions = it.getRequest().getRegions();
        TextRegion _textRegion = new TextRegion(0, 6);
        _regions.add(_textRegion);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("idlist");
        it.setToBeFormatted(_builder);
        it.setFormatter(new GenericFormatter() {

            @Override
            protected void format(final EObject model, final ITextRegionExtensions regionAccess, final IFormattableDocument document) {
                throw new IllegalStateException("this method should never be called");
            }

            @Override
            public boolean shouldFormat(final Object obj, final IFormattableDocument document) {
                return false;
            }
        });
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("idlist");
        it.setExpectation(_builder_1);
    };
    this._genericFormatterTester.assertFormatted(_function);
}
Also used : GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Test(org.junit.Test)

Example 59 with ITextRegion

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

the class TokenRegionProviderTest method testBug486454.

@Test
public void testBug486454() throws Exception {
    String model = "t";
    ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(1, 0));
    assertEquals(0, tokenRegion.getOffset());
    assertEquals(1, tokenRegion.getLength());
}
Also used : TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) Test(org.junit.Test)

Aggregations

ITextRegion (org.eclipse.xtext.util.ITextRegion)59 TextRegion (org.eclipse.xtext.util.TextRegion)24 Test (org.junit.Test)14 INode (org.eclipse.xtext.nodemodel.INode)11 EObject (org.eclipse.emf.ecore.EObject)9 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)9 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)9 Collection (java.util.Collection)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)4 CommonToken (org.antlr.runtime.CommonToken)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)3 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)3 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)3 XtextResource (org.eclipse.xtext.resource.XtextResource)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 CoreException (org.eclipse.core.runtime.CoreException)2 URI (org.eclipse.emf.common.util.URI)2