| /** |
| ******************************************************************************** |
| * Copyright (c) 2020-2021 Robert Bosch GmbH. |
| * |
| * 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 org.eclipse.app4mc.slg.ros2.transformers.sw; |
| |
| import java.util.ArrayList; |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.eclipse.app4mc.amalthea.model.Component; |
| import org.eclipse.app4mc.amalthea.model.Task; |
| import org.eclipse.app4mc.slg.commons.m2t.generators.TaskTranslationUnit; |
| import org.eclipse.app4mc.slg.commons.m2t.generators.TranslationUnit; |
| import org.eclipse.app4mc.slg.commons.m2t.transformers.sw.TaskTransformer; |
| import org.eclipse.app4mc.slg.ros2.generators.RosTaskTranslationUnit; |
| import org.eclipse.app4mc.slg.ros2.transformers.stimuli.RosInterProcessStimulusTransformer; |
| import org.eclipse.app4mc.transformation.util.OutputBuffer; |
| import org.eclipse.xtext.xbase.lib.CollectionLiterals; |
| |
| import com.google.inject.Inject; |
| import com.google.inject.Singleton; |
| |
| @Singleton |
| public class RosTaskTransformer extends TaskTransformer { |
| |
| @Inject private OutputBuffer outputBuffer; |
| @Inject private RosLabelTransformer rosTransformerLabel; |
| @Inject private RosRunnableTransformer rosTransformerRunnable; |
| @Inject private RosInterProcessStimulusTransformer ipStimulusTransformer; |
| |
| private final HashMap<ArrayList<?>, TaskTranslationUnit> cache = CollectionLiterals.newHashMap(); |
| |
| @Override |
| public TaskTranslationUnit transform(final Task task, final Component component) { |
| final ArrayList<?> key = CollectionLiterals.newArrayList(task, component); |
| final RosTaskTranslationUnit _result; |
| synchronized (cache) { |
| if (cache.containsKey(key)) { |
| return cache.get(key); |
| } |
| RosTaskTranslationUnit _rosTaskTranslationUnit = new RosTaskTranslationUnit(this.outputBuffer, |
| this.rosTransformerRunnable, this.rosTransformerLabel, this.ipStimulusTransformer, task, component); |
| _result = _rosTaskTranslationUnit; |
| cache.put(key, _result); |
| } |
| _init_transform(_result, task, component); |
| return _result; |
| } |
| |
| private void _init_transform(final RosTaskTranslationUnit it, final Task task, final Component component) { |
| } |
| |
| @Override |
| public Map<ArrayList<?>, ? extends TranslationUnit> getCache() { |
| return this.cache; |
| } |
| |
| } |