| /** |
| ******************************************************************************** |
| * 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 com.google.inject.Inject; |
| import java.util.ArrayList; |
| import java.util.HashMap; |
| import java.util.List; |
| import org.eclipse.app4mc.amalthea.model.Label; |
| import org.eclipse.app4mc.slg.commons.m2t.generators.LabelTranslationUnit; |
| import org.eclipse.app4mc.slg.commons.m2t.transformers.LabelTransformer; |
| import org.eclipse.app4mc.slg.ros2.generators.RosLabelTranslationUnit; |
| import org.eclipse.app4mc.transformation.util.OutputBuffer; |
| import org.eclipse.xtend2.lib.StringConcatenation; |
| import org.eclipse.xtext.xbase.lib.CollectionLiterals; |
| |
| public class RosLabelTransformer extends LabelTransformer { |
| @Inject |
| private OutputBuffer outputBuffer; |
| |
| private static final String LIB_NAME = "LABELS_LIB"; |
| |
| @Override |
| public LabelTranslationUnit transform(final Label label) { |
| final ArrayList<?> key = CollectionLiterals.newArrayList(label); |
| final RosLabelTranslationUnit _result; |
| synchronized (_createCache_transform) { |
| if (_createCache_transform.containsKey(key)) { |
| return _createCache_transform.get(key); |
| } |
| RosLabelTranslationUnit tu = new RosLabelTranslationUnit(this.outputBuffer, label); |
| _result = tu; |
| _createCache_transform.put(key, _result); |
| } |
| _init_transform(_result, label); |
| return _result; |
| } |
| |
| private final HashMap<ArrayList<?>, LabelTranslationUnit> _createCache_transform = CollectionLiterals.newHashMap(); |
| |
| private void _init_transform(final RosLabelTranslationUnit it, final Label label) { |
| } |
| |
| @Override |
| public HashMap<ArrayList<?>, LabelTranslationUnit> getCache() { |
| return this._createCache_transform; |
| } |
| |
| @Override |
| public boolean createCMake() { |
| return this.outputBuffer.appendTo("OTHER", RosLabelTranslationUnit.MAKEFILE_PATH, this.toCMake()); |
| } |
| |
| @Override |
| public String toCMake() { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("# "); |
| _builder.append(RosLabelTransformer.LIB_NAME); |
| _builder.append(" ################################################################"); |
| _builder.newLineIfNotEmpty(); |
| _builder.append("####"); |
| _builder.newLine(); |
| _builder.append("add_library("); |
| _builder.append(RosLabelTransformer.LIB_NAME); |
| _builder.append(" STATIC"); |
| _builder.newLineIfNotEmpty(); |
| { |
| List<String> _srcFiles = this.getSrcFiles(); |
| for (final String srcFile : _srcFiles) { |
| _builder.append("\t${CMAKE_CURRENT_LIST_DIR}/_src/"); |
| _builder.append(srcFile); |
| _builder.newLineIfNotEmpty(); |
| } |
| } |
| _builder.append(")"); |
| _builder.newLine(); |
| _builder.newLine(); |
| _builder.append("target_include_directories("); |
| _builder.append(RosLabelTransformer.LIB_NAME); |
| _builder.newLineIfNotEmpty(); |
| _builder.append("\t "); |
| _builder.append("PUBLIC ${CMAKE_CURRENT_LIST_DIR}/_inc"); |
| _builder.newLine(); |
| _builder.append(")\t"); |
| _builder.newLine(); |
| return _builder.toString(); |
| } |
| |
| } |