|
10 | 10 |
|
11 | 11 | import ql
|
12 | 12 |
|
13 |
| -from ClassPredicate pred, String constant |
| 13 | +/** |
| 14 | + * Gets a string that is allowed to be returned from the `getAPrimaryQlClass` implementation |
| 15 | + * in class `c`. |
| 16 | + * |
| 17 | + * For most languages this is just the name of `c`, but QL for Swift implements |
| 18 | + * the `getAPrimaryQlClass` predicate for a class `Foo` in another class `FooBase`. |
| 19 | + */ |
| 20 | +string getAnAllowedResultForClass(Class c) { |
| 21 | + result = c.getName() |
| 22 | + or |
| 23 | + c.getName() = result + "Base" |
| 24 | +} |
| 25 | + |
| 26 | +from ClassPredicate pred, String constant, Class c |
14 | 27 | where
|
15 |
| - exists(string className, string constantName | |
16 |
| - pred.getParent().getName() = className and |
17 |
| - pred.getName() = "getAPrimaryQlClass" and |
| 28 | + c = pred.getParent() and |
| 29 | + pred.getName() = "getAPrimaryQlClass" and |
| 30 | + exists(string constantName | |
18 | 31 | constant = pred.getBody().(ComparisonFormula).getRightOperand() and
|
19 | 32 | constant.getValue() = constantName and
|
20 | 33 | // might be "Foo::classname", detect by matching with a regexp
|
21 |
| - not constantName.regexpMatch(".*\\b" + className + "$") and |
| 34 | + not constantName.regexpMatch(".*\\b" + getAnAllowedResultForClass(c) + "$") and |
22 | 35 | // ignore constants with "?" in them
|
23 | 36 | not constantName.regexpMatch(".*\\?.*")
|
24 | 37 | )
|
25 | 38 | select pred,
|
26 |
| - "The getAPrimaryQlClass predicate $@ instead of the class name \"" + pred.getParent().getName() + |
27 |
| - "\".", constant, "results in \"" + constant.getValue() + "\"" |
| 39 | + "The getAPrimaryQlClass predicate $@ instead of the class name \"" + c.getName() + "\".", |
| 40 | + constant, "results in \"" + constant.getValue() + "\"" |
0 commit comments