blob: df31d344a7832ee22b0bddcc11de5d9b5967dc27 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Robert Bosch GmbH.
* 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:
* Robert Bosch GmbH - initial API and implementation
*******************************************************************************/
package templates
import org.eclipse.app4mc.amalthea.model.Amalthea
import org.eclipse.app4mc.amalthea.model.RunnableCall
import org.eclipse.app4mc.amalthea.model.Task
import org.eclipse.app4mc.amalthea.model.util.ModelUtil
import org.eclipse.app4mc.amalthea.model.util.SoftwareUtil
import org.eclipse.app4mc.transformation.extensions.base.templates.AbstractTransformer
import org.osgi.service.component.annotations.Component
@Component(service=M2T_Output_Transformer)
class M2T_Output_Transformer extends AbstractTransformer {
/**
* Creates output with a "template only" style (like Xpand/Xtend).
*/
def String generateOutput1(Amalthea amalthea) '''
«var swModel=amalthea.swModel»
// generating info about tasks and runnables (in execution order)
«FOR task : swModel.tasks»
-----------------------------------------------
Task: «task.name»
«var graphEntries=task.activityGraph.items»
«FOR graphEntry: graphEntries»
«IF graphEntry instanceof RunnableCall»
Associated Runnable: «(graphEntry as RunnableCall).runnable.name»
«ENDIF»
«ENDFOR»
«ENDFOR»
-----------------------------------------------
'''
/**
* Creates output with a combination of template and functions.
* This allows a more flexible use of utility functions and lambdas.
*/
def String generateOutput2(Amalthea amalthea) '''
// generating info about tasks and runnables (in alphabetic order)
«FOR task : ModelUtil.getOrCreateSwModel(amalthea).tasks»
-----------------------------------------------
Task: «task.name»
«FOR name: runnableNamesOf(task)»
Associated Runnable: «name»
«ENDFOR»
«ENDFOR»
-----------------------------------------------
'''
def runnableNamesOf(Task task) {
SoftwareUtil.collectActivityGraphItems(task.activityGraph, null, [e | e instanceof RunnableCall])
.map[e | (e as RunnableCall).runnable.name]
.sort
}
}