@@ -144,36 +144,34 @@ class Entity extends @object {
144144 /** Gets a textual representation of this entity. */
145145 string toString ( ) { result = this .getName ( ) }
146146
147- private predicate hasRealLocationInfo (
148- string filepath , int startline , int startcolumn , int endline , int endcolumn
149- ) {
150- // take the location of the declaration if there is one
151- this .getDeclaration ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) or
152- any ( CaseClause cc | this = cc .getImplicitlyDeclaredVariable ( ) )
153- .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
147+ /** Gets the location of this entity. */
148+ Location getLocation ( ) {
149+ result = this .getDeclaration ( ) .getLocation ( )
150+ or
151+ result = any ( CaseClause cc | this = cc .getImplicitlyDeclaredVariable ( ) ) .getLocation ( )
154152 }
155153
156154 /**
155+ * DEPRECATED: Use `getLocation()` instead.
156+ *
157157 * Holds if this element is at the specified location.
158158 * The location spans column `startcolumn` of line `startline` to
159159 * column `endcolumn` of line `endline` in file `filepath`.
160160 * For more information, see
161161 * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
162162 */
163- predicate hasLocationInfo (
163+ deprecated predicate hasLocationInfo (
164164 string filepath , int startline , int startcolumn , int endline , int endcolumn
165165 ) {
166- // take the location of the declaration if there is one
167- if this .hasRealLocationInfo ( _, _, _, _, _)
168- then this .hasRealLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
169- else (
170- // otherwise fall back on dummy location
171- filepath = "" and
172- startline = 0 and
173- startcolumn = 0 and
174- endline = 0 and
175- endcolumn = 0
176- )
166+ this .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
167+ or
168+ // otherwise fall back on dummy location
169+ not exists ( this .getLocation ( ) ) and
170+ filepath = "" and
171+ startline = 0 and
172+ startcolumn = 0 and
173+ endline = 0 and
174+ endcolumn = 0
177175 }
178176}
179177
@@ -680,16 +678,22 @@ class Callable extends TCallable {
680678 result = this .asFuncLit ( ) .getName ( )
681679 }
682680
681+ /** Gets the location of this callable. */
682+ Location getLocation ( ) {
683+ result = this .asFunction ( ) .getLocation ( ) or result = this .asFuncLit ( ) .getLocation ( )
684+ }
685+
683686 /**
687+ * DEPRECATED: Use `getLocation()` instead.
688+ *
684689 * Holds if this element is at the specified location.
685690 * The location spans column `sc` of line `sl` to
686691 * column `ec` of line `el` in file `fp`.
687692 * For more information, see
688693 * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
689694 */
690- predicate hasLocationInfo ( string fp , int sl , int sc , int el , int ec ) {
691- this .asFunction ( ) .hasLocationInfo ( fp , sl , sc , el , ec ) or
692- this .asFuncLit ( ) .hasLocationInfo ( fp , sl , sc , el , ec )
695+ deprecated predicate hasLocationInfo ( string fp , int sl , int sc , int el , int ec ) {
696+ this .getLocation ( ) .hasLocationInfo ( fp , sl , sc , el , ec )
693697 }
694698}
695699
0 commit comments