From 3fb3b9b54ab742226ba07585c7e778b7bce92df9 Mon Sep 17 00:00:00 2001 From: james Date: Mon, 10 Feb 2020 14:54:14 +0000 Subject: [PATCH] docs: add info about using getAQlClass() --- .../writing-queries/debugging-queries.rst | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/language/learn-ql/writing-queries/debugging-queries.rst b/docs/language/learn-ql/writing-queries/debugging-queries.rst index 68bb1bae9b7..b0b03321354 100644 --- a/docs/language/learn-ql/writing-queries/debugging-queries.rst +++ b/docs/language/learn-ql/writing-queries/debugging-queries.rst @@ -62,6 +62,28 @@ is preferred over:: From the type context, the query optimizer deduces that some parts of the program are redundant and removes them, or *specializes* them. +Determine the most specific types of a variable +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +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. + +For example, if you were working with a Java database, you might use ``getAQlClass()`` on every ``Expr`` in a callable called ``c``: + +.. code-block:: ql + + import java + + from Expr e, Callable c + where + c.getDeclaringType().hasQualifiedName("my.namespace.name", "MyClass") + and c.getName() = "c" + and e.getEnclosingCallable() = c + select e, e.getAQlClass() + +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. + +Use ``getAQlClass()`` as a debugging tool, but don't include it in the final version of your query, as it slows down performance. + Avoid complex recursion ~~~~~~~~~~~~~~~~~~~~~~~