Search in sources :

Example 6 with IEObjectRegion

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

the class FormattableDocument method append.

@Override
public <T extends EObject> T append(T owner, Procedure1<? super IHiddenRegionFormatter> after) {
    if (owner != null) {
        IEObjectRegion region = getTextRegionAccess().regionForEObject(owner);
        if (region != null) {
            IHiddenRegion gap = region.getNextHiddenRegion();
            set(gap, after);
        }
    }
    return owner;
}
Also used : IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 7 with IEObjectRegion

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

the class TextRegionAccessToString method toString.

@Override
public String toString() {
    List<ITextSegment> list = toTokenAndGapList();
    if (list.isEmpty())
        return "(empty)";
    ITextRegionAccess access = list.get(0).getTextRegionAccess();
    DiffColumn diff = new DiffColumn(access);
    TextRegionListToString result = new TextRegionListToString();
    if (!hideColumnExplanation) {
        if (diff.isDiff()) {
            result.add("Columns: 1:offset 2:length 3:diff 4:kind 5: text 6:grammarElement", false);
        } else {
            result.add("Columns: 1:offset 2:length 3:kind 4: text 5:grammarElement", false);
        }
        result.add("Kind: H=IHiddenRegion S=ISemanticRegion B/E=IEObjectRegion", false);
        result.add("", false);
    }
    appendRegions(result, list, diff, false);
    diff.appendDiffs(result, this);
    return result.toString();
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment)

Example 8 with IEObjectRegion

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

the class FormattableDocument method interior.

@Override
public <T extends EObject> T interior(T object, Procedure1<? super IHiddenRegionFormatter> init) {
    if (object != null) {
        IEObjectRegion objRegion = getTextRegionAccess().regionForEObject(object);
        if (objRegion != null) {
            IHiddenRegion previous = objRegion.getPreviousHiddenRegion();
            IHiddenRegion next = objRegion.getNextHiddenRegion();
            if (previous != null && next != null && previous != next) {
                interior(previous.getNextSemanticRegion(), next.getPreviousSemanticRegion(), init);
            }
        }
    }
    return object;
}
Also used : IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 9 with IEObjectRegion

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

the class FormattableDocument method prepend.

@Override
public <T extends EObject> T prepend(T owner, Procedure1<? super IHiddenRegionFormatter> before) {
    if (owner != null) {
        IEObjectRegion region = getTextRegionAccess().regionForEObject(owner);
        if (region != null) {
            IHiddenRegion gap = region.getPreviousHiddenRegion();
            set(gap, before);
        }
    }
    return owner;
}
Also used : IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 10 with IEObjectRegion

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

the class FormattableDocument method surround.

@Override
public <T extends EObject> T surround(T owner, Procedure1<? super IHiddenRegionFormatter> beforeAndAfter) {
    if (owner != null && !owner.eIsProxy()) {
        IEObjectRegion region = getTextRegionAccess().regionForEObject(owner);
        if (region == null)
            return owner;
        IHiddenRegion previous = region.getPreviousHiddenRegion();
        IHiddenRegion next = region.getNextHiddenRegion();
        set(previous, next, beforeAndAfter);
    }
    return owner;
}
Also used : IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Aggregations

IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)16 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)9 EObject (org.eclipse.emf.ecore.EObject)8 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)7 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)5 EReference (org.eclipse.emf.ecore.EReference)4 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)4 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 IAstRegion (org.eclipse.xtext.formatting2.regionaccess.IAstRegion)3 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 EList (org.eclipse.emf.common.util.EList)2 ListChange (org.eclipse.emf.ecore.change.ListChange)2 AbstractElement (org.eclipse.xtext.AbstractElement)2 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)2 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)2 Delegate (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Delegate)2