Skip to content

Commit 2d862ef

Browse files
Support synthetic fields
1 parent 309f0e7 commit 2d862ef

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

java/ql/src/utils/GenerateFlowTestCase.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ string getFieldToken(FieldContent fc) {
137137
fc.getField().getName()
138138
}
139139

140+
/**
141+
* Returns a valid Java token naming the synthtic field `fc`,
142+
* assuming that the name of that field consists only of characters valid in a Java identifier and `.`.
143+
*/
144+
string getSyntheticFieldToken(SyntheticFieldContent fc) {
145+
exists(string name, int parts |
146+
name = fc.getField() and
147+
parts = count(name.splitAt("."))
148+
|
149+
if parts = 1
150+
then result = name
151+
else result = name.splitAt(".", parts - 2) + "_" + name.splitAt(".", parts - 1)
152+
)
153+
}
154+
140155
/**
141156
* Returns a token suitable for incorporation into a Java method name describing content `c`.
142157
*/
@@ -150,6 +165,8 @@ string contentToken(Content c) {
150165
c instanceof MapValueContent and result = "MapValue"
151166
or
152167
result = getFieldToken(c)
168+
or
169+
result = getSyntheticFieldToken(c)
153170
}
154171

155172
/**
@@ -422,6 +439,8 @@ class TestCase extends TTestCase {
422439
content instanceof CollectionContent and result = "Element"
423440
or
424441
result = "Field[" + content.(FieldContent).getField().getQualifiedName() + "]"
442+
or
443+
result = "SyntheticField[" + content.(SyntheticFieldContent).getField() + "]"
425444
)
426445
)
427446
}

0 commit comments

Comments
 (0)