Skip to content

Commit d900fca

Browse files
Merge pull request github#6374 from joefarebrother/test-gen-improvements
Java: Add support for synthetic fields to the test generator
2 parents d7c2979 + 9ddae3e commit d900fca

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
@@ -140,6 +140,21 @@ string getFieldToken(FieldContent fc) {
140140
fc.getField().getName()
141141
}
142142

143+
/**
144+
* Returns a valid Java token naming the synthetic field `fc`,
145+
* assuming that the name of that field consists only of characters valid in a Java identifier and `.`.
146+
*/
147+
string getSyntheticFieldToken(SyntheticFieldContent fc) {
148+
exists(string name, int parts |
149+
name = fc.getField() and
150+
parts = count(name.splitAt("."))
151+
|
152+
if parts = 1
153+
then result = name
154+
else result = name.splitAt(".", parts - 2) + "_" + name.splitAt(".", parts - 1)
155+
)
156+
}
157+
143158
/**
144159
* Returns a token suitable for incorporation into a Java method name describing content `c`.
145160
*/
@@ -153,6 +168,8 @@ string contentToken(Content c) {
153168
c instanceof MapValueContent and result = "MapValue"
154169
or
155170
result = getFieldToken(c)
171+
or
172+
result = getSyntheticFieldToken(c)
156173
}
157174

158175
/**
@@ -425,6 +442,8 @@ class TestCase extends TTestCase {
425442
content instanceof CollectionContent and result = "Element"
426443
or
427444
result = "Field[" + content.(FieldContent).getField().getQualifiedName() + "]"
445+
or
446+
result = "SyntheticField[" + content.(SyntheticFieldContent).getField() + "]"
428447
)
429448
)
430449
}

0 commit comments

Comments
 (0)