how to detect chained method calls in Java #534
-
hi, i would like to detect the following patterns : 1 - 2 - 3- I am able to detect pattern 1 and 2 by something like: class RecordClass extends Class {
ConnectRecordClass() {
this.hasQualifiedName("org.apache.<blah>", "<blah>")
}
}
this.getMethod().getDeclaringType().getASourceSupertype*() instanceof RecordClass and
this.getMethod().getName() = "toString" For pattern number 3, how can I get reference to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Presumably, you need to handle data flow, so something like this is also important:
Is it any value that was at some point retrieved from the However, you are saying something that makes me think there is no robust way to do this using static analysis. You are saying that you only want to match on invocations of the The problem here is that this is not easily known statically since we would need to track creations of What would be easier to detect and may be good enough for your purpose is creations of |
Beta Was this translation helpful? Give feedback.
-
Do you want something like this? from Method value, MethodAccess valueMa, MethodAccess toString
where value.hasName("value") and
valueMa.getMethod() = value and
toString.getQualifier() = valueMa and // <- chaining; `toString()`'s qualifier is `value()`.
toString.hasName("toString")
select value, valueMa, toString This should work (untested code) and detect |
Beta Was this translation helpful? Give feedback.
Do you want something like this?
This should work (untested code) and detect
this.record.value().toString()
.