Skip to content

Commit 48872b4

Browse files
committed
Java: Improve Callable.getStringSignature() documentation
1 parent 57ff8e7 commit 48872b4

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

java/ql/src/semmle/code/java/Member.qll

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,26 @@ class Callable extends StmtParent, Member, @callable {
183183
Type getParameterType(int n) { params(_, result, n, this, _) }
184184

185185
/**
186-
* Gets the signature of this callable, including its name and the types of all its parameters,
187-
* identified by their simple (unqualified) names.
186+
* Gets the signature of this callable, including its name and the types of all
187+
* its parameters, identified by their simple (unqualified) names.
188+
*
189+
* The format of the string is `<name><params>`, where `<name>` is the result of
190+
* the predicate `getName()` and `<params>` is the result of `paramsString()`.
191+
* For example, the method `void printf(java.lang.String, java.lang.Object...)`
192+
* has the string signature `printf(String, Object[])`.
188193
*
189194
* Use `getSignature` to obtain a signature including fully qualified type names.
190195
*/
191196
string getStringSignature() { result = this.getName() + this.paramsString() }
192197

193-
/** Gets a parenthesized string containing all parameter types of this callable, separated by a comma. */
198+
/**
199+
* Gets a parenthesized string containing all parameter types of this callable,
200+
* separated by a comma and space. For the parameter types the unqualified string
201+
* representation is used. If this callable has no parameters, the result is `()`.
202+
*
203+
* For example, the method `void printf(java.lang.String, java.lang.Object...)`
204+
* has the params string `(String, Object[])`.
205+
*/
194206
pragma[nomagic]
195207
string paramsString() {
196208
exists(int n | n = getNumberOfParameters() |
@@ -210,7 +222,12 @@ class Callable extends StmtParent, Member, @callable {
210222
n > 0 and result = paramUpTo(n - 1) + ", " + getParameterType(n)
211223
}
212224

213-
/** Holds if this callable has the specified string signature. */
225+
/**
226+
* Holds if this callable has the specified string signature.
227+
*
228+
* This predicate simply tests if `sig` is equal to the result of the
229+
* `getStringSignature()` predicate.
230+
*/
214231
predicate hasStringSignature(string sig) { sig = this.getStringSignature() }
215232

216233
/** Gets an exception that occurs in the `throws` clause of this callable. */
@@ -250,8 +267,10 @@ class Callable extends StmtParent, Member, @callable {
250267

251268
/**
252269
* Gets the signature of this callable, where all types in the signature have a fully-qualified name.
270+
* The parameter types are only separated by a comma (without space). If this callable has
271+
* no parameters, the callable name is followed by `()`.
253272
*
254-
* For example, method `void m(String s)` has the signature `m(java.lang.String)`.
273+
* For example, method `void m(String s, int i)` has the signature `m(java.lang.String,int)`.
255274
*/
256275
string getSignature() {
257276
constrs(this, _, result, _, _, _) or

0 commit comments

Comments
 (0)