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 | 101 |
1 files changed, 101 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..b20ffa01 --- /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,101 @@ | |||
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 | |||
12 | def void init (EObject root, List<Metric> metrics, String name, List<String> referenceTypes){ | ||
13 | val otherContents = root.eAllContents.toList(); | ||
14 | otherContents.add(root); | ||
15 | init(otherContents, metrics, name, referenceTypes); | ||
16 | } | ||
17 | |||
18 | /** | ||
19 | * init the graph with all nodes and reference types in the meta model | ||
20 | * @param objects: objects in the instance model (exclude root) | ||
21 | * @param metrics: metrics to be evaluated | ||
22 | * @param name: name of the instance model | ||
23 | * @param ReferenceTypes: reference types defined in the meta model | ||
24 | */ | ||
25 | def void init(List<EObject> objects, List<Metric> metrics, String name, List<String> referenceTypes){ | ||
26 | objects.forEach[it| | ||
27 | statistic.addNode(it); | ||
28 | ] | ||
29 | |||
30 | referenceTypes.forEach[it| | ||
31 | statistic.addType(it); | ||
32 | ]; | ||
33 | |||
34 | objects.forEach[source| | ||
35 | source.eClass.EAllReferences.forEach[r| | ||
36 | //add the type first (if it is not added already) | ||
37 | //many references | ||
38 | if(r.isMany){ | ||
39 | source.getNeighbours(r).forEach[target| | ||
40 | addEdge(source, target, r); | ||
41 | ] | ||
42 | }else{ | ||
43 | //single references | ||
44 | val target = source.eGet(r) as EObject; | ||
45 | addEdge(source, target, r); | ||
46 | } | ||
47 | ] | ||
48 | ] | ||
49 | |||
50 | this.metrics = metrics; | ||
51 | this.name = name; | ||
52 | } | ||
53 | |||
54 | /** | ||
55 | * Set basic information for the output | ||
56 | */ | ||
57 | override setBasicInformation(ArrayList<ArrayList<String>> output){ | ||
58 | val metaInfo = new ArrayList<String>(); | ||
59 | metaInfo.add(META_MODEL_HEADER); | ||
60 | metaInfo.add(this.metaModel); | ||
61 | |||
62 | val edgeInfo = new ArrayList<String>(); | ||
63 | edgeInfo.add(NUM_EDGE_TYPE_HEADER); | ||
64 | edgeInfo.add(this.statistic.allTypes.size()+""); | ||
65 | |||
66 | val nodeInfo = new ArrayList<String>(); | ||
67 | nodeInfo.add(NUM_NODE_HEADER); | ||
68 | nodeInfo.add(this.statistic.allNodes.size()+""); | ||
69 | |||
70 | output.add(metaInfo); | ||
71 | output.add(edgeInfo); | ||
72 | output.add(nodeInfo); | ||
73 | } | ||
74 | |||
75 | def EList<EObject> getNeighbours(EObject o, EReference r){ | ||
76 | return (o.eGet(r, true) as EList<EObject>); | ||
77 | } | ||
78 | |||
79 | def addEdge(EObject source, EObject target, EReference r){ | ||
80 | if(target !== null && r !== null){ | ||
81 | statistic.addEdge(source, target, r.name); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | override GraphStatistic getStatistic(){ | ||
86 | return this.statistic; | ||
87 | } | ||
88 | |||
89 | override String getName(){ | ||
90 | return this.name; | ||
91 | } | ||
92 | |||
93 | def void setMetaModel(String model){ | ||
94 | this.metaModel = model; | ||
95 | } | ||
96 | |||
97 | def String getMetaModel(){ | ||
98 | return this.metaModel; | ||
99 | } | ||
100 | |||
101 | } \ No newline at end of file | ||