@@ -22,6 +22,7 @@ class StringFormatMethod extends FormatMethod {
2222 StringFormatMethod ( ) {
2323 (
2424 this .hasName ( "format" ) or
25+ this .hasName ( "formatted" ) or
2526 this .hasName ( "printf" ) or
2627 this .hasName ( "readLine" ) or
2728 this .hasName ( "readPassword" )
@@ -38,6 +39,8 @@ class StringFormatMethod extends FormatMethod {
3839 override int getFormatStringIndex ( ) {
3940 result = 0 and this .getSignature ( ) = "format(java.lang.String,java.lang.Object[])"
4041 or
42+ result = - 1 and this .getSignature ( ) = "formatted(java.lang.Object[])"
43+ or
4144 result = 0 and this .getSignature ( ) = "printf(java.lang.String,java.lang.Object[])"
4245 or
4346 result = 1 and
@@ -91,6 +94,12 @@ class FmtSyntax extends TFmtSyntax {
9194 predicate isLogger ( ) { this = TFmtLogger ( ) }
9295}
9396
97+ private Expr getArgumentOrQualifier ( Call c , int i ) {
98+ result = c .getArgument ( i )
99+ or
100+ result = c .getQualifier ( ) and i = - 1
101+ }
102+
94103/**
95104 * Holds if `c` wraps a call to a `StringFormatMethod`, such that `fmtix` is
96105 * the index of the format string argument to `c` and the following and final
@@ -111,7 +120,7 @@ private predicate formatWrapper(Callable c, int fmtix, FmtSyntax syntax) {
111120 or
112121 fmtcall .getCallee ( ) .( LoggerFormatMethod ) .getFormatStringIndex ( ) = i and syntax = TFmtLogger ( )
113122 ) and
114- fmtcall . getArgument ( i ) = fmt .getAnAccess ( ) and
123+ getArgumentOrQualifier ( fmtcall , i ) = fmt .getAnAccess ( ) and
115124 fmtcall .getArgument ( i + 1 ) = args .getAnAccess ( )
116125 )
117126}
@@ -155,7 +164,7 @@ class FormattingCall extends Call {
155164 }
156165
157166 /** Gets the argument to this call in the position of the format string */
158- Expr getFormatArgument ( ) { result = this . getArgument ( this .getFormatStringIndex ( ) ) }
167+ Expr getFormatArgument ( ) { result = getArgumentOrQualifier ( this , this .getFormatStringIndex ( ) ) }
159168
160169 /** Gets an argument to be formatted. */
161170 Expr getAnArgumentToBeFormatted ( ) {
0 commit comments