Search in sources :

Example 56 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.

the class StringBasedTextRegionAccessDiffAppender method updateEObjectRegions.

protected void updateEObjectRegions() {
    ISemanticRegion current = this.last.getPreviousSemanticRegion();
    while (true) {
        ISemanticRegion sem = (ISemanticRegion) current;
        EObject eobj = sem.getSemanticElement();
        IHiddenRegion nextHiddenRegion = sem.getNextHiddenRegion();
        while (eobj != null) {
            AbstractEObjectRegion eobjRegion = getOrCreateEObjectRegion(eobj, null);
            if (eobjRegion.getNextHiddenRegion() != null) {
                break;
            }
            eobjRegion.setTrailingHiddenRegion(nextHiddenRegion);
            eobj = eobj.eContainer();
        }
        ISemanticRegion prev = sem.getPreviousSemanticRegion();
        if (prev == null) {
            break;
        } else {
            current = prev;
        }
    }
    while (true) {
        ISemanticRegion sem = (ISemanticRegion) current;
        EObject eobj = sem.getSemanticElement();
        IHiddenRegion previousHiddenRegion = sem.getPreviousHiddenRegion();
        while (eobj != null) {
            AbstractEObjectRegion eobjRegion = result.regionForEObject(eobj);
            if (eobjRegion.getPreviousHiddenRegion() != null) {
                break;
            }
            eobjRegion.setLeadingHiddenRegion(previousHiddenRegion);
            eobj = eobj.eContainer();
        }
        ISemanticRegion next = sem.getNextSemanticRegion();
        if (next == null) {
            break;
        } else {
            current = next;
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 57 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.

the class StringBasedTextRegionAccessDiffAppender method finish.

public StringBasedTextRegionAccessDiff finish() {
    if (this.last instanceof ISemanticRegion) {
        appendHiddenRegion(false);
    }
    updateEObjectRegions();
    if (diffFirstOriginal != null && diffFirstCopy != null && diffFirstCopy != null) {
        IHiddenRegion orig = result.getOriginalTextRegionAccess().regionForRootEObject().getNextHiddenRegion();
        result.append(new SequentialRegionDiff(diffFirstOriginal, orig, diffFirstCopy, this.last));
        diffFirstCopy = null;
        diffFirstOriginal = null;
    }
    return result;
}
Also used : IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 58 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.

the class FormattableDocumentTest method autowrap.

@Test
public void autowrap() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(10));
        };
        it.preferences(_function_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("idlist  aaa  bbb  ccc  ddd  eee  fff");
        _builder.newLine();
        it.setToBeFormatted(_builder);
        final GenericFormatter<IDList> _function_2 = new GenericFormatter<IDList>() {

            @Override
            protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
                final Consumer<ISemanticRegion> _function = (ISemanticRegion it_1) -> {
                    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_2) -> {
                        it_2.autowrap();
                        it_2.oneSpace();
                    };
                    document.prepend(it_1, _function_1);
                };
                regions.regionFor(model).ruleCallsTo(FormattableDocumentTest.this._formatterTestLanguageGrammarAccess.getIDRule()).forEach(_function);
            }
        };
        it.setFormatter(_function_2);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("idlist aaa");
        _builder_1.newLine();
        _builder_1.append("bbb ccc");
        _builder_1.newLine();
        _builder_1.append("ddd eee fff");
        _builder_1.newLine();
        it.setExpectation(_builder_1);
    };
    this._genericFormatterTester.assertFormatted(_function);
}
Also used : GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) Consumer(java.util.function.Consumer) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) Test(org.junit.Test)

Aggregations

ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)54 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)32 Test (org.junit.Test)32 ISemanticRegionsFinder (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder)17 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)15 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)13 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)12 Mixed (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed)12 EObject (org.eclipse.emf.ecore.EObject)9 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)9 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)8 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)7 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)4 AssignedAction (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.AssignedAction)4 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)3 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)3 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)3 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)3 ValueList (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList)3 XtextResource (org.eclipse.xtext.resource.XtextResource)3