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;
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations