Search in sources :

Example 26 with TextRegion

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

the class XtendExpressionUtil method getRichStringPartTextRegion.

protected ITextRegion getRichStringPartTextRegion(EObject element) {
    if (element instanceof RichStringLiteral) {
        return locationInFileProvider.getSignificantTextRegion(element);
    }
    ICompositeNode elementNode = NodeModelUtils.getNode(element);
    ITextRegion totalTextRegion = elementNode.getTotalTextRegion();
    int offset = totalTextRegion.getOffset() - 1;
    int length = totalTextRegion.getLength() + 2;
    ILeafNode nextNode = NodeModelUtils.findLeafNodeAtOffset(elementNode.getRootNode(), elementNode.getEndOffset());
    while (nextNode != null && nextNode.isHidden()) {
        length += nextNode.getLength();
        INode nextSibling = nextNode.getNextSibling();
        if (nextSibling instanceof ILeafNode) {
            nextNode = (ILeafNode) nextSibling;
        } else {
            nextNode = null;
        }
    }
    return new TextRegion(offset, length);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 27 with TextRegion

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

the class ExtractMethodRefactoring method getExpressionsRegion.

protected ITextRegion getExpressionsRegion() {
    ITextRegion firstRegion = expressionUtil.getTextRegion(firstExpression);
    ITextRegion lastRegion = expressionUtil.getTextRegion(lastExpression);
    ITextRegion expressionRegion = new TextRegion(firstRegion.getOffset(), lastRegion.getOffset() + lastRegion.getLength() - firstRegion.getOffset());
    return expressionRegion;
}
Also used : TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 28 with TextRegion

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

the class AbstractXtendFormatterTest method assertFormatted.

public void assertFormatted(final Procedure1<? super MapBasedPreferenceValues> cfg, final CharSequence expectation, final CharSequence toBeFormatted, final String prefix, final String postfix, final boolean allowErrors) {
    final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(80));
            it_1.<Boolean>put(XtendFormatterPreferenceKeys.keepOneLineMethods, Boolean.valueOf(false));
            if (cfg != null) {
                cfg.apply(it_1);
            }
        };
        it.preferences(_function_1);
        it.setExpectation(((prefix + expectation) + postfix));
        it.setToBeFormatted(((prefix + toBeFormatted) + postfix));
        Collection<ITextRegion> _regions = it.getRequest().getRegions();
        int _length = prefix.length();
        int _length_1 = toBeFormatted.length();
        TextRegion _textRegion = new TextRegion(_length, _length_1);
        _regions.add(_textRegion);
        it.setAllowSyntaxErrors(allowErrors);
    };
    this.tester.assertFormatted(_function);
}
Also used : TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) FormatterTestRequest(org.eclipse.xtext.testing.formatter.FormatterTestRequest) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) Collection(java.util.Collection)

Example 29 with TextRegion

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

the class FlexTokenRegionProviderTest method testTokenMerge_1.

@Test
public void testTokenMerge_1() throws Exception {
    String model = " ab ";
    ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 0));
    assertEquals(1, tokenRegion.getOffset());
    assertEquals(2, 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)

Example 30 with TextRegion

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

the class FlexTokenRegionProviderTest method testTokenSplit_1.

@Test
public void testTokenSplit_1() throws Exception {
    String model = " axb ";
    ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 1));
    assertEquals(1, tokenRegion.getOffset());
    assertEquals(3, 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

TextRegion (org.eclipse.xtext.util.TextRegion)41 ITextRegion (org.eclipse.xtext.util.ITextRegion)28 Test (org.junit.Test)19 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 Collection (java.util.Collection)5 StringReader (java.io.StringReader)3 CommonToken (org.antlr.runtime.CommonToken)3 IFile (org.eclipse.core.resources.IFile)3 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)3 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)3 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)3 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)3 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)3 IEclipseTrace (org.eclipse.xtext.ui.generator.trace.IEclipseTrace)3 EObject (org.eclipse.emf.ecore.EObject)2 ITextSelection (org.eclipse.jface.text.ITextSelection)2 AbstractElement (org.eclipse.xtext.AbstractElement)2 ILocationData (org.eclipse.xtext.generator.trace.ILocationData)2 ILocationInResource (org.eclipse.xtext.generator.trace.ILocationInResource)2 TraceRegionToStringTester (org.eclipse.xtext.generator.trace.TraceRegionToStringTester)2