Search in sources :

Example 6 with IHiddenRegion

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

the class TextReplacerContext method isInUndefinedRegion.

protected boolean isInUndefinedRegion(ITextReplacement repl) {
    ITextSegment replacerRegion = replacer.getRegion();
    IHiddenRegion hidden = null;
    if (replacerRegion instanceof IHiddenRegionPart) {
        hidden = ((IHiddenRegionPart) replacerRegion).getHiddenRegion();
    } else if (replacerRegion instanceof IHiddenRegion) {
        hidden = (IHiddenRegion) replacerRegion;
    }
    return hidden == null || hidden.isUndefined();
}
Also used : IHiddenRegionPart(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegionPart) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment)

Example 7 with IHiddenRegion

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

the class TextRegionAccessToString method toTokenAndGapList.

protected List<ITextSegment> toTokenAndGapList() {
    final int range = this.hightlightOrigin ? 4 : (Integer.MAX_VALUE / 2);
    ITextSegment first = null;
    {
        ITextSegment current = origin;
        for (int i = 0; i < range && current != null; i++) {
            first = current;
            if (current instanceof ITextRegionAccess)
                current = ((ITextRegionAccess) current).regionForRootEObject().getPreviousHiddenRegion();
            else if (current instanceof ISequentialRegion)
                current = ((ISequentialRegion) current).getPreviousHiddenRegion();
            else if (current instanceof IHiddenRegionPart)
                current = ((IHiddenRegionPart) current).getHiddenRegion();
            else
                throw new IllegalStateException("Unexpected Type: " + current.getClass());
        }
    }
    if (first == null)
        return Collections.emptyList();
    List<ITextSegment> result = Lists.newArrayList();
    {
        ITextSegment current = first;
        for (int i = 0; i <= (range * 2) && current != null; i++) {
            result.add(current);
            if (current instanceof ISemanticRegion)
                current = ((ISemanticRegion) current).getNextHiddenRegion();
            else if (current instanceof IHiddenRegion)
                current = ((IHiddenRegion) current).getNextSemanticRegion();
            else
                throw new IllegalStateException("Unexpected Type: " + current.getClass());
        }
    }
    return result;
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ISequentialRegion(org.eclipse.xtext.formatting2.regionaccess.ISequentialRegion) IHiddenRegionPart(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegionPart) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 8 with IHiddenRegion

use of org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion 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 9 with IHiddenRegion

use of org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion 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 10 with IHiddenRegion

use of org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion 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)

Aggregations

IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)21 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)8 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)6 IHiddenRegionPart (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegionPart)4 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)4 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)4 EObject (org.eclipse.emf.ecore.EObject)3 ISequentialRegion (org.eclipse.xtext.formatting2.regionaccess.ISequentialRegion)3 AbstractElement (org.eclipse.xtext.AbstractElement)2 IHiddenRegionFormatting (org.eclipse.xtext.formatting2.IHiddenRegionFormatting)2 ITextReplacer (org.eclipse.xtext.formatting2.ITextReplacer)2 IAstRegion (org.eclipse.xtext.formatting2.regionaccess.IAstRegion)2 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 ChangeKind (org.eclipse.emf.ecore.change.ChangeKind)1 ListChange (org.eclipse.emf.ecore.change.ListChange)1 AbstractFormatter2 (org.eclipse.xtext.formatting2.AbstractFormatter2)1