-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add models for Apache Commons Lang's tuple types #5772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add models for Apache Commons Lang's tuple types #5772
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! Did you forget to check in the test .ql
and .expected
files?
private SummaryComponent interpretComponent(string c) { | ||
specSplit(_, c, _) and | ||
( | ||
exists(int pos | parseArg(c, pos) and result = SummaryComponent::argument(pos)) | ||
or | ||
exists(int pos | parseParam(c, pos) and result = SummaryComponent::parameter(pos)) | ||
or | ||
c.matches("Field%") and result = SummaryComponent::field(interpretField(c.splitAt(" ", 1))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Field %"
?
@@ -137,10 +137,10 @@ class MapValueContent extends Content, TMapValueContent { | |||
* Thus, `node2` references an object with a field `f` that contains the | |||
* value of `node1`. | |||
*/ | |||
predicate storeStep(Node node1, Content f, PostUpdateNode node2) { | |||
predicate storeStep(Node node1, Content f, Node node2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just verifying that this change is expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, because we now have storeSteps pointed at synthetic nodes that don't have PUNs (perhaps they should?)
No files are forgotten; the flow.ql and empty .expected (for an inline-expectation test) are already present in the commons-lang3 directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the public constructors are not modeled, is that on purpose?
"org.apache.commons.lang3.tuple;ImmutablePair;false;right;;;Argument[0];Field org.apache.commons.lang3.tuple.ImmutablePair.right of ReturnValue;value", | ||
"org.apache.commons.lang3.tuple;ImmutablePair;false;left;;;Argument[0];Field org.apache.commons.lang3.tuple.ImmutablePair.left of ReturnValue;value", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really minor, but is it intended that here "right" is listed before "left"? In all other cases it seems to be the other way around.
|
||
void sink(Object o) {} | ||
|
||
void test() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be missing a test for Triple.of(left, middle, right)
Might be good to add it for completeness?
|
||
void sink(Object o) {} | ||
|
||
void test() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be missing a test for Pair.of(left, right)
Might be good to add it for completeness?
@Marcono1234 thanks, done |
bindingset[name] | ||
private Field interpretField(string name) { | ||
exists(string splitRegex, string package, string className, string fieldName | | ||
splitRegex = "^(.*)\\.([^.]+)\\.([^.]+)$" and | ||
package = name.regexpCapture(splitRegex, 1) and | ||
className = name.regexpCapture(splitRegex, 2) and | ||
fieldName = name.regexpCapture(splitRegex, 3) | ||
| | ||
result = any(Field f | f.hasQualifiedName(package, className, fieldName)) | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having a bindingset
-annotated predicate, I'd prefer to match the style of parseArg
and parseParam
.
bindingset[name] | |
private Field interpretField(string name) { | |
exists(string splitRegex, string package, string className, string fieldName | | |
splitRegex = "^(.*)\\.([^.]+)\\.([^.]+)$" and | |
package = name.regexpCapture(splitRegex, 1) and | |
className = name.regexpCapture(splitRegex, 2) and | |
fieldName = name.regexpCapture(splitRegex, 3) | |
| | |
result = any(Field f | f.hasQualifiedName(package, className, fieldName)) | |
) | |
} | |
private predicate parseField(string c, Field f) { | |
specSplit(_, c, _) and | |
exists(string splitRegex, string package, string className, string fieldName | | |
fieldRegex = "^Field (.*)\\.([^.]+)\\.([^.]+)$" and | |
package = c.regexpCapture(fieldRegex, 1) and | |
className = c.regexpCapture(fieldRegex, 2) and | |
fieldName = c.regexpCapture(fieldRegex, 3) and | |
f.hasQualifiedName(package, className, fieldName) | |
) | |
} |
d91a3e9
to
d28c95d
Compare
@aschackmull done, and style changed from |
I've got a feeling that the tests in |
Nope, those tests seem fine. I don't immediately see what trouble you would expect. |
I was thinking of |
I think that's fine because it defers to |
Ah, perfect! |
This also adds support for (fully-qualified) fields.
My approach here is to keep the models to the concrete types
(Im)?mutable(Pair|Triple)
, relying on virtual dispatch to determine what happens to calls against the interfacesPair
andTriple
. This can fail when neither type is referred to explicitly and tuples are provided by external code already constructed, however I don't add the synthetic field needed for this case in this PR.