Search in sources :

Example 1 with SinglelineDocCommentReplacer

use of org.eclipse.xtext.formatting2.internal.SinglelineDocCommentReplacer in project xtext-core by eclipse.

the class AbstractFormatter2 method createCommentReplacer.

public ITextReplacer createCommentReplacer(IComment comment) {
    EObject grammarElement = comment.getGrammarElement();
    if (grammarElement instanceof AbstractRule) {
        String ruleName = ((AbstractRule) grammarElement).getName();
        if (ruleName.startsWith("ML"))
            return new MultilineCommentReplacer(comment, '*');
        if (ruleName.startsWith("SL")) {
            if (comment.getLineRegions().get(0).getIndentation().getLength() > 0)
                return new SinglelineDocCommentReplacer(comment, "//");
            else
                return new SinglelineCodeCommentReplacer(comment, "//");
        }
    }
    String elementName = new GrammarElementTitleSwitch().showQualified().showRule().doSwitch(grammarElement);
    throw new IllegalStateException("No " + ITextReplacer.class.getSimpleName() + " configured for " + elementName);
}
Also used : GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) MultilineCommentReplacer(org.eclipse.xtext.formatting2.internal.MultilineCommentReplacer) EObject(org.eclipse.emf.ecore.EObject) SinglelineCodeCommentReplacer(org.eclipse.xtext.formatting2.internal.SinglelineCodeCommentReplacer) SinglelineDocCommentReplacer(org.eclipse.xtext.formatting2.internal.SinglelineDocCommentReplacer) AbstractRule(org.eclipse.xtext.AbstractRule)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)1 AbstractRule (org.eclipse.xtext.AbstractRule)1 MultilineCommentReplacer (org.eclipse.xtext.formatting2.internal.MultilineCommentReplacer)1 SinglelineCodeCommentReplacer (org.eclipse.xtext.formatting2.internal.SinglelineCodeCommentReplacer)1 SinglelineDocCommentReplacer (org.eclipse.xtext.formatting2.internal.SinglelineDocCommentReplacer)1 GrammarElementTitleSwitch (org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch)1