Search in sources :

Example 1 with FormattingNotApplicableException

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();
}
Also used : IHiddenRegionFormatting(org.eclipse.xtext.formatting2.IHiddenRegionFormatting) FormattingNotApplicableException(org.eclipse.xtext.formatting2.FormattingNotApplicableException)

Example 2 with 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;
}
Also used : ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) FormattingNotApplicableException(org.eclipse.xtext.formatting2.FormattingNotApplicableException) ITextReplacerContext(org.eclipse.xtext.formatting2.ITextReplacerContext)

Example 3 with FormattingNotApplicableException

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();
}
Also used : ITextReplacer(org.eclipse.xtext.formatting2.ITextReplacer) ISubFormatter(org.eclipse.xtext.formatting2.ISubFormatter) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment) FormattingNotApplicableException(org.eclipse.xtext.formatting2.FormattingNotApplicableException) ITextReplacerContext(org.eclipse.xtext.formatting2.ITextReplacerContext)

Aggregations

FormattingNotApplicableException (org.eclipse.xtext.formatting2.FormattingNotApplicableException)3 ITextReplacerContext (org.eclipse.xtext.formatting2.ITextReplacerContext)2 IHiddenRegionFormatting (org.eclipse.xtext.formatting2.IHiddenRegionFormatting)1 ISubFormatter (org.eclipse.xtext.formatting2.ISubFormatter)1 ITextReplacer (org.eclipse.xtext.formatting2.ITextReplacer)1 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)1 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)1