diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.java')
-rw-r--r-- | Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.java | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.java b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.java new file mode 100644 index 00000000..8a9aa8d3 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.java | |||
@@ -0,0 +1,140 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph; | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.Graph; | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic; | ||
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric; | ||
6 | import java.util.ArrayList; | ||
7 | import java.util.HashSet; | ||
8 | import java.util.List; | ||
9 | import java.util.function.Consumer; | ||
10 | import org.eclipse.emf.common.util.EList; | ||
11 | import org.eclipse.emf.ecore.EObject; | ||
12 | import org.eclipse.emf.ecore.EReference; | ||
13 | import org.eclipse.xtend.lib.annotations.AccessorType; | ||
14 | import org.eclipse.xtend.lib.annotations.Accessors; | ||
15 | import org.eclipse.xtext.xbase.lib.IteratorExtensions; | ||
16 | import org.eclipse.xtext.xbase.lib.Pure; | ||
17 | |||
18 | @SuppressWarnings("all") | ||
19 | public class EMFGraph extends Graph { | ||
20 | @Accessors(AccessorType.PUBLIC_GETTER) | ||
21 | private EObject root; | ||
22 | |||
23 | public void init(final EObject root, final List<Metric> metrics, final String name, final List<EReference> referenceTypes) { | ||
24 | final List<EObject> otherContents = IteratorExtensions.<EObject>toList(root.eAllContents()); | ||
25 | this.root = root; | ||
26 | otherContents.add(root); | ||
27 | this.init(otherContents, metrics, name, referenceTypes); | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * init the graph with all nodes and reference types in the meta model | ||
32 | * @param objects: objects in the instance model (exclude root) | ||
33 | * @param metrics: metrics to be evaluated | ||
34 | * @param name: name of the instance model | ||
35 | * @param ReferenceTypes: reference types defined in the meta model | ||
36 | */ | ||
37 | public void init(final List<EObject> objects, final List<Metric> metrics, final String name, final List<EReference> referenceTypes) { | ||
38 | final Consumer<EObject> _function = (EObject it) -> { | ||
39 | HashSet<String> types = new HashSet<String>(); | ||
40 | types.add(it.eClass().getName()); | ||
41 | this.statistic.addNodeWithAllTypes(it, types); | ||
42 | }; | ||
43 | objects.forEach(_function); | ||
44 | final Consumer<EReference> _function_1 = (EReference it) -> { | ||
45 | boolean _isDerived = it.isDerived(); | ||
46 | boolean _not = (!_isDerived); | ||
47 | if (_not) { | ||
48 | this.statistic.addEdgeType(it.getName()); | ||
49 | } | ||
50 | }; | ||
51 | referenceTypes.forEach(_function_1); | ||
52 | final Consumer<EObject> _function_2 = (EObject source) -> { | ||
53 | final Consumer<EReference> _function_3 = (EReference r) -> { | ||
54 | boolean _isMany = r.isMany(); | ||
55 | if (_isMany) { | ||
56 | final Consumer<EObject> _function_4 = (EObject target) -> { | ||
57 | this.addEdge(source, target, r); | ||
58 | }; | ||
59 | this.getNeighbours(source, r).forEach(_function_4); | ||
60 | } else { | ||
61 | Object _eGet = source.eGet(r); | ||
62 | final EObject target = ((EObject) _eGet); | ||
63 | this.addEdge(source, target, r); | ||
64 | } | ||
65 | }; | ||
66 | source.eClass().getEAllReferences().forEach(_function_3); | ||
67 | }; | ||
68 | objects.forEach(_function_2); | ||
69 | this.metrics = metrics; | ||
70 | this.name = name; | ||
71 | } | ||
72 | |||
73 | public void removeReference(final EReference r) { | ||
74 | boolean _containsEdgeType = this.statistic.containsEdgeType(r.getName()); | ||
75 | if (_containsEdgeType) { | ||
76 | this.statistic.removeReference(r.getName(), r.isContainment()); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * Set basic information for the output | ||
82 | */ | ||
83 | @Override | ||
84 | public void setBasicInformation(final ArrayList<ArrayList<String>> output) { | ||
85 | final ArrayList<String> metaInfo = new ArrayList<String>(); | ||
86 | metaInfo.add(Graph.META_MODEL_HEADER); | ||
87 | metaInfo.add(this.metaModel); | ||
88 | final ArrayList<String> edgeInfo = new ArrayList<String>(); | ||
89 | edgeInfo.add(Graph.NUM_EDGE_TYPE_HEADER); | ||
90 | int _size = this.statistic.getAllTypes().size(); | ||
91 | String _plus = (Integer.valueOf(_size) + ""); | ||
92 | edgeInfo.add(_plus); | ||
93 | final ArrayList<String> nodeInfo = new ArrayList<String>(); | ||
94 | nodeInfo.add(Graph.NUM_NODE_HEADER); | ||
95 | int _size_1 = this.statistic.getAllNodes().size(); | ||
96 | String _plus_1 = (Integer.valueOf(_size_1) + ""); | ||
97 | nodeInfo.add(_plus_1); | ||
98 | final ArrayList<String> stateInfo = new ArrayList<String>(); | ||
99 | stateInfo.add(Graph.STATE_ID_HEADER); | ||
100 | stateInfo.add(this.name); | ||
101 | output.add(metaInfo); | ||
102 | output.add(edgeInfo); | ||
103 | output.add(nodeInfo); | ||
104 | output.add(stateInfo); | ||
105 | } | ||
106 | |||
107 | public EList<EObject> getNeighbours(final EObject o, final EReference r) { | ||
108 | Object _eGet = o.eGet(r, true); | ||
109 | return ((EList<EObject>) _eGet); | ||
110 | } | ||
111 | |||
112 | public void addEdge(final EObject source, final EObject target, final EReference r) { | ||
113 | if ((((target != null) && (r != null)) && (!r.isDerived()))) { | ||
114 | this.statistic.addEdge(source, target, r.getName()); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | @Override | ||
119 | public GraphStatistic getStatistic() { | ||
120 | return this.statistic; | ||
121 | } | ||
122 | |||
123 | @Override | ||
124 | public String getName() { | ||
125 | return this.name; | ||
126 | } | ||
127 | |||
128 | public void setMetaModel(final String model) { | ||
129 | this.metaModel = model; | ||
130 | } | ||
131 | |||
132 | public String getMetaModel() { | ||
133 | return this.metaModel; | ||
134 | } | ||
135 | |||
136 | @Pure | ||
137 | public EObject getRoot() { | ||
138 | return this.root; | ||
139 | } | ||
140 | } | ||