blob: d957175777d42cf33e768942b404313a57d591f2 [file] [log] [blame]
/*
*
* Copyright (c) 2011, 2016 - 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:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*/
package org.eclipse.osbp.xtext.datamartdsl.formatting
import com.google.inject.Inject
import org.eclipse.osbp.utils.xtext.GenericFormatter
import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter
import org.eclipse.xtext.formatting.impl.FormattingConfig
import org.eclipse.xtext.xbase.services.XtypeGrammarAccess
import org.eclipse.xtext.ParserRule
import org.eclipse.xtext.GrammarUtil
//import org.eclipse.osbp.xtext.datamartdsl.services.DatamartDSLGrammarAccess
/**
* This class contains custom formatting description.
*
* see : http://www.eclipse.org/Xtext/documentation.html#formatting
* on how and when to use it
*
* Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example
*/
class DatamartDSLFormatter extends AbstractDeclarativeFormatter {
// @Inject extension DatamartDSLGrammarAccess
@Inject XtypeGrammarAccess grammarAccess
override protected void configureFormatting(FormattingConfig c) {
val genericFormatter = new GenericFormatter()
var ParserRule referenceDef = GrammarUtil.findRuleForName( grammar.grammar, "DatamartReference" ) as ParserRule
var ParserRule slicerDef = GrammarUtil.findRuleForName( grammar.grammar, "DatamartSlicer" ) as ParserRule
var ParserRule hierarchyDef = GrammarUtil.findRuleForName( grammar.grammar, "DatamartHierarchy" ) as ParserRule
var ParserRule measureDef = GrammarUtil.findRuleForName( grammar.grammar, "DatamartMeasure" ) as ParserRule
var ParserRule numOrElementDef = GrammarUtil.findRuleForName( grammar.grammar, "DatamartNumberOrElement" ) as ParserRule
var ParserRule conditionDef = GrammarUtil.findRuleForName( grammar.grammar, "DatamartCondition" ) as ParserRule
var ParserRule condExprDef = GrammarUtil.findRuleForName( grammar.grammar, "DatamartConditionalExpression" ) as ParserRule
// var ParserRule propertyDef = GrammarUtil.findRuleForName( grammar.grammar, "DatamartProperty" ) as ParserRule
// var ParserRule DerivedMeasureDef = GrammarUtil.findRuleForName( grammar.grammar, "DatamartDerivedMeasure" ) as ParserRule
// var ParserRule expressionDef = GrammarUtil.findRuleForName( grammar.grammar, "Expression" ) as ParserRule
// var ParserRule cubeElementDef = GrammarUtil.findRuleForName( grammar.grammar, "DatamartCubeElement" ) as ParserRule
// var ParserRule paramFuncDef = GrammarUtil.findRuleForName( grammar.grammar, "DatamartParameterFunction" ) as ParserRule
// dsl-specific formatting:
c.setNoLinewrap().before ( referenceDef )
// c.setNoLinewrap().before ( expressionDef )
c.setNoLinewrap().between( slicerDef , hierarchyDef )
// c.setNoLinewrap().between( conditionDef, propertyDef )
c.setNoLinewrap().between( conditionDef, condExprDef )
c.setNoLinewrap().between( hierarchyDef, measureDef )
c.setNoLinewrap().before ( numOrElementDef )
// common formatting:
genericFormatter.formatFirstLevelBlocks( c, grammar.grammar, "DatamartDefinition", "DatamartImport" )
genericFormatter.genericFormatting( c, grammar, grammarAccess )
}
}