blob: 60e431f6d9422af910623de2240fef4c5171b99d [file] [log] [blame]
/**
********************************************************************************
* Copyright (c) 2018-2021 Robert Bosch GmbH and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Robert Bosch GmbH - initial API and implementation
********************************************************************************
*/
package app4mc.example.transform.m2t.transformers
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.transformers.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
}
}