blob: 17b31feb81eb1fb5a590f3363cfb99b5fc3f11b3 [file] [log] [blame]
/**
********************************************************************************
* Copyright (c) 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.commons.m2t.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.SLGBaseTransformer;
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 TaskTransformer extends SLGBaseTransformer {
@Inject private OutputBuffer outputBuffer;
@Inject private RunnableTransformer runnableTransformer;
@Inject private LabelTransformer labelTransformer;
public TaskTranslationUnit transform(final Task task, final Component component) {
final ArrayList<?> key = CollectionLiterals.newArrayList(task, component);
final TaskTranslationUnit _result;
synchronized (cache) {
if (cache.containsKey(key)) {
return cache.get(key);
}
TaskTranslationUnit _taskTranslationUnit = new TaskTranslationUnit(this.outputBuffer,
this.runnableTransformer, this.labelTransformer, task, component);
_result = _taskTranslationUnit;
cache.put(key, _result);
}
_init_transform(_result, task, component);
return _result;
}
private final HashMap<ArrayList<?>, TaskTranslationUnit> cache = CollectionLiterals.newHashMap();
private void _init_transform(final TaskTranslationUnit it, final Task task, final Component component) {
}
@Override
public Map<ArrayList<?>, ? extends TranslationUnit> getCache() {
return this.cache;
}
}