Skip to content

Commit 5bf82ae

Browse files
committed
Swift: Add FieldDecl.hasQualifiedName.
1 parent c1bd04e commit 5bf82ae

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

swift/ql/lib/codeql/swift/elements/decl/VarDecl.qll

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,32 @@ class VarDecl extends Generated::VarDecl {
99
}
1010

1111
/**
12-
* A field declaration.
12+
* A field declaration. That is, a variable declaration that is a member of a
13+
* class, struct, enum or protocol.
1314
*/
1415
class FieldDecl extends VarDecl {
1516
FieldDecl() { this = any(Decl ctx).getAMember() }
17+
18+
/**
19+
* Holds if this field is called `fieldName` and is a member of a
20+
* class, struct, extension, enum or protocol called `typeName`.
21+
*/
22+
cached
23+
predicate hasQualifiedName(string typeName, string fieldName) {
24+
this.getName() = fieldName and
25+
exists(Decl d |
26+
d.asNominalTypeDecl().getFullName() = typeName and
27+
d.getAMember() = this
28+
)
29+
}
30+
31+
/**
32+
* Holds if this field is called `fieldName` and is a member of a
33+
* class, struct, extension, enum or protocol called `typeName` in a module
34+
* called `moduleName`.
35+
*/
36+
predicate hasQualifiedName(string moduleName, string typeName, string fieldName) {
37+
this.hasQualifiedName(typeName, fieldName) and
38+
this.getModule().getFullName() = moduleName
39+
}
1640
}

0 commit comments

Comments
 (0)