|
| 1 | +/** |
| 2 | + * Provides classes for working with external data. |
| 3 | + */ |
| 4 | + |
1 | 5 | import python
|
2 | 6 |
|
3 | 7 | class ExternalDefect extends @externalDefect {
|
@@ -27,23 +31,37 @@ class ExternalMetric extends @externalMetric {
|
27 | 31 | string toString() { result = getQueryPath() + ": " + getLocation() + " - " + getValue() }
|
28 | 32 | }
|
29 | 33 |
|
| 34 | +/** |
| 35 | + * An external data item. |
| 36 | + */ |
30 | 37 | class ExternalData extends @externalDataElement {
|
| 38 | + /** Gets the path of the file this data was loaded from. */ |
31 | 39 | string getDataPath() { externalData(this, result, _, _) }
|
32 | 40 |
|
| 41 | + /** Gets the path fo the file this data was loaded from, with its |
| 42 | + * extension replaced by `.ql`. |
| 43 | + */ |
33 | 44 | string getQueryPath() { result = getDataPath().regexpReplaceAll("\\.[^.]*$", ".ql") }
|
34 | 45 |
|
| 46 | + /** Gets the number of fields in this data item. */ |
35 | 47 | int getNumFields() { result = 1 + max(int i | externalData(this, _, i, _) | i) }
|
36 | 48 |
|
| 49 | + /** Gets the value of the field at position `index` of this data item. */ |
37 | 50 | string getField(int index) { externalData(this, _, index, result) }
|
38 | 51 |
|
| 52 | + /** Gets the integer value of the field at position `index` of this data item. */ |
39 | 53 | int getFieldAsInt(int index) { result = getField(index).toInt() }
|
40 | 54 |
|
| 55 | + /** Gets the floating-point value of the field at position `index` of this data item. */ |
41 | 56 | float getFieldAsFloat(int index) { result = getField(index).toFloat() }
|
42 | 57 |
|
| 58 | + /** Gets the value of the field at position `index` of this data item, interpreted as a date. */ |
43 | 59 | date getFieldAsDate(int index) { result = getField(index).toDate() }
|
44 | 60 |
|
| 61 | + /** Gets a textual representation of this data item. */ |
45 | 62 | string toString() { result = getQueryPath() + ": " + buildTupleString(0) }
|
46 | 63 |
|
| 64 | + /** Gets a textual representation of this data item, starting with the field at position `start`. */ |
47 | 65 | private string buildTupleString(int start) {
|
48 | 66 | start = getNumFields() - 1 and result = getField(start)
|
49 | 67 | or
|
|
0 commit comments