diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.xtend')
-rw-r--r-- | Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.xtend | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.xtend new file mode 100644 index 00000000..5c161f4b --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.xtend | |||
@@ -0,0 +1,106 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | ||
4 | import java.util.ArrayList | ||
5 | import java.util.List | ||
6 | import org.eclipse.emf.common.util.EList | ||
7 | import org.eclipse.emf.ecore.EObject | ||
8 | import org.eclipse.emf.ecore.EReference | ||
9 | |||
10 | class EMFGraph extends Graph{ | ||
11 | def void init (EObject root, List<Metric> metrics, String name, List<String> referenceTypes){ | ||
12 | val otherContents = root.eAllContents.toList(); | ||
13 | otherContents.add(root); | ||
14 | init(otherContents, metrics, name, referenceTypes); | ||
15 | } | ||
16 | |||
17 | /** | ||
18 | * init the graph with all nodes and reference types in the meta model | ||
19 | * @param objects: objects in the instance model (exclude root) | ||
20 | * @param metrics: metrics to be evaluated | ||
21 | * @param name: name of the instance model | ||
22 | * @param ReferenceTypes: reference types defined in the meta model | ||
23 | */ | ||
24 | def void init(List<EObject> objects, List<Metric> metrics, String name, List<String> referenceTypes){ | ||
25 | objects.forEach[it| | ||
26 | statistic.addNode(it); | ||
27 | ] | ||
28 | |||
29 | referenceTypes.forEach[it| | ||
30 | statistic.addType(it); | ||
31 | ]; | ||
32 | |||
33 | objects.forEach[source| | ||
34 | source.eClass.EAllReferences.forEach[r| | ||
35 | //add the type first (if it is not added already) | ||
36 | //many references | ||
37 | if(r.isMany){ | ||
38 | source.getNeighbours(r).forEach[target| | ||
39 | addEdge(source, target, r); | ||
40 | ] | ||
41 | }else{ | ||
42 | //single references | ||
43 | val target = source.eGet(r) as EObject; | ||
44 | addEdge(source, target, r); | ||
45 | } | ||
46 | ] | ||
47 | ] | ||
48 | |||
49 | this.metrics = metrics; | ||
50 | this.name = name; | ||
51 | } | ||
52 | |||
53 | /** | ||
54 | * Set basic information for the output | ||
55 | */ | ||
56 | override setBasicInformation(ArrayList<ArrayList<String>> output){ | ||
57 | val metaInfo = new ArrayList<String>(); | ||
58 | metaInfo.add(META_MODEL_HEADER); | ||
59 | metaInfo.add(this.metaModel); | ||
60 | |||
61 | val edgeInfo = new ArrayList<String>(); | ||
62 | edgeInfo.add(NUM_EDGE_TYPE_HEADER); | ||
63 | edgeInfo.add(this.statistic.allTypes.size()+""); | ||
64 | |||
65 | val nodeInfo = new ArrayList<String>(); | ||
66 | nodeInfo.add(NUM_NODE_HEADER); | ||
67 | nodeInfo.add(this.statistic.allNodes.size()+""); | ||
68 | |||
69 | val stateInfo = new ArrayList<String>(); | ||
70 | stateInfo.add(STATE_ID_HEADER); | ||
71 | stateInfo.add(this.name); | ||
72 | |||
73 | |||
74 | output.add(metaInfo); | ||
75 | output.add(edgeInfo); | ||
76 | output.add(nodeInfo); | ||
77 | output.add(stateInfo); | ||
78 | } | ||
79 | |||
80 | def EList<EObject> getNeighbours(EObject o, EReference r){ | ||
81 | return (o.eGet(r, true) as EList<EObject>); | ||
82 | } | ||
83 | |||
84 | def addEdge(EObject source, EObject target, EReference r){ | ||
85 | if(target !== null && r !== null){ | ||
86 | statistic.addEdge(source, target, r.name); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | override GraphStatistic getStatistic(){ | ||
91 | return this.statistic; | ||
92 | } | ||
93 | |||
94 | override String getName(){ | ||
95 | return this.name; | ||
96 | } | ||
97 | |||
98 | def void setMetaModel(String model){ | ||
99 | this.metaModel = model; | ||
100 | } | ||
101 | |||
102 | def String getMetaModel(){ | ||
103 | return this.metaModel; | ||
104 | } | ||
105 | |||
106 | } \ No newline at end of file | ||