|
| 1 | +import ql |
| 2 | + |
| 3 | +/** |
| 4 | + * Gets the name for a `node` that defines something in a QL program. |
| 5 | + * E.g. a predicate, class, or module definition. |
| 6 | + */ |
| 7 | +string getName(AstNode node, string kind) { |
| 8 | + result = node.(Class).getName() and kind = "class" |
| 9 | + or |
| 10 | + // not including CharPreds or db relations. The remaining are: classlessPredicate, classPredicate, newTypeBranch. |
| 11 | + result = node.(ClasslessPredicate).getName() and |
| 12 | + kind = "classlessPredicate" |
| 13 | + or |
| 14 | + result = node.(ClassPredicate).getName() and |
| 15 | + kind = "classPredicate" |
| 16 | + or |
| 17 | + result = node.(NewTypeBranch).getName() and |
| 18 | + kind = "newtypeBranch" |
| 19 | + or |
| 20 | + result = node.(VarDecl).getName() and |
| 21 | + kind = "variable" and |
| 22 | + not node = any(FieldDecl f).getVarDecl() |
| 23 | + or |
| 24 | + result = node.(FieldDecl).getName() and kind = "field" |
| 25 | + or |
| 26 | + result = node.(Module).getName() and kind = "module" |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * Holds if `name` seems to contain an upper-cased acronym that could be pascal-cased. |
| 31 | + * `name` is the name of `node`, and `kind` describes what kind of definition `node` is. |
| 32 | + */ |
| 33 | +predicate shouldBePascalCased(string name, AstNode node, string kind) { |
| 34 | + name = getName(node, kind) and |
| 35 | + name.regexpMatch(".*[A-Z]{4,}.+") and |
| 36 | + not node.hasAnnotation("deprecated") and |
| 37 | + // allowed upper-case acronyms. |
| 38 | + not name.regexpMatch(".*(PEP|AES|DES|EOF).*") |
| 39 | +} |
0 commit comments