Skip to content

Commit 268e9ea

Browse files
committed
Add section on specifying java types
1 parent ab1bc85 commit 268e9ea

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

docs/codeql/codeql-language-guides/customizing-library-models-for-java-and-kotlin.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,26 @@ The CodeQL library for Java and Kotlin analysis exposes the following extensible
6969

7070
The extensible predicates are populated using the models defined in data extension files.
7171

72+
Specifying types in Java and Kotlin models
73+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74+
75+
**Nested and inner classes** are denoted by joining the enclosing type and the nested type with a dollar sign (``$``), for example ``Outer$Inner``. This applies both to the type column and to nested types in a signature. For example, the ``Level`` enum nested inside the ``Logger`` interface, nested inside the ``System`` class, is written as ``System$Logger$Level``:
76+
77+
.. code-block:: yaml
78+
79+
- ["java.lang", "System$Logger", True, "log", "(System$Logger$Level,String)", "", "Argument[1]", "log-injection", "manual"]
80+
81+
**Generics** are erased, so type parameters are removed:
82+
83+
- In the type column, leave out any type parameters, so ``List<E>`` becomes ``List``.
84+
- In the signature, replace each type parameter with its upper bound, or ``Object`` if it has none. So ``T`` from ``<T>`` becomes ``Object``, and ``T`` from ``<T extends Number>`` becomes ``Number``.
85+
86+
For example, ``forEach`` on ``Iterable<T>`` takes a ``Consumer<? super T>`` argument, so the type is ``Iterable`` and the signature is ``(Consumer)``:
87+
88+
.. code-block:: yaml
89+
90+
- ["java.lang", "Iterable", True, "forEach", "(Consumer)", "", "Argument[this].Element", "Argument[0].Parameter[0]", "value", "manual"]
91+
7292
Examples of custom model definitions
7393
------------------------------------
7494

0 commit comments

Comments
 (0)