blob: e69bb0aae05f24b67fc5c652bc2319982e64fd52 [file] [log] [blame]
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Florian Pirchner - Initial implementation
*/
/*
* generated by Xtext
*/
package org.eclipse.osbp.dsl.dto.xtext.formatting;
import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.formatting.impl.FormattingConfig;
import org.eclipse.osbp.dsl.common.xtext.formatting.CommonGrammarFormatter;
import org.eclipse.osbp.dsl.dto.xtext.services.DtoGrammarGrammarAccess;
/**
* This class contains custom formatting description.
*
* see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#formatting
* on how and when to use it
*
* Also see org.eclipse.xtext.xtext.XtextFormattingTokenSerializer as an
* example
*/
public class DtoGrammarFormatter extends CommonGrammarFormatter {
@Override
protected void configureFormatting(FormattingConfig c) {
configure(c, (DtoGrammarGrammarAccess) getGrammarAccess());
}
public void configure(FormattingConfig c, DtoGrammarGrammarAccess ga) {
DtoGrammarGrammarAccess f = (DtoGrammarGrammarAccess) getGrammarAccess();
super.configure(c, ga.getCommonGrammarGrammarAccess());
configureClassDef(c, f.getClassAccess());
configureDtoFeature(c, f.getDtoFeatureAccess());
configureDtoMapper(c, f.getDtoMapperAccess());
configureLimitedMapperDtoMapper(c, f.getLimitedMapperDtoMapperAccess());
c.setLinewrap(0, 1, 2).before(f.getSL_COMMENTRule());
c.setLinewrap(0, 1, 2).after(f.getSL_COMMENTRule());
c.setLinewrap(0, 1, 2).before(f.getML_COMMENTRule());
c.setLinewrap(1, 1, 1).after(f.getML_COMMENTRule());
for (Keyword kw : ga.findKeywords("@")) {
c.setNoSpace().after(kw);
}
for (Keyword kw : ga.findKeywords("(")) {
c.setNoSpace().after(kw);
}
for (Keyword kw : ga.findKeywords("(")) {
c.setNoSpace().before(kw);
}
for (Keyword kw : ga.findKeywords(")")) {
c.setNoSpace().before(kw);
}
for (Keyword kw : ga.findKeywords(";")) {
c.setNoSpace().before(kw);
}
for (Keyword kw : ga.findKeywords(",")) {
c.setNoSpace().before(kw);
}
}
protected void configureClassDef(FormattingConfig c,
DtoGrammarGrammarAccess.ClassElements ele) {
c.setLinewrap().around(ele.getAnnotationsAssignment_1());
c.setLinewrap().around(ele.getRule());
// c.setIndentationIncrement().after(
// ele.getLeftCurlyBracketKeyword_2_0_6());
// c.setIndentationDecrement().before(
// ele.getRightCurlyBracketKeyword_2_0_8());
c.setLinewrap(2).after(ele.getRightCurlyBracketKeyword_2_1_9());
}
protected void configureDtoFeature(FormattingConfig c,
DtoGrammarGrammarAccess.DtoFeatureElements ele) {
c.setLinewrap().around(ele.getAnnotationsAssignment_1());
// Setting for ";"
c.setNoSpace().before(ele.getSemicolonKeyword_2_0_3_1());
c.setNoSpace().before(ele.getSemicolonKeyword_2_1_5_1());
c.setNoSpace().before(ele.getSemicolonKeyword_2_2_1_5());
c.setNoSpace().before(ele.getSemicolonKeyword_2_1_5_1());
c.setNoSpace().before(ele.getSemicolonKeyword_2_5_7());
c.setNoSpace().before(ele.getSemicolonKeyword_2_6_2_1());
c.setNoSpace().before(ele.getSemicolonKeyword_2_7_7_1());
c.setLinewrap(1, 1, 2).around(ele.getRule());
c.setIndentationIncrement().before(ele.getRule());
c.setIndentationDecrement().after(ele.getRule());
}
protected void configureDtoMapper(FormattingConfig c,
DtoGrammarGrammarAccess.DtoMapperElements ele) {
c.setLinewrap(1, 1, 2).after(ele.getRule());
// Settings for "{" and "}"
c.setIndentationIncrement().after(ele.getLeftCurlyBracketKeyword_0());
c.setLinewrap().after(ele.getLeftCurlyBracketKeyword_0());
c.setLinewrap(1).before(ele.getRightCurlyBracketKeyword_4());
c.setIndentationDecrement().before(ele.getRightCurlyBracketKeyword_4());
c.setLinewrap(1, 1, 2).after(ele.getRightCurlyBracketKeyword_4());
}
protected void configureLimitedMapperDtoMapper(FormattingConfig c,
DtoGrammarGrammarAccess.LimitedMapperDtoMapperElements ele) {
c.setLinewrap(1, 1, 2).around(ele.getRule());
// Settings for "{" and "}"
c.setIndentationIncrement().after(ele.getLeftCurlyBracketKeyword_0());
c.setIndentationDecrement().before(ele.getRightCurlyBracketKeyword_3());
c.setLinewrap(2).after(ele.getRightCurlyBracketKeyword_3());
}
}