Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c9983fc7ba3532cfa05a0fdb19a762eaae7474e6 (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
package org.eclipse.etrice.core.postprocessing;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.ETypedElement;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;

@SuppressWarnings("all")
public class PostprocessingHelpers {
  public static int UNBOUNDED_MULTIPLICITY = ETypedElement.UNBOUNDED_MULTIPLICITY;
  
  public static EClass getClass(final EPackage pckg, final String name) {
    EClassifier _eClassifier = pckg.getEClassifier(name);
    return ((EClass) _eClassifier);
  }
  
  public static EAttribute getAttribute(final EClass cls, final String name) {
    EList<EAttribute> _eAllAttributes = cls.getEAllAttributes();
    final Function1<EAttribute,Boolean> _function = new Function1<EAttribute,Boolean>() {
        public Boolean apply(final EAttribute a) {
          String _name = a.getName();
          boolean _equals = _name.equals(name);
          return Boolean.valueOf(_equals);
        }
      };
    EAttribute _findFirst = IterableExtensions.<EAttribute>findFirst(_eAllAttributes, _function);
    return _findFirst;
  }
  
  public static EReference getReference(final EClass cls, final String name) {
    EList<EReference> _eAllReferences = cls.getEAllReferences();
    final Function1<EReference,Boolean> _function = new Function1<EReference,Boolean>() {
        public Boolean apply(final EReference a) {
          String _name = a.getName();
          boolean _equals = _name.equals(name);
          return Boolean.valueOf(_equals);
        }
      };
    EReference _findFirst = IterableExtensions.<EReference>findFirst(_eAllReferences, _function);
    return _findFirst;
  }
  
  public static boolean addOperation(final EClass owner, final String name, final EClassifier type, final String body) {
    boolean _addOperation = PostprocessingHelpers.addOperation(owner, name, type, Integer.valueOf(1), body);
    return _addOperation;
  }
  
  public static boolean addOperation(final EClass owner, final String name, final EClassifier type, final Integer upperBound, final String body) {
    boolean _xblockexpression = false;
    {
      final EOperation op = EcoreFactory.eINSTANCE.createEOperation();
      op.setName(name);
      op.setEType(type);
      op.setUpperBound((upperBound).intValue());
      final EAnnotation anno = EcoreFactory.eINSTANCE.createEAnnotation();
      anno.setSource("http://www.eclipse.org/emf/2002/GenModel");
      EMap<String,String> _details = anno.getDetails();
      _details.put("body", body);
      EList<EAnnotation> _eAnnotations = op.getEAnnotations();
      _eAnnotations.add(anno);
      EList<EOperation> _eOperations = owner.getEOperations();
      boolean _add = _eOperations.add(op);
      _xblockexpression = (_add);
    }
    return _xblockexpression;
  }
}

Back to the top