Skip to content

Commit 30913c9

Browse files
author
james
committed
docs: add info about using getAQlClass()
(cherry picked from commit 3fb3b9b)
1 parent bd94e80 commit 30913c9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/language/learn-ql/writing-queries/debugging-queries.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,28 @@ is preferred over::
6262

6363
From the type context, the query optimizer deduces that some parts of the program are redundant and removes them, or *specializes* them.
6464

65+
Determine the most specific types of a variable
66+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67+
68+
If you are unfamiliar with the library used in a query, you can use CodeQL to determine what types an entity has. There is a predicate called ``getAQlClass()``, which returns the most specific QL types of the entity that it is called on.
69+
70+
For example, if you were working with a Java database, you might use ``getAQlClass()`` on every ``Expr`` in a callable called ``c``:
71+
72+
.. code-block:: ql
73+
74+
import java
75+
76+
from Expr e, Callable c
77+
where
78+
c.getDeclaringType().hasQualifiedName("my.namespace.name", "MyClass")
79+
and c.getName() = "c"
80+
and e.getEnclosingCallable() = c
81+
select e, e.getAQlClass()
82+
83+
The result of this query is a list of the most specific types of every ``Expr`` in that function. You will see multiple results for expressions that are represented by more than one type, so it will likely return a very large table of results.
84+
85+
Use ``getAQlClass()`` as a debugging tool, but don't include it in the final version of your query, as it slows down performance.
86+
6587
Avoid complex recursion
6688
~~~~~~~~~~~~~~~~~~~~~~~
6789

0 commit comments

Comments
 (0)