aboutsummaryrefslogtreecommitdiffstats
path: root/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.java
blob: 8a9aa8d3507759a77756a3f51f2ed78dd90b0732 (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
package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph;

import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.Graph;
import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic;
import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.function.Consumer;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtend.lib.annotations.AccessorType;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
import org.eclipse.xtext.xbase.lib.Pure;

@SuppressWarnings("all")
public class EMFGraph extends Graph {
  @Accessors(AccessorType.PUBLIC_GETTER)
  private EObject root;
  
  public void init(final EObject root, final List<Metric> metrics, final String name, final List<EReference> referenceTypes) {
    final List<EObject> otherContents = IteratorExtensions.<EObject>toList(root.eAllContents());
    this.root = root;
    otherContents.add(root);
    this.init(otherContents, metrics, name, referenceTypes);
  }
  
  /**
   * init the graph with all nodes and reference types in the meta model
   * @param objects: objects in the instance model (exclude root)
   * @param metrics: metrics to be evaluated
   * @param name: name of the instance model
   * @param ReferenceTypes: reference types defined in the meta model
   */
  public void init(final List<EObject> objects, final List<Metric> metrics, final String name, final List<EReference> referenceTypes) {
    final Consumer<EObject> _function = (EObject it) -> {
      HashSet<String> types = new HashSet<String>();
      types.add(it.eClass().getName());
      this.statistic.addNodeWithAllTypes(it, types);
    };
    objects.forEach(_function);
    final Consumer<EReference> _function_1 = (EReference it) -> {
      boolean _isDerived = it.isDerived();
      boolean _not = (!_isDerived);
      if (_not) {
        this.statistic.addEdgeType(it.getName());
      }
    };
    referenceTypes.forEach(_function_1);
    final Consumer<EObject> _function_2 = (EObject source) -> {
      final Consumer<EReference> _function_3 = (EReference r) -> {
        boolean _isMany = r.isMany();
        if (_isMany) {
          final Consumer<EObject> _function_4 = (EObject target) -> {
            this.addEdge(source, target, r);
          };
          this.getNeighbours(source, r).forEach(_function_4);
        } else {
          Object _eGet = source.eGet(r);
          final EObject target = ((EObject) _eGet);
          this.addEdge(source, target, r);
        }
      };
      source.eClass().getEAllReferences().forEach(_function_3);
    };
    objects.forEach(_function_2);
    this.metrics = metrics;
    this.name = name;
  }
  
  public void removeReference(final EReference r) {
    boolean _containsEdgeType = this.statistic.containsEdgeType(r.getName());
    if (_containsEdgeType) {
      this.statistic.removeReference(r.getName(), r.isContainment());
    }
  }
  
  /**
   * Set basic information for the output
   */
  @Override
  public void setBasicInformation(final ArrayList<ArrayList<String>> output) {
    final ArrayList<String> metaInfo = new ArrayList<String>();
    metaInfo.add(Graph.META_MODEL_HEADER);
    metaInfo.add(this.metaModel);
    final ArrayList<String> edgeInfo = new ArrayList<String>();
    edgeInfo.add(Graph.NUM_EDGE_TYPE_HEADER);
    int _size = this.statistic.getAllTypes().size();
    String _plus = (Integer.valueOf(_size) + "");
    edgeInfo.add(_plus);
    final ArrayList<String> nodeInfo = new ArrayList<String>();
    nodeInfo.add(Graph.NUM_NODE_HEADER);
    int _size_1 = this.statistic.getAllNodes().size();
    String _plus_1 = (Integer.valueOf(_size_1) + "");
    nodeInfo.add(_plus_1);
    final ArrayList<String> stateInfo = new ArrayList<String>();
    stateInfo.add(Graph.STATE_ID_HEADER);
    stateInfo.add(this.name);
    output.add(metaInfo);
    output.add(edgeInfo);
    output.add(nodeInfo);
    output.add(stateInfo);
  }
  
  public EList<EObject> getNeighbours(final EObject o, final EReference r) {
    Object _eGet = o.eGet(r, true);
    return ((EList<EObject>) _eGet);
  }
  
  public void addEdge(final EObject source, final EObject target, final EReference r) {
    if ((((target != null) && (r != null)) && (!r.isDerived()))) {
      this.statistic.addEdge(source, target, r.getName());
    }
  }
  
  @Override
  public GraphStatistic getStatistic() {
    return this.statistic;
  }
  
  @Override
  public String getName() {
    return this.name;
  }
  
  public void setMetaModel(final String model) {
    this.metaModel = model;
  }
  
  public String getMetaModel() {
    return this.metaModel;
  }
  
  @Pure
  public EObject getRoot() {
    return this.root;
  }
}