@@ -26,6 +26,19 @@ abstract class Use extends Locatable {
2626 * Gets the type of use.
2727 */
2828 abstract string getUseType ( ) ;
29+
30+ /**
31+ * Holds if this element is at the specified location.
32+ * The location spans column `startcolumn` of line `startline` to
33+ * column `endcolumn` of line `endline` in file `filepath`.
34+ * For more information, see
35+ * [Providing locations in CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
36+ */
37+ predicate hasLocationInfo (
38+ string filepath , int startline , int startcolumn , int endline , int endcolumn
39+ ) {
40+ this .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
41+ }
2942}
3043
3144cached
@@ -166,6 +179,43 @@ private class MethodUse extends Use instanceof NameRef {
166179 override string getUseType ( ) { result = "method" }
167180}
168181
182+ private class OperationUse extends Use instanceof Operation {
183+ override Definition getDefinition ( ) { result .asItemNode ( ) = this .( Call ) .getStaticTarget ( ) }
184+
185+ override string getUseType ( ) { result = "method" }
186+
187+ override predicate hasLocationInfo (
188+ string filepath , int startline , int startcolumn , int endline , int endcolumn
189+ ) {
190+ // We don't have entities for the operator symbols, so approximate a location
191+ this =
192+ any ( PrefixExpr pe |
193+ pe .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , _, _) and
194+ pe .getExpr ( ) .getLocation ( ) .hasLocationInfo ( _, endline , endcolumn + 2 , _, _)
195+ )
196+ or
197+ this =
198+ any ( BinaryExpr be |
199+ be .getLhs ( ) .getLocation ( ) .hasLocationInfo ( filepath , _, _, startline , startcolumn - 2 ) and
200+ be .getRhs ( ) .getLocation ( ) .hasLocationInfo ( filepath , endline , endcolumn + 2 , _, _)
201+ )
202+ }
203+ }
204+
205+ private class IndexExprUse extends Use instanceof IndexExpr {
206+ override Definition getDefinition ( ) { result .asItemNode ( ) = this .( Call ) .getStaticTarget ( ) }
207+
208+ override string getUseType ( ) { result = "method" }
209+
210+ override predicate hasLocationInfo (
211+ string filepath , int startline , int startcolumn , int endline , int endcolumn
212+ ) {
213+ // We don't have entities for the brackets, so approximate a location
214+ super .getIndex ( ) .getLocation ( ) .hasLocationInfo ( filepath , _, _, startline , startcolumn - 2 ) and
215+ this .getLocation ( ) .hasLocationInfo ( _, _, _, endline , endcolumn )
216+ }
217+ }
218+
169219private class FileUse extends Use instanceof Name {
170220 override Definition getDefinition ( ) {
171221 exists ( Module m |
0 commit comments