mirror of
https://github.com/github/codeql.git
synced 2025-12-21 11:16:30 +01:00
Merge pull request #6374 from joefarebrother/test-gen-improvements
Java: Add support for synthetic fields to the test generator
This commit is contained in:
@@ -140,6 +140,21 @@ string getFieldToken(FieldContent fc) {
|
|||||||
fc.getField().getName()
|
fc.getField().getName()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a valid Java token naming the synthetic field `fc`,
|
||||||
|
* assuming that the name of that field consists only of characters valid in a Java identifier and `.`.
|
||||||
|
*/
|
||||||
|
string getSyntheticFieldToken(SyntheticFieldContent fc) {
|
||||||
|
exists(string name, int parts |
|
||||||
|
name = fc.getField() and
|
||||||
|
parts = count(name.splitAt("."))
|
||||||
|
|
|
||||||
|
if parts = 1
|
||||||
|
then result = name
|
||||||
|
else result = name.splitAt(".", parts - 2) + "_" + name.splitAt(".", parts - 1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a token suitable for incorporation into a Java method name describing content `c`.
|
* Returns a token suitable for incorporation into a Java method name describing content `c`.
|
||||||
*/
|
*/
|
||||||
@@ -153,6 +168,8 @@ string contentToken(Content c) {
|
|||||||
c instanceof MapValueContent and result = "MapValue"
|
c instanceof MapValueContent and result = "MapValue"
|
||||||
or
|
or
|
||||||
result = getFieldToken(c)
|
result = getFieldToken(c)
|
||||||
|
or
|
||||||
|
result = getSyntheticFieldToken(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -425,6 +442,8 @@ class TestCase extends TTestCase {
|
|||||||
content instanceof CollectionContent and result = "Element"
|
content instanceof CollectionContent and result = "Element"
|
||||||
or
|
or
|
||||||
result = "Field[" + content.(FieldContent).getField().getQualifiedName() + "]"
|
result = "Field[" + content.(FieldContent).getField().getQualifiedName() + "]"
|
||||||
|
or
|
||||||
|
result = "SyntheticField[" + content.(SyntheticFieldContent).getField() + "]"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user