Search in sources :

Example 1 with ScopeModelElements

use of com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.ScopeModelElements in project dsl-devkit by dsldevkit.

the class ScopeFormatter method configureFormatting.

@Override
protected void configureFormatting(final FormattingConfig cfg) {
    final ScopeGrammarAccess g = (ScopeGrammarAccess) getGrammarAccess();
    cfg.setAutoLinewrap(MAX_LINE_LENGTH);
    // Comments
    cfg.setLinewrap(0, 1, 2).before(g.getSL_COMMENTRule());
    cfg.setLinewrap(0, 1, 2).before(g.getML_COMMENTRule());
    cfg.setLinewrap(0, 1, 1).after(g.getML_COMMENTRule());
    // general keywords
    for (final Pair<Keyword, Keyword> pair : g.findKeywordPairs("(", ")")) {
        cfg.setNoSpace().before(pair.getFirst());
        cfg.setNoSpace().after(pair.getFirst());
        cfg.setNoSpace().before(pair.getSecond());
    }
    for (final Pair<Keyword, Keyword> pair : g.findKeywordPairs("[", "]")) {
        cfg.setNoSpace().after(pair.getFirst());
        cfg.setNoSpace().before(pair.getSecond());
    }
    for (final Pair<Keyword, Keyword> pair : g.findKeywordPairs("{", "}")) {
        if (pair.getFirst() == g.getListLiteralAccess().getLeftCurlyBracketKeyword_1()) {
            continue;
        }
        cfg.setLinewrap().after(pair.getFirst());
        cfg.setIndentationIncrement().after(pair.getFirst());
        cfg.setLinewrap().before(pair.getSecond());
        cfg.setIndentationDecrement().before(pair.getSecond());
    }
    for (final Keyword delimiter : g.findKeywords(",")) {
        cfg.setNoSpace().before(delimiter);
    }
    for (final Keyword delimiter : g.findKeywords(";")) {
        cfg.setNoSpace().before(delimiter);
        cfg.setLinewrap().after(delimiter);
    }
    for (final Keyword delimiter : g.findKeywords("#", ".", "::")) {
        cfg.setNoSpace().around(delimiter);
    }
    // ScopeModel
    final ScopeModelElements sm = g.getScopeModelAccess();
    cfg.setLinewrap(2).between(sm.getNameAssignment_1(), sm.getImportsAssignment_3());
    cfg.setLinewrap(1).before(sm.getImportsAssignment_3());
    cfg.setLinewrap(2).between(sm.getImportsAssignment_3(), sm.getExtensionsAssignment_4());
    cfg.setLinewrap(1).before(sm.getExtensionsAssignment_4());
    cfg.setLinewrap(2).between(sm.getExtensionsAssignment_4(), sm.getInjectionsAssignment_5());
    cfg.setLinewrap(1).before(sm.getInjectionsAssignment_5());
    cfg.setLinewrap(2).before(sm.getNamingAssignment_6());
    cfg.setLinewrap(2).before(sm.getScopesAssignment_7());
    // ScopeDefinition
    final ScopeDefinitionElements sd = g.getScopeDefinitionAccess();
    cfg.setSpace(" ").before(sd.getLeftParenthesisKeyword_1_0());
    cfg.setLinewrap(1, 1, 2).before(sd.getRulesAssignment_4());
    // ScopeRule
    final ScopeRuleElements sr = g.getScopeRuleAccess();
    cfg.setIndentationIncrement().after(sr.getEqualsSignKeyword_2());
    cfg.setLinewrap(0, 0, 1).after(sr.getEqualsSignKeyword_2());
    cfg.setLinewrap(0, 0, 1).before(sr.getGreaterThanSignGreaterThanSignKeyword_4_0());
    cfg.setLinewrap(0, 0, 1).before(sr.getSemicolonKeyword_5());
    cfg.setIndentationDecrement().before(sr.getSemicolonKeyword_5());
    // NamedScopeExpression
    final NamedScopeExpressionElements nse = g.getNamedScopeExpressionAccess();
    cfg.setLinewrap(0, 0, 1).before(nse.getCaseDefCaseKeyword_1_0_0());
    cfg.setLinewrap(0, 0, 1).before(nse.getAsKeyword_2_0());
}
Also used : NamedScopeExpressionElements(com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.NamedScopeExpressionElements) ScopeGrammarAccess(com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess) Keyword(org.eclipse.xtext.Keyword) ScopeModelElements(com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.ScopeModelElements) ScopeDefinitionElements(com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.ScopeDefinitionElements) ScopeRuleElements(com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.ScopeRuleElements)

Aggregations

ScopeGrammarAccess (com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess)1 NamedScopeExpressionElements (com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.NamedScopeExpressionElements)1 ScopeDefinitionElements (com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.ScopeDefinitionElements)1 ScopeModelElements (com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.ScopeModelElements)1 ScopeRuleElements (com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.ScopeRuleElements)1 Keyword (org.eclipse.xtext.Keyword)1