blob: e7a75a0f4026afc01c7a7d198c8d43b8f18d9642 [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 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*
* This copyright notice shows up in the generated Java code
*
*/
package org.eclipse.osbp.xtext.gridsource.generator
import com.google.inject.Inject
import java.io.StringWriter
import java.io.Writer
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.emf.ecore.xmi.XMLResource
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.xtext.generator.IGenerator
import org.eclipse.osbp.infogrid.model.gridsource.CxGridSource
import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropPriceStyle
import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropQuantityStyle
import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropStyle
import static extension org.eclipse.osbp.infogrid.model.gridsource.util.Util.*
/**
* Generates code from your model files on save.
*
* see http://www.eclipse.org/Xtext/documentation.html#TutorialCodeGeneration
*/
class GridSourceGenerator implements IGenerator {
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
resource.toBinary(fsa)
}
def toBinary(Resource input, IFileSystemAccess fsa) {
val XMLResource outputRes = new XMLResourceImpl
val CxGridSource lModel = input.contents.get(0) as CxGridSource
// set required inputs
lModel.rootTypeFQN = lModel.rootType.qualifiedName
for (inputDef : lModel.inputs) {
inputDef.inputTypeFQN = inputDef.inputType.qualifiedName
for (filter : inputDef.filters) {
filter.inputTypePropertyPath.dotPath = filter.inputTypePropertyPath.calcDotPath
filter.rootTypePropertyPath.dotPath = filter.rootTypePropertyPath.calcDotPath
}
}
// set required properties
for (prop : lModel.properties) {
prop.dotPath = prop.calcDotPath
// prepare dot path in styles
prop.style.prepare
}
val copy = EcoreUtil.copy(lModel)
outputRes.contents += copy
val Writer writer = new StringWriter
outputRes.save(writer, null)
fsa.generateFile(input.URI.lastSegment + ".gridsource_xmi", "xmi", writer.toString)
}
def dispatch void prepare(CxGridPropStyle style) {
}
def dispatch void prepare(CxGridPropPriceStyle style) {
style.valuePropertyDotPath = style.valuePropertyPath.calcDotPath
style.currencyPropertyDotPath = style.currencyPropertyPath.calcDotPath
}
def dispatch void prepare(CxGridPropQuantityStyle style) {
style.valuePropertyDotPath = style.valuePropertyPath.calcDotPath
style.uomPropertyDotPath = style.uomPropertyPath.calcDotPath
}
}