| /** |
| ******************************************************************************** |
| * 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; |
| |
| import static org.eclipse.app4mc.slg.ros2.transformers.RosBaseSettings.INC_EXT; |
| import static org.eclipse.app4mc.slg.ros2.transformers.RosBaseSettings.INC_FOLDER; |
| import static org.eclipse.app4mc.slg.ros2.transformers.RosBaseSettings.INC_TYPE; |
| import static org.eclipse.app4mc.slg.ros2.transformers.RosBaseSettings.SRC_EXT; |
| import static org.eclipse.app4mc.slg.ros2.transformers.RosBaseSettings.SRC_FOLDER; |
| import static org.eclipse.app4mc.slg.ros2.transformers.RosBaseSettings.SRC_TYPE; |
| |
| import org.eclipse.app4mc.slg.commons.m2t.SLGTranslationUnit; |
| import org.eclipse.app4mc.transformation.util.OutputBuffer; |
| |
| import com.google.inject.Inject; |
| |
| public abstract class RosBaseTransformer { |
| |
| @Inject private OutputBuffer outputBuffer; |
| |
| // Buffer handling |
| |
| public boolean isIncFileEmpty(SLGTranslationUnit tu) { |
| return !outputBuffer.bufferExists(INC_TYPE, getIncModulePath(tu)); |
| } |
| |
| public boolean isSrcFileEmpty(SLGTranslationUnit tu) { |
| return !outputBuffer.bufferExists(SRC_TYPE, getSrcModulePath(tu)); |
| } |
| |
| public boolean incAppend(SLGTranslationUnit tu, String str) { |
| return outputBuffer.appendTo(INC_TYPE, getIncModulePath(tu), str); |
| } |
| |
| public boolean srcAppend(SLGTranslationUnit tu, String str) { |
| return outputBuffer.appendTo(SRC_TYPE, getSrcModulePath(tu), str); |
| } |
| |
| // Attributes derived from translation unit |
| |
| public String getIncModulePath(SLGTranslationUnit tu) { return tu.getModulePath() + INC_FOLDER + tu.getModuleName(); } |
| public String getSrcModulePath(SLGTranslationUnit tu) { return tu.getModulePath() + SRC_FOLDER + tu.getModuleName(); } |
| |
| public String getSrcFile(SLGTranslationUnit tu) { return tu.getModuleName() + SRC_EXT; } |
| public String getIncFile(SLGTranslationUnit tu) { return tu.getModuleName() + INC_EXT; } |
| |
| public String getSrcPath(SLGTranslationUnit tu) { return tu.getModulePath() + SRC_FOLDER + getSrcFile(tu); } |
| public String getIncPath(SLGTranslationUnit tu) { return tu.getModulePath() + INC_FOLDER + getIncFile(tu); } |
| |
| } |