Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 06d1969642b7a125eebcbec03e3ccc45540508bf (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
package org.eclipse.etrice.generator.extensions;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.BaseState;
import org.eclipse.etrice.core.room.DetailCode;
import org.eclipse.etrice.core.room.ExternalPort;
import org.eclipse.etrice.core.room.Guard;
import org.eclipse.etrice.core.room.InitialTransition;
import org.eclipse.etrice.core.room.Message;
import org.eclipse.etrice.core.room.MessageHandler;
import org.eclipse.etrice.core.room.Port;
import org.eclipse.etrice.core.room.PortClass;
import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.RefableType;
import org.eclipse.etrice.core.room.RefinedState;
import org.eclipse.etrice.core.room.RoomClass;
import org.eclipse.etrice.core.room.RoomModel;
import org.eclipse.etrice.core.room.SAPRef;
import org.eclipse.etrice.core.room.SPPRef;
import org.eclipse.etrice.core.room.ServiceImplementation;
import org.eclipse.etrice.core.room.StandardOperation;
import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.StateMachine;
import org.eclipse.etrice.core.room.Transition;
import org.eclipse.etrice.core.room.Trigger;
import org.eclipse.etrice.core.room.TriggeredTransition;
import org.eclipse.etrice.core.room.VarDecl;
import org.eclipse.etrice.generator.etricegen.ActiveTrigger;
import org.eclipse.etrice.generator.etricegen.ExpandedActorClass;
import org.eclipse.etrice.generator.etricegen.TransitionChain;
import org.eclipse.etrice.generator.extensions.RoomNameProv;
import org.eclipse.xtext.xbase.lib.BooleanExtensions;
import org.eclipse.xtext.xbase.lib.ComparableExtensions;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IntegerExtensions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;

@SuppressWarnings("all")
@Singleton
public class RoomExtensions {
  @Inject
  private RoomNameProv nameProvider;
  
  public <T extends Object> List<T> union(final List<T> l1, final List<T> l2) {
      ArrayList<T> _arrayList = new ArrayList<T>();
      ArrayList<T> ret = _arrayList;
      ret.addAll(l1);
      ret.addAll(l2);
      return ret;
  }
  
  public List<Port> punion(final List<Port> in1, final List<ExternalPort> in2) {
      ArrayList<Port> _arrayList = new ArrayList<Port>();
      ArrayList<Port> ret = _arrayList;
      for (final ExternalPort ele : in2) {
        Port _ifport = ele.getIfport();
        ret.add(_ifport);
      }
      ret.addAll(in1);
      return ret;
  }
  
  public String getGenerationPathSegment() {
    return "/src-gen/";
  }
  
  public String getDocGenerationPathSegment() {
    return "/doc-gen/";
  }
  
  public String getModelPath(final EObject e) {
      Resource _eResource = e.eResource();
      Resource res = _eResource;
      boolean _operator_equals = ObjectExtensions.operator_equals(res, null);
      if (_operator_equals) {
        return "";
      } else {
        URI _uRI = res.getURI();
        String _fileString = _uRI.toFileString();
        return _fileString;
      }
  }
  
  public String getPackage(final RoomClass rc) {
    EObject _eContainer = rc.eContainer();
    String _name = ((RoomModel) _eContainer).getName();
    return _name;
  }
  
  public String getPathFromPackage(final String packageName) {
    String _replaceAll = packageName.replaceAll("\\.", "/");
    String _operator_plus = StringExtensions.operator_plus(_replaceAll, "/");
    return _operator_plus;
  }
  
  public String getPath(final RoomClass rc) {
    String _package = this.getPackage(rc);
    String _pathFromPackage = this.getPathFromPackage(_package);
    return _pathFromPackage;
  }
  
  public String getProjectPath(final EObject e) {
      Resource _eResource = e.eResource();
      Resource res = _eResource;
      boolean _operator_equals = ObjectExtensions.operator_equals(res, null);
      if (_operator_equals) {
        return "";
      } else {
        {
          File _file = new File("");
          File tmpf = _file;
          URI _uRI = res.getURI();
          String _fileString = _uRI.toFileString();
          File _file_1 = new File(_fileString);
          tmpf = _file_1;
          boolean _isFile = tmpf.isFile();
          boolean _operator_not = BooleanExtensions.operator_not(_isFile);
          if (_operator_not) {
            return "";
          }
          boolean isProject = false;
          Boolean _xdowhileexpression;
          do {
            {
              File _parentFile = tmpf.getParentFile();
              tmpf = _parentFile;
              String[] _list = tmpf.list();
              String[] contents = _list;
              for (final String f : contents) {
                boolean _equals = f.equals(".project");
                if (_equals) {
                  isProject = true;
                }
              }
            }
            boolean _operator_and = false;
            boolean _operator_not_1 = BooleanExtensions.operator_not(isProject);
            if (!_operator_not_1) {
              _operator_and = false;
            } else {
              File _parentFile_1 = tmpf.getParentFile();
              boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_parentFile_1, null);
              _operator_and = BooleanExtensions.operator_and(_operator_not_1, _operator_notEquals);
            }
            _xdowhileexpression = _operator_and;
          } while(_xdowhileexpression);
          String _absolutePath = tmpf.getAbsolutePath();
          return _absolutePath;
        }
      }
  }
  
  public String getGenerationTargetPath(final EObject e) {
    String _projectPath = this.getProjectPath(e);
    String _generationPathSegment = this.getGenerationPathSegment();
    String _operator_plus = StringExtensions.operator_plus(_projectPath, _generationPathSegment);
    return _operator_plus;
  }
  
  public String getDocGenerationTargetPath(final EObject e) {
    String _projectPath = this.getProjectPath(e);
    String _docGenerationPathSegment = this.getDocGenerationPathSegment();
    String _operator_plus = StringExtensions.operator_plus(_projectPath, _docGenerationPathSegment);
    return _operator_plus;
  }
  
  public List<Port> getEndPorts(final ActorClass ac) {
    EList<Port> _intPorts = ac.getIntPorts();
    EList<ExternalPort> _extPorts = ac.getExtPorts();
    List<Port> _punion = this.punion(_intPorts, _extPorts);
    return _punion;
  }
  
  public String getPathName(final String path) {
    String _replaceAll = path.replaceAll("/", "_");
    return _replaceAll;
  }
  
  public String getPortClassName(final ProtocolClass p, final boolean conj) {
      String _name = p.getName();
      String ret = _name;
      if (conj) {
        String _operator_plus = StringExtensions.operator_plus(ret, "ConjPort");
        ret = _operator_plus;
      } else {
        String _operator_plus_1 = StringExtensions.operator_plus(ret, "Port");
        ret = _operator_plus_1;
      }
      return ret;
  }
  
  public String getPortClassName(final Port p) {
      ProtocolClass _protocol = p.getProtocol();
      boolean _isConjugated = p.isConjugated();
      String _portClassName = this.getPortClassName(_protocol, _isConjugated);
      String ret = _portClassName;
      boolean _isReplicated = p.isReplicated();
      if (_isReplicated) {
        String _operator_plus = StringExtensions.operator_plus(ret, "Repl");
        ret = _operator_plus;
      }
      return ret;
  }
  
  public String getPortClassName(final ExternalPort p) {
    Port _ifport = p.getIfport();
    String _portClassName = this.getPortClassName(_ifport);
    return _portClassName;
  }
  
  public String getPortClassName(final SAPRef sap) {
    ProtocolClass _protocol = sap.getProtocol();
    String _portClassName = this.getPortClassName(_protocol, true);
    return _portClassName;
  }
  
  public String getPortClassName(final ServiceImplementation svc) {
    SPPRef _spp = svc.getSpp();
    ProtocolClass _protocol = _spp.getProtocol();
    String _portClassName = this.getPortClassName(_protocol, false);
    String _operator_plus = StringExtensions.operator_plus(_portClassName, "Repl");
    return _operator_plus;
  }
  
  public List<Message> getAllIncomingMessages(final ProtocolClass pc) {
    ProtocolClass _base = pc.getBase();
    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_base, null);
    if (_operator_notEquals) {
      ProtocolClass _base_1 = pc.getBase();
      List<Message> _allIncomingMessages = this.getAllIncomingMessages(_base_1);
      EList<Message> _incomingMessages = pc.getIncomingMessages();
      List<Message> _union = this.<Message>union(_allIncomingMessages, _incomingMessages);
      return _union;
    } else {
      EList<Message> _incomingMessages_1 = pc.getIncomingMessages();
      return _incomingMessages_1;
    }
  }
  
  public List<Message> getAllOutgoingMessages(final ProtocolClass pc) {
    EList<Message> _xifexpression = null;
    ProtocolClass _base = pc.getBase();
    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_base, null);
    if (_operator_notEquals) {
      ProtocolClass _base_1 = pc.getBase();
      List<Message> _allOutgoingMessages = this.getAllOutgoingMessages(_base_1);
      EList<Message> _outgoingMessages = pc.getOutgoingMessages();
      List<Message> _union = this.<Message>union(_allOutgoingMessages, _outgoingMessages);
      return _union;
    } else {
      EList<Message> _outgoingMessages_1 = pc.getOutgoingMessages();
      _xifexpression = _outgoingMessages_1;
    }
    return _xifexpression;
  }
  
  public List<Message> getIncoming(final ProtocolClass pc, final boolean conj) {
    if (conj) {
      List<Message> _allOutgoingMessages = this.getAllOutgoingMessages(pc);
      return _allOutgoingMessages;
    } else {
      List<Message> _allIncomingMessages = this.getAllIncomingMessages(pc);
      return _allIncomingMessages;
    }
  }
  
  public List<Message> getOutgoing(final ProtocolClass pc, final boolean conj) {
    if (conj) {
      List<Message> _allIncomingMessages = this.getAllIncomingMessages(pc);
      return _allIncomingMessages;
    } else {
      List<Message> _allOutgoingMessages = this.getAllOutgoingMessages(pc);
      return _allOutgoingMessages;
    }
  }
  
  public PortClass getPortClass(final ProtocolClass pc, final boolean conj) {
    if (conj) {
      PortClass _conjugate = pc.getConjugate();
      return _conjugate;
    } else {
      PortClass _regular = pc.getRegular();
      return _regular;
    }
  }
  
  public boolean handlesSend(final ProtocolClass pc, final boolean conj) {
      PortClass _portClass = this.getPortClass(pc, conj);
      boolean _operator_equals = ObjectExtensions.operator_equals(_portClass, null);
      if (_operator_equals) {
        return false;
      } else {
        PortClass _portClass_1 = this.getPortClass(pc, conj);
        EList<MessageHandler> _msgHandlers = _portClass_1.getMsgHandlers();
        for (final MessageHandler hdlr : _msgHandlers) {
          List<Message> _outgoing = this.getOutgoing(pc, conj);
          Message _msg = hdlr.getMsg();
          boolean _contains = _outgoing.contains(_msg);
          if (_contains) {
            return true;
          }
        }
      }
      return false;
  }
  
  public boolean handlesReceive(final ProtocolClass pc, final boolean conj) {
      PortClass _portClass = this.getPortClass(pc, conj);
      boolean _operator_equals = ObjectExtensions.operator_equals(_portClass, null);
      if (_operator_equals) {
        return false;
      } else {
        PortClass _portClass_1 = this.getPortClass(pc, conj);
        EList<MessageHandler> _msgHandlers = _portClass_1.getMsgHandlers();
        for (final MessageHandler hdlr : _msgHandlers) {
          List<Message> _incoming = this.getIncoming(pc, conj);
          Message _msg = hdlr.getMsg();
          boolean _contains = _incoming.contains(_msg);
          if (_contains) {
            return true;
          }
        }
      }
      return false;
  }
  
  public List<MessageHandler> getReceiveHandlers(final ProtocolClass pc, final boolean conj) {
    PortClass _portClass = this.getPortClass(pc, conj);
    boolean _operator_equals = ObjectExtensions.operator_equals(_portClass, null);
    if (_operator_equals) {
      ArrayList<MessageHandler> _arrayList = new ArrayList<MessageHandler>();
      return _arrayList;
    } else {
      {
        ArrayList<MessageHandler> _arrayList_1 = new ArrayList<MessageHandler>();
        ArrayList<MessageHandler> res = _arrayList_1;
        PortClass _portClass_1 = this.getPortClass(pc, conj);
        EList<MessageHandler> _msgHandlers = _portClass_1.getMsgHandlers();
        for (final MessageHandler hdlr : _msgHandlers) {
          List<Message> _incoming = this.getIncoming(pc, conj);
          Message _msg = hdlr.getMsg();
          boolean _contains = _incoming.contains(_msg);
          if (_contains) {
            res.add(hdlr);
          }
        }
        return res;
      }
    }
  }
  
  public List<MessageHandler> getSendHandlers(final ProtocolClass pc, final boolean conj) {
    PortClass _portClass = this.getPortClass(pc, conj);
    boolean _operator_equals = ObjectExtensions.operator_equals(_portClass, null);
    if (_operator_equals) {
      ArrayList<MessageHandler> _arrayList = new ArrayList<MessageHandler>();
      return _arrayList;
    } else {
      {
        ArrayList<MessageHandler> _arrayList_1 = new ArrayList<MessageHandler>();
        ArrayList<MessageHandler> res = _arrayList_1;
        PortClass _portClass_1 = this.getPortClass(pc, conj);
        EList<MessageHandler> _msgHandlers = _portClass_1.getMsgHandlers();
        for (final MessageHandler hdlr : _msgHandlers) {
          List<Message> _outgoing = this.getOutgoing(pc, conj);
          Message _msg = hdlr.getMsg();
          boolean _contains = _outgoing.contains(_msg);
          if (_contains) {
            res.add(hdlr);
          }
        }
        return res;
      }
    }
  }
  
  public MessageHandler getSendHandler(final Message m, final boolean conj) {
    EObject _eContainer = m.eContainer();
    List<MessageHandler> _sendHandlers = this.getSendHandlers(((ProtocolClass) _eContainer), conj);
    final Function1<MessageHandler,Boolean> _function = new Function1<MessageHandler,Boolean>() {
        public Boolean apply(final MessageHandler e) {
          Message _msg = e.getMsg();
          boolean _operator_equals = ObjectExtensions.operator_equals(_msg, m);
          return ((Boolean)_operator_equals);
        }
      };
    MessageHandler _findFirst = IterableExtensions.<MessageHandler>findFirst(_sendHandlers, _function);
    return _findFirst;
  }
  
  public boolean isIncoming(final Message m) {
    EObject _eContainer = m.eContainer();
    List<Message> _allIncomingMessages = this.getAllIncomingMessages(((ProtocolClass) _eContainer));
    boolean _contains = _allIncomingMessages.contains(m);
    return _contains;
  }
  
  public String getCodeName(final Message m) {
    boolean _isIncoming = this.isIncoming(m);
    if (_isIncoming) {
      String _name = m.getName();
      String _operator_plus = StringExtensions.operator_plus("IN_", _name);
      return _operator_plus;
    } else {
      String _name_1 = m.getName();
      String _operator_plus_1 = StringExtensions.operator_plus("OUT_", _name_1);
      return _operator_plus_1;
    }
  }
  
  public boolean isLeaf(final State s) {
    StateGraph _subgraph = s.getSubgraph();
    boolean _operator_equals = ObjectExtensions.operator_equals(_subgraph, null);
    return _operator_equals;
  }
  
  public List<State> getLeafStateList(final StateGraph sg) {
      ArrayList<State> _arrayList = new ArrayList<State>();
      ArrayList<State> res = _arrayList;
      EList<State> _states = sg.getStates();
      for (final State s : _states) {
        List<State> _leafStateList = this.getLeafStateList(s);
        res.addAll(_leafStateList);
      }
      return res;
  }
  
  public List<State> getLeafStateList(final State s) {
    boolean _isLeaf = this.isLeaf(s);
    if (_isLeaf) {
      {
        ArrayList<State> _arrayList = new ArrayList<State>();
        ArrayList<State> res = _arrayList;
        res.add(s);
        return res;
      }
    } else {
      StateGraph _subgraph = s.getSubgraph();
      List<State> _leafStateList = this.getLeafStateList(_subgraph);
      return _leafStateList;
    }
  }
  
  public List<State> getStateList(final StateGraph sg) {
      ArrayList<State> _arrayList = new ArrayList<State>();
      ArrayList<State> ret = _arrayList;
      EList<State> _states = sg.getStates();
      for (final State e : _states) {
        {
          ret.add(e);
          StateGraph _subgraph = e.getSubgraph();
          StateGraph tmp = _subgraph;
          boolean _operator_notEquals = ObjectExtensions.operator_notEquals(tmp, null);
          if (_operator_notEquals) {
            StateGraph _subgraph_1 = e.getSubgraph();
            List<State> _stateList = this.getStateList(_subgraph_1);
            ret.addAll(_stateList);
          }
        }
      }
      return ret;
  }
  
  public List<State> getBaseStateList(final StateGraph sg) {
      ArrayList<State> _arrayList = new ArrayList<State>();
      ArrayList<State> ret = _arrayList;
      List<State> _stateList = this.getStateList(sg);
      for (final State e : _stateList) {
        if ((e instanceof BaseState)) {
          ret.add(e);
        }
      }
      return ret;
  }
  
  public List<State> getAllBaseStates(final ActorClass ac) {
    List<State> _xifexpression = null;
    ActorClass _base = ac.getBase();
    boolean _operator_equals = ObjectExtensions.operator_equals(_base, null);
    if (_operator_equals) {
      StateMachine _stateMachine = ac.getStateMachine();
      List<State> _baseStateList = this.getBaseStateList(_stateMachine);
      return _baseStateList;
    } else {
      ActorClass _base_1 = ac.getBase();
      List<State> _allBaseStates = this.getAllBaseStates(_base_1);
      StateMachine _stateMachine_1 = ac.getStateMachine();
      List<State> _baseStateList_1 = this.getBaseStateList(_stateMachine_1);
      List<State> _union = this.<State>union(_allBaseStates, _baseStateList_1);
      _xifexpression = _union;
    }
    return _xifexpression;
  }
  
  public boolean overridesStop(final ActorClass ac) {
    boolean _operator_or = false;
    EList<StandardOperation> _operations = ac.getOperations();
    final Function1<StandardOperation,Boolean> _function = new Function1<StandardOperation,Boolean>() {
        public Boolean apply(final StandardOperation e) {
          boolean _operator_and = false;
          boolean _operator_and_1 = false;
          String _name = e.getName();
          boolean _operator_equals = ObjectExtensions.operator_equals(_name, "stop");
          if (!_operator_equals) {
            _operator_and_1 = false;
          } else {
            EList<VarDecl> _arguments = e.getArguments();
            boolean _isEmpty = _arguments.isEmpty();
            _operator_and_1 = BooleanExtensions.operator_and(_operator_equals, _isEmpty);
          }
          if (!_operator_and_1) {
            _operator_and = false;
          } else {
            RefableType _returntype = e.getReturntype();
            boolean _operator_equals_1 = ObjectExtensions.operator_equals(_returntype, null);
            _operator_and = BooleanExtensions.operator_and(_operator_and_1, _operator_equals_1);
          }
          return ((Boolean)_operator_and);
        }
      };
    boolean _exists = IterableExtensions.<StandardOperation>exists(_operations, _function);
    if (_exists) {
      _operator_or = true;
    } else {
      boolean _operator_and = false;
      ActorClass _base = ac.getBase();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_base, null);
      if (!_operator_notEquals) {
        _operator_and = false;
      } else {
        ActorClass _base_1 = ac.getBase();
        boolean _overridesStop = this.overridesStop(_base_1);
        _operator_and = BooleanExtensions.operator_and(_operator_notEquals, _overridesStop);
      }
      _operator_or = BooleanExtensions.operator_or(_exists, _operator_and);
    }
    return _operator_or;
  }
  
  public int getNumberOfInheritedStates(final ActorClass ac) {
    ActorClass _base = ac.getBase();
    boolean _operator_equals = ObjectExtensions.operator_equals(_base, null);
    if (_operator_equals) {
      return 0;
    } else {
      ActorClass _base_1 = ac.getBase();
      StateMachine _stateMachine = _base_1.getStateMachine();
      List<State> _stateList = this.getStateList(_stateMachine);
      int _size = _stateList.size();
      ActorClass _base_2 = ac.getBase();
      int _numberOfInheritedStates = this.getNumberOfInheritedStates(_base_2);
      int _operator_plus = IntegerExtensions.operator_plus(((Integer)_size), ((Integer)_numberOfInheritedStates));
      return _operator_plus;
    }
  }
  
  public int getNumberOfInheritedBaseStates(final ActorClass ac) {
    ActorClass _base = ac.getBase();
    boolean _operator_equals = ObjectExtensions.operator_equals(_base, null);
    if (_operator_equals) {
      return 0;
    } else {
      ActorClass _base_1 = ac.getBase();
      StateMachine _stateMachine = _base_1.getStateMachine();
      List<State> _baseStateList = this.getBaseStateList(_stateMachine);
      int _size = _baseStateList.size();
      ActorClass _base_2 = ac.getBase();
      int _numberOfInheritedBaseStates = this.getNumberOfInheritedBaseStates(_base_2);
      int _operator_plus = IntegerExtensions.operator_plus(((Integer)_size), ((Integer)_numberOfInheritedBaseStates));
      return _operator_plus;
    }
  }
  
  public String getStateId(final State s) {
    String _genStateId = RoomNameProv.getGenStateId(s);
    return _genStateId;
  }
  
  public String getStatePathName(final State s) {
    String _genStatePathName = RoomNameProv.getGenStatePathName(s);
    return _genStatePathName;
  }
  
  public String getChainId(final TransitionChain t) {
    String _genChainId = RoomNameProv.getGenChainId(t);
    return _genChainId;
  }
  
  public boolean hasGuard(final Trigger tr) {
    boolean _operator_and = false;
    boolean _operator_and_1 = false;
    Guard _guard = tr.getGuard();
    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_guard, null);
    if (!_operator_notEquals) {
      _operator_and_1 = false;
    } else {
      Guard _guard_1 = tr.getGuard();
      DetailCode _guard_2 = _guard_1.getGuard();
      boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_guard_2, null);
      _operator_and_1 = BooleanExtensions.operator_and(_operator_notEquals, _operator_notEquals_1);
    }
    if (!_operator_and_1) {
      _operator_and = false;
    } else {
      Guard _guard_3 = tr.getGuard();
      DetailCode _guard_4 = _guard_3.getGuard();
      EList<String> _commands = _guard_4.getCommands();
      int _size = _commands.size();
      boolean _operator_greaterThan = ComparableExtensions.<Integer>operator_greaterThan(((Integer)_size), ((Integer)0));
      _operator_and = BooleanExtensions.operator_and(_operator_and_1, _operator_greaterThan);
    }
    return _operator_and;
  }
  
  public boolean hasGuard(final ExpandedActorClass ac, final ActiveTrigger at) {
      boolean hasGuard = false;
      EList<TriggeredTransition> _transitions = at.getTransitions();
      for (final TriggeredTransition t : _transitions) {
        EList<Trigger> _triggers = t.getTriggers();
        final Function1<Trigger,Boolean> _function = new Function1<Trigger,Boolean>() {
            public Boolean apply(final Trigger e) {
              boolean _operator_and = false;
              String _trigger = at.getTrigger();
              boolean _isMatching = ac.isMatching(e, _trigger);
              if (!_isMatching) {
                _operator_and = false;
              } else {
                boolean _hasGuard = RoomExtensions.this.hasGuard(e);
                _operator_and = BooleanExtensions.operator_and(_isMatching, _hasGuard);
              }
              return ((Boolean)_operator_and);
            }
          };
        boolean _exists = IterableExtensions.<Trigger>exists(_triggers, _function);
        if (_exists) {
          hasGuard = true;
        }
      }
      return hasGuard;
  }
  
  public boolean hasEntryCode(final State s) {
    boolean _operator_and = false;
    DetailCode _entryCode = s.getEntryCode();
    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_entryCode, null);
    if (!_operator_notEquals) {
      _operator_and = false;
    } else {
      DetailCode _entryCode_1 = s.getEntryCode();
      EList<String> _commands = _entryCode_1.getCommands();
      int _size = _commands.size();
      boolean _operator_greaterThan = ComparableExtensions.<Integer>operator_greaterThan(((Integer)_size), ((Integer)0));
      _operator_and = BooleanExtensions.operator_and(_operator_notEquals, _operator_greaterThan);
    }
    return _operator_and;
  }
  
  public boolean hasExitCode(final State s) {
    boolean _operator_and = false;
    DetailCode _exitCode = s.getExitCode();
    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_exitCode, null);
    if (!_operator_notEquals) {
      _operator_and = false;
    } else {
      DetailCode _exitCode_1 = s.getExitCode();
      EList<String> _commands = _exitCode_1.getCommands();
      int _size = _commands.size();
      boolean _operator_greaterThan = ComparableExtensions.<Integer>operator_greaterThan(((Integer)_size), ((Integer)0));
      _operator_and = BooleanExtensions.operator_and(_operator_notEquals, _operator_greaterThan);
    }
    return _operator_and;
  }
  
  public String getEntryCode(final ExpandedActorClass ac, final State s) {
    if ((s instanceof RefinedState)) {
      String _entryCodeOperationName = RoomNameProv.getEntryCodeOperationName(s);
      String _operator_plus = StringExtensions.operator_plus("super.", _entryCodeOperationName);
      String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, "();\n");
      DetailCode _entryCode = s.getEntryCode();
      String _code = ac.getCode(_entryCode);
      String _operator_plus_2 = StringExtensions.operator_plus(_operator_plus_1, _code);
      return _operator_plus_2;
    } else {
      DetailCode _entryCode_1 = s.getEntryCode();
      String _code_1 = ac.getCode(_entryCode_1);
      return _code_1;
    }
  }
  
  public String getExitCode(final ExpandedActorClass ac, final State s) {
    String _xifexpression = null;
    if ((s instanceof RefinedState)) {
      DetailCode _exitCode = s.getExitCode();
      String _code = ac.getCode(_exitCode);
      String _operator_plus = StringExtensions.operator_plus(_code, "super.");
      String _entryCodeOperationName = RoomNameProv.getEntryCodeOperationName(s);
      String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, _entryCodeOperationName);
      String _operator_plus_2 = StringExtensions.operator_plus(_operator_plus_1, "();\n");
      return _operator_plus_2;
    } else {
      DetailCode _exitCode_1 = s.getExitCode();
      String _code_1 = ac.getCode(_exitCode_1);
      _xifexpression = _code_1;
    }
    return _xifexpression;
  }
  
  public boolean hasActionCode(final Transition t) {
    boolean _operator_and = false;
    DetailCode _action = t.getAction();
    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_action, null);
    if (!_operator_notEquals) {
      _operator_and = false;
    } else {
      DetailCode _action_1 = t.getAction();
      EList<String> _commands = _action_1.getCommands();
      int _size = _commands.size();
      boolean _operator_greaterThan = ComparableExtensions.<Integer>operator_greaterThan(((Integer)_size), ((Integer)0));
      _operator_and = BooleanExtensions.operator_and(_operator_notEquals, _operator_greaterThan);
    }
    return _operator_and;
  }
  
  public String getActionCode(final ExpandedActorClass ac, final Transition t) {
    DetailCode _action = t.getAction();
    String _code = ac.getCode(_action);
    return _code;
  }
  
  public String getContextId(final TransitionChain tc) {
    State _stateContext = tc.getStateContext();
    String _stateId = this.getStateId(_stateContext);
    return _stateId;
  }
  
  public Transition getInitTransition(final StateGraph sg) {
      EList<Transition> _transitions = sg.getTransitions();
      for (final Transition tr : _transitions) {
        if ((tr instanceof InitialTransition)) {
          return tr;
        }
      }
      return null;
  }
  
  public boolean hasInitTransition(final StateGraph sg) {
      EList<Transition> _transitions = sg.getTransitions();
      for (final Transition tr : _transitions) {
        if ((tr instanceof InitialTransition)) {
          return true;
        }
      }
      return false;
  }
  
  public List<Transition> getTransitionList(final State s) {
    boolean _isLeaf = this.isLeaf(s);
    if (_isLeaf) {
      ArrayList<Transition> _arrayList = new ArrayList<Transition>();
      return _arrayList;
    } else {
      StateGraph _subgraph = s.getSubgraph();
      List<Transition> _transitionList = this.getTransitionList(_subgraph);
      return _transitionList;
    }
  }
  
  public List<Transition> getTransitionList(final StateGraph sg) {
      EList<Transition> _transitions = sg.getTransitions();
      ArrayList<Transition> _arrayList = new ArrayList<Transition>(_transitions);
      ArrayList<Transition> res = _arrayList;
      EList<State> _states = sg.getStates();
      for (final State s : _states) {
        List<Transition> _transitionList = this.getTransitionList(s);
        res.addAll(_transitionList);
      }
      return res;
  }
}

Back to the top