For your regex example, the solution is very simple. I also give some information about cases where the solution is not so simple.
How to implement a run-time test depends on whether the type system is a calculation of the properties of the data itself or the properties of the origin (data source). Here is the text in the " " Runtime Checks and Type Clarification " Framework Checker Guide :
Some type systems support a run-time test that the Framework can use to refine types within a conditional expression, for example, if, after assert is approved, etc.
Regardless of whether the type system supports such a test at runtime, whether the type system is a calculation of the properties of the data itself or the property of origin (data source). Example A data property about whether a string is a regular expression. An example of property of origin is units: there is no way to look at the representation of a number and determine whether it should represent kilometers or miles.
1) For data properties , your easiest option is to avoid test instances and instead use the tests that come with the Framework Checker, such as isRegex .
For example, instead of
if (x instanceof @Regex String) ...
records
if (RegexUtil.isRegex(x)) ...
and you're done.
If you really want to use instanceof instead of isRegex , you will need to hack the compiler to convert each source code to x instanceof @Regex String to RegexUtil.isRegex(x) . You can also do this by overwriting the byte code.
2) For properties near the origin , implementation efforts are much greater. You will need to add a bit of evidence to the representation of each database in your program (including both objects and primitives) and change each operation (in your own program and in libraries) so that in addition to working with data this also matches the origin bit . A tool that already does this, on which you can build, is DynComp , which is distributed as part of the Daikon invariant detector .
source share