Search in sources :

Example 16 with IHiddenRegion

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

the class FormattableDocument method prepend.

@Override
public ISemanticRegion prepend(ISemanticRegion token, Procedure1<? super IHiddenRegionFormatter> before) {
    if (token != null) {
        IHiddenRegion gap = token.getPreviousHiddenRegion();
        set(gap, before);
    }
    return token;
}
Also used : IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 17 with IHiddenRegion

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

the class FormattableDocument method append.

@Override
public ISemanticRegion append(ISemanticRegion token, Procedure1<? super IHiddenRegionFormatter> after) {
    if (token != null) {
        IHiddenRegion gap = token.getNextHiddenRegion();
        set(gap, after);
    }
    return token;
}
Also used : IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 18 with IHiddenRegion

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

the class FormattableDocument method surround.

@Override
public ISemanticRegion surround(ISemanticRegion token, Procedure1<? super IHiddenRegionFormatter> beforeAndAfter) {
    if (token != null) {
        IHiddenRegion previous = token.getPreviousHiddenRegion();
        IHiddenRegion next = token.getNextHiddenRegion();
        set(previous, next, beforeAndAfter);
    }
    return token;
}
Also used : IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 19 with IHiddenRegion

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

the class TextReplacerMerger method mergeHiddenRegionReplacers.

protected ITextReplacer mergeHiddenRegionReplacers(List<? extends ITextReplacer> conflicting) {
    List<IHiddenRegionFormatting> formattings = Lists.newArrayList();
    IHiddenRegion region = null;
    for (ITextReplacer replacer : conflicting) {
        if (replacer instanceof HiddenRegionReplacer) {
            HiddenRegionReplacer hiddenRegionReplacer = (HiddenRegionReplacer) replacer;
            formattings.add(hiddenRegionReplacer.getFormatting());
            if (region == null)
                region = hiddenRegionReplacer.getRegion();
            else if (region != hiddenRegionReplacer.getRegion())
                return null;
        } else
            return null;
    }
    IHiddenRegionFormatting mergedFormatting = merger.merge(formattings);
    if (mergedFormatting != null)
        return formatter.createHiddenRegionReplacer(region, mergedFormatting);
    return null;
}
Also used : IHiddenRegionFormatting(org.eclipse.xtext.formatting2.IHiddenRegionFormatting) ITextReplacer(org.eclipse.xtext.formatting2.ITextReplacer) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 20 with IHiddenRegion

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

the class HiddenRegionPartAssociator method associate.

@Override
public void associate(IHiddenRegion region, BiConsumer<IHiddenRegionPart, HiddenRegionPartAssociation> handler) {
    List<IHiddenRegionPart> parts = region.getParts();
    if (!region.isMultiline()) {
        // rather than one of the surrounding semantic tokens.
        for (IHiddenRegionPart p : parts) {
            handler.accept(p, HiddenRegionPartAssociation.CONTAINER);
        }
    } else {
        int i = 0;
        if (region.getPreviousSemanticRegion() != null) {
            // collect whitespace and comments from the same line as belonging to the PREVIOUS semantic token
            while (i < parts.size()) {
                IHiddenRegionPart part = parts.get(i);
                if (part.isMultiline()) {
                    if (part.getText().endsWith("\n")) {
                        handler.accept(part, HiddenRegionPartAssociation.PREVIOUS);
                        i++;
                    }
                    break;
                } else {
                    handler.accept(part, HiddenRegionPartAssociation.PREVIOUS);
                    i++;
                }
            }
        }
        int j = parts.size() - 1;
        if (region.getNextSemanticRegion() != null) {
            // associated with the NEXT semantic token.
            while (j >= i) {
                IHiddenRegionPart part = parts.get(j);
                if (part instanceof IWhitespace && part.getLineCount() > 2) {
                    break;
                } else {
                    handler.accept(part, HiddenRegionPartAssociation.NEXT);
                    j--;
                }
            }
        }
        // Associate the remaining tokens with the CONTAINER
        for (int k = i; k <= j; k++) {
            IHiddenRegionPart part = parts.get(k);
            handler.accept(part, HiddenRegionPartAssociation.CONTAINER);
        }
    }
}
Also used : IHiddenRegionPart(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegionPart) IWhitespace(org.eclipse.xtext.formatting2.regionaccess.IWhitespace)

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