-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathClover.qll
More file actions
139 lines (105 loc) · 3.85 KB
/
Clover.qll
File metadata and controls
139 lines (105 loc) · 3.85 KB
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
import java
/**
* A Clover report is characterised by the fact that one of its
* top-level children (usually, in fact, there is only one) is
* a tag with the name "coverage".
*/
class CloverReport extends XMLFile {
CloverReport() { this.getAChild().getName() = "coverage" }
}
/**
* The Clover "coverage" tag contains one or more "projects".
*/
class CloverCoverage extends XMLElement {
CloverCoverage() {
this.getParent() instanceof CloverReport and
this.getName() = "coverage"
}
CloverProject getAProject() { result = this.getAChild() }
}
/**
* Several elements in the Clover report contain a "metrics" element which
* contains various numbers, aggregated to the different levels. They are
* all subclasses of this class, to share code.
*/
abstract class CloverMetricsContainer extends XMLElement {
CloverMetrics getMetrics() { result = this.getAChild() }
}
/**
* A "metrics" element contains a range of numbers for the current
* aggregation level.
*/
class CloverMetrics extends XMLElement {
CloverMetrics() {
this.getParent() instanceof CloverMetricsContainer and
this.getName() = "metrics"
}
private int attr(string name) { result = this.getAttribute(name).getValue().toInt() }
private float ratio(string name) { result = attr("covered" + name) / attr(name).(float) }
int getNumConditionals() { result = attr("conditionals") }
int getNumCoveredConditionals() { result = attr("coveredconditionals") }
int getNumStatements() { result = attr("statements") }
int getNumCoveredStatements() { result = attr("coveredstatements") }
int getNumElements() { result = attr("elements") }
int getNumCoveredElements() { result = attr("coveredelements") }
int getNumMethods() { result = attr("methods") }
int getNumCoveredMethods() { result = attr("coveredmethods") }
int getNumLoC() { result = attr("loc") }
int getNumNonCommentedLoC() { result = attr("ncloc") }
int getNumPackages() { result = attr("packages") }
int getNumFiles() { result = attr("files") }
int getNumClasses() { result = attr("classes") }
int getCloverComplexity() { result = attr("complexity") }
float getConditionalCoverage() { result = ratio("conditionals") }
float getStatementCoverage() { result = ratio("statements") }
float getElementCoverage() { result = ratio("elements") }
float getMethodCoverage() { result = ratio("methods") }
float getNonCommentedLoCRatio() { result = attr("ncloc") / attr("loc") }
}
/**
* A Clover project has an aggregated "metrics" element and
* groups together several "package" (or "testpackage") elements.
*/
class CloverProject extends CloverMetricsContainer {
CloverProject() { this.getParent() instanceof CloverCoverage }
}
/**
* A Clover package is nested in a project and contains several files.
*/
class CloverPackage extends CloverMetricsContainer {
CloverPackage() {
this.getParent() instanceof CloverProject and
this.getName() = "package"
}
Package getRealPackage() { result.hasName(getAttribute("name").getValue()) }
}
/**
* A Clover file is nested in a package and contains several classes.
*/
class CloverFile extends CloverMetricsContainer {
CloverFile() {
this.getParent() instanceof CloverPackage and
this.getName() = "file"
}
}
/**
* A Clover class is nested in a file and contains metric information.
*/
class CloverClass extends CloverMetricsContainer {
CloverClass() {
this.getParent() instanceof CloverFile and
this.getName() = "class"
}
CloverPackage getPackage() { result = getParent().(CloverFile).getParent() }
RefType getRealClass() {
result
.hasQualifiedName(getPackage().getAttribute("name").getValue(),
getAttribute("name").getValue())
}
}
/**
* Get the clover metrics associated with the given class, if any.
*/
CloverMetrics cloverInfo(RefType t) {
exists(CloverClass c | c.getRealClass() = t | result = c.getMetrics())
}