| /** |
| ******************************************************************************** |
| * 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.Arrays; |
| import java.util.List; |
| |
| import org.eclipse.app4mc.amalthea.model.ActivityGraphItem; |
| import org.eclipse.app4mc.amalthea.model.ChannelReceive; |
| import org.eclipse.app4mc.amalthea.model.ChannelSend; |
| import org.eclipse.app4mc.amalthea.model.LabelAccess; |
| import org.eclipse.app4mc.amalthea.model.RunnableCall; |
| import org.eclipse.app4mc.amalthea.model.Ticks; |
| import org.eclipse.app4mc.slg.commons.m2t.generators.TicksTranslationUnit; |
| import org.eclipse.app4mc.slg.commons.m2t.generators.TranslationUnit; |
| import org.eclipse.app4mc.slg.commons.m2t.transformers.SLGBaseTransformer; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| import com.google.inject.Inject; |
| import com.google.inject.Singleton; |
| |
| @Singleton |
| public class ActivityGraphItemTransformer extends SLGBaseTransformer { |
| private static final String UNSUPPORTED_ELEMENT = "Unsupported element inside ActivityGraph : {}"; |
| |
| private static final Logger LOG = LoggerFactory.getLogger(ActivityGraphItemTransformer.class); |
| |
| @Inject private RunnableTransformer runnableTransformer; |
| @Inject private LabelAccessTransformer labelAccessTransformer; |
| @Inject private TicksTransformer ticksTransformer; |
| |
| protected TranslationUnit _transform(final ActivityGraphItem activityGraphItem) { |
| ActivityGraphItemTransformer.LOG.error(UNSUPPORTED_ELEMENT, activityGraphItem.getClass().getName()); |
| return new TranslationUnit("undefined", "", "", ""); |
| } |
| |
| protected TranslationUnit _transform(final RunnableCall runnableCall) { |
| return this.runnableTransformer.transform(runnableCall.getRunnable()); |
| } |
| |
| protected TranslationUnit _transform(final Ticks ticks) { |
| return this.ticksTransformer.transform(ticks); |
| } |
| |
| public List<TicksTranslationUnit> transformAllItems(final Ticks ticks) { |
| return this.ticksTransformer.transformAllItems(ticks); |
| } |
| |
| protected TranslationUnit _transform(final LabelAccess labelAccess) { |
| return this.labelAccessTransformer.transform(labelAccess); |
| } |
| |
| protected TranslationUnit _transform(final ChannelReceive channelReceive) { |
| ActivityGraphItemTransformer.LOG.error(UNSUPPORTED_ELEMENT, channelReceive.getClass().getName()); |
| return new TranslationUnit("undefined", "", "", ""); |
| } |
| |
| protected TranslationUnit _transform(final ChannelSend channelSend) { |
| ActivityGraphItemTransformer.LOG.error(UNSUPPORTED_ELEMENT, channelSend.getClass().getName()); |
| return new TranslationUnit("undefined", "", "", ""); |
| } |
| |
| public TranslationUnit transform(final ActivityGraphItem channelReceive) { |
| if (channelReceive instanceof ChannelReceive) { |
| return _transform((ChannelReceive) channelReceive); |
| } else if (channelReceive instanceof ChannelSend) { |
| return _transform((ChannelSend) channelReceive); |
| } else if (channelReceive instanceof LabelAccess) { |
| return _transform((LabelAccess) channelReceive); |
| } else if (channelReceive instanceof Ticks) { |
| return _transform((Ticks) channelReceive); |
| } else if (channelReceive instanceof RunnableCall) { |
| return _transform((RunnableCall) channelReceive); |
| } else if (channelReceive != null) { |
| return _transform(channelReceive); |
| } else { |
| throw new IllegalArgumentException( |
| "Unhandled parameter types: " + Arrays.<Object>asList(channelReceive).toString()); |
| } |
| } |
| |
| } |