@@ -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
@@ -163,6 +176,43 @@ private class MethodUse extends Use instanceof NameRef {
163176 override string getUseType ( ) { result = "method" }
164177}
165178
179+ private class OperationUse extends Use instanceof Operation {
180+ override Definition getDefinition ( ) { result .asItemNode ( ) = super .getResolvedTarget ( ) }
181+
182+ override string getUseType ( ) { result = "method" }
183+
184+ override predicate hasLocationInfo (
185+ string filepath , int startline , int startcolumn , int endline , int endcolumn
186+ ) {
187+ // We don't have entities for the operator symbols, so approximate a location
188+ this =
189+ any ( PrefixExpr pe |
190+ pe .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , _, _) and
191+ pe .getExpr ( ) .getLocation ( ) .hasLocationInfo ( _, endline , endcolumn + 2 , _, _)
192+ )
193+ or
194+ this =
195+ any ( BinaryExpr be |
196+ be .getLhs ( ) .getLocation ( ) .hasLocationInfo ( filepath , _, _, startline , startcolumn - 2 ) and
197+ be .getRhs ( ) .getLocation ( ) .hasLocationInfo ( filepath , endline , endcolumn + 2 , _, _)
198+ )
199+ }
200+ }
201+
202+ private class IndexExprUse extends Use instanceof IndexExpr {
203+ override Definition getDefinition ( ) { result .asItemNode ( ) = super .getStaticTarget ( ) }
204+
205+ override string getUseType ( ) { result = "method" }
206+
207+ override predicate hasLocationInfo (
208+ string filepath , int startline , int startcolumn , int endline , int endcolumn
209+ ) {
210+ // We don't have entities for the brackets, so approximate a location
211+ super .getIndex ( ) .getLocation ( ) .hasLocationInfo ( filepath , _, _, startline , startcolumn - 2 ) and
212+ this .getLocation ( ) .hasLocationInfo ( _, _, _, endline , endcolumn )
213+ }
214+ }
215+
166216private class FileUse extends Use instanceof Name {
167217 override Definition getDefinition ( ) {
168218 exists ( Module m |
0 commit comments