use of org.eclipse.xtext.formatting2.FormattingNotApplicableException in project xtext-core by eclipse.
the class MaxLineWidthDocument method validate.
protected void validate(HiddenRegionReplacer replacer) throws FormattingNotApplicableException {
IHiddenRegionFormatting formatting = replacer.getFormatting();
Integer newLineMin = formatting.getNewLineMin();
if (newLineMin != null && newLineMin < 0)
throw new FormattingNotApplicableException();
}
use of org.eclipse.xtext.formatting2.FormattingNotApplicableException in project xtext-core by eclipse.
the class MaxLineWidthDocument method createReplacements.
@Override
public ITextReplacerContext createReplacements(ITextReplacerContext context) {
ITextReplacerContext last = super.createReplacements(context);
List<ITextReplacement> replacements = last.getReplacementsUntil(context);
String string = applyTextReplacements(replacements);
if (string.contains("\n"))
throw new FormattingNotApplicableException();
int leadingCharCount = context.getLeadingCharsInLineCount();
int formattedLength = string.length();
int lineLength = leadingCharCount + formattedLength;
if (lineLength > maxLineWidth)
throw new FormattingNotApplicableException();
return last;
}
use of org.eclipse.xtext.formatting2.FormattingNotApplicableException in project xtext-core by eclipse.
the class ConditionalReplacer method createReplacements.
@Override
public ITextReplacerContext createReplacements(ITextReplacerContext context) {
context.setNextReplacerIsChild();
for (ISubFormatter formatter : subFormatters) {
try {
ITextSegment region = getRegion();
SubDocument subDocument = new SubDocument(region, getDocument());
for (ITextReplacer replacer : replacers) subDocument.addReplacer(replacer);
formatter.format(subDocument);
ITextReplacerContext first = context.withReplacer(subDocument);
ITextReplacerContext last = subDocument.createReplacements(first);
return last;
} catch (FormattingNotApplicableException e) {
// no need to do anything.
// Try the next SubFormatter until one doens't throw a FormattingNotApplicableException
}
}
throw new FormattingNotApplicableException();
}
Aggregations