Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 509b81d29bbe0aa46c145bc5a40f9b768b3a0da2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
 * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * CONTRIBUTORS:
 * 		Henrik Rentz-Reichert (initial contribution)
 */
package org.eclipse.etrice.generator.generic;

import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.etrice.core.fsm.fSM.AbstractInterfaceItem;
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.Port;
import org.eclipse.etrice.core.room.SAP;
import org.eclipse.etrice.core.room.SPP;
import org.eclipse.etrice.core.room.ServiceImplementation;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.generator.fsm.base.Indexed;
import org.eclipse.etrice.generator.fsm.generic.IIfItemIdGenerator;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
import org.eclipse.etrice.generator.generic.RoomExtensions;
import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.util.Tuples;
import org.eclipse.xtext.xbase.lib.Extension;

/**
 * Target language independent part of an actor class generator.
 * It uses the {@link ILanguageExtension}.
 */
@SuppressWarnings("all")
public class GenericActorClassGenerator implements IIfItemIdGenerator {
  @Inject
  @Extension
  protected RoomHelpers _roomHelpers;
  
  @Inject
  @Extension
  protected RoomExtensions _roomExtensions;
  
  @Inject
  protected ILanguageExtension langExt;
  
  /**
   * Generate constants for the local IDs of all interface items of an actor
   * class.
   * 
   * @param xpac an {@link ExpandedActorClass}
   * @return the generated code
   */
  public String genInterfaceItemConstants(final ExpandedActorClass xpac) {
    final ActorClass ac = xpac.getActorClass();
    List<Port> _xifexpression = null;
    boolean _usesInheritance = this.langExt.usesInheritance();
    if (_usesInheritance) {
      _xifexpression = this._roomHelpers.getEndPorts(ac);
    } else {
      _xifexpression = this._roomHelpers.getAllEndPorts(ac);
    }
    final List<Port> endPorts = _xifexpression;
    List<SAP> _xifexpression_1 = null;
    boolean _usesInheritance_1 = this.langExt.usesInheritance();
    if (_usesInheritance_1) {
      _xifexpression_1 = ac.getServiceAccessPoints();
    } else {
      _xifexpression_1 = this._roomHelpers.getAllSAPs(ac);
    }
    final List<SAP> strSAPs = _xifexpression_1;
    List<ServiceImplementation> _xifexpression_2 = null;
    boolean _usesInheritance_2 = this.langExt.usesInheritance();
    if (_usesInheritance_2) {
      _xifexpression_2 = ac.getServiceImplementations();
    } else {
      _xifexpression_2 = this._roomHelpers.getAllServiceImplementations(ac);
    }
    final List<ServiceImplementation> svcImpls = _xifexpression_2;
    final ArrayList<Pair<String, String>> list = new ArrayList<Pair<String, String>>();
    for (final Port ep : endPorts) {
      String _ifItemId = this.getIfItemId(ep);
      int _interfaceItemLocalId = xpac.getInterfaceItemLocalId(ep);
      int _plus = (1 + _interfaceItemLocalId);
      String _string = Integer.valueOf(_plus).toString();
      Pair<String, String> _pair = Tuples.<String, String>pair(_ifItemId, _string);
      list.add(_pair);
    }
    for (final SAP sap : strSAPs) {
      String _ifItemId_1 = this.getIfItemId(sap);
      int _interfaceItemLocalId_1 = xpac.getInterfaceItemLocalId(sap);
      int _plus_1 = (1 + _interfaceItemLocalId_1);
      String _string_1 = Integer.valueOf(_plus_1).toString();
      Pair<String, String> _pair_1 = Tuples.<String, String>pair(_ifItemId_1, _string_1);
      list.add(_pair_1);
    }
    for (final ServiceImplementation svc : svcImpls) {
      SPP _spp = svc.getSpp();
      String _ifItemId_2 = this.getIfItemId(_spp);
      SPP _spp_1 = svc.getSpp();
      int _interfaceItemLocalId_2 = xpac.getInterfaceItemLocalId(_spp_1);
      int _plus_2 = (1 + _interfaceItemLocalId_2);
      String _string_2 = Integer.valueOf(_plus_2).toString();
      Pair<String, String> _pair_2 = Tuples.<String, String>pair(_ifItemId_2, _string_2);
      list.add(_pair_2);
    }
    return this.langExt.genEnumeration("interface_items", list);
  }
  
  public String genInterfaceItemConstantsForOptionalActor(final ActorClass ac) {
    final List<Port> ports = this._roomHelpers.getAllInterfacePorts(ac);
    final ArrayList<Pair<String, String>> list = new ArrayList<Pair<String, String>>();
    Iterable<Indexed<Port>> _indexed = Indexed.<Port>indexed(ports);
    for (final Indexed<Port> ep : _indexed) {
      Port _value = ep.getValue();
      String _ifItemId = this.getIfItemId(_value);
      int _index1 = ep.getIndex1();
      String _string = Integer.valueOf(_index1).toString();
      Pair<String, String> _pair = Tuples.<String, String>pair(_ifItemId, _string);
      list.add(_pair);
    }
    return this.langExt.genEnumeration("interface_items", list);
  }
  
  @Override
  public String getIfItemId(final AbstractInterfaceItem item) {
    String _name = item.getName();
    return ("IFITEM_" + _name);
  }
}

Back to the top