add getter for static initializer blocks

This commit is contained in:
Erik Krogh Kristensen
2021-09-01 23:46:52 +02:00
parent 9585481d0b
commit ffd51e725f
3 changed files with 12 additions and 0 deletions

View File

@@ -258,6 +258,11 @@ class ClassDefinition extends @class_definition, ClassOrInterface, AST::ValueNod
}
override string getAPrimaryQlClass() { result = "ClassDefinition" }
/**
* Gets a static initializer of this class, if any.
*/
BlockStmt getAStaticInitializerBlock() { result.getParent() = this }
}
/**

View File

@@ -670,3 +670,6 @@ unionIndex
| { stillMyUnion: true; } | 1 | MyUnion \| { yetAnotherType: true; } |
| { stillMyUnion: true; } | 1 | { myUnion: true; } \| { stillMyUnion: true; } |
| { yetAnotherType: true; } | 2 | MyUnion \| { yetAnotherType: true; } |
getAStaticInitializerBlock
| tst.ts:179:3:192:3 | class F ... \\n } | tst.ts:185:5:187:5 | static ... ;\\n } |
| tst.ts:179:3:192:3 | class F ... \\n } | tst.ts:188:5:190:5 | static ... ;\\n } |

View File

@@ -39,3 +39,7 @@ query predicate unknownType(Expr e, Type type) {
query CallSignatureType abstractSignature() { result.isAbstract() }
query UnionType unionIndex(Type element, int i) { result.getElementType(i) = element }
query BlockStmt getAStaticInitializerBlock(ClassDefinition cls) {
result = cls.getAStaticInitializerBlock()
}