Skip to content

Commit ee9873f

Browse files
committed
add kotlin to Java language guides
1 parent 27817ea commit ee9873f

10 files changed

+42
-28
lines changed

docs/codeql/codeql-language-guides/abstract-syntax-tree-classes-for-working-with-java-programs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. _abstract-syntax-tree-classes-for-working-with-java-programs:
22

3-
Abstract syntax tree classes for working with Java programs
3+
Abstract syntax tree classes for working with Java and Kotlin programs
44
===========================================================
55

66
CodeQL has a large selection of classes for representing the abstract syntax tree of Java and Kotlin programs.

docs/codeql/codeql-language-guides/annotations-in-java.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
.. _annotations-in-java:
22

3-
Annotations in Java
3+
Annotations in Java and Kotlin
44
===================
55

6-
CodeQL databases of Java projects contain information about all annotations attached to program elements.
6+
CodeQL databases of Java/Kotlin projects contain information about all annotations attached to program elements.
7+
8+
.. include:: ../reusables/kotlin-beta-note.rst
79

810
About working with annotations
911
------------------------------
@@ -15,7 +17,7 @@ Annotations are represented by these CodeQL classes:
1517
- The class ``AnnotationElement`` represents an annotation element, that is, a member of an annotation type.
1618
- The class ``Annotation`` represents an annotation such as ``@Override``; annotation values can be accessed through member predicate ``getValue``.
1719

18-
For example, the Java standard library defines an annotation ``SuppressWarnings`` that instructs the compiler not to emit certain kinds of warnings:
20+
For example, the Java/Kotlin standard library defines an annotation ``SuppressWarnings`` that instructs the compiler not to emit certain kinds of warnings:
1921

2022
.. code-block:: java
2123
@@ -101,7 +103,7 @@ As a first step, let's write a query that finds all ``@Override`` annotations. A
101103
where ann.getType().hasQualifiedName("java.lang", "Override")
102104
select ann
103105
104-
As always, it is a good idea to try this query on a CodeQL database for a Java project to make sure it actually produces some results. On the earlier example, it should find the annotation on ``Sub1.m``. Next, we encapsulate the concept of an ``@Override`` annotation as a CodeQL class:
106+
As always, it is a good idea to try this query on a CodeQL database for a Java/Kotlin project to make sure it actually produces some results. On the earlier example, it should find the annotation on ``Sub1.m``. Next, we encapsulate the concept of an ``@Override`` annotation as a CodeQL class:
105107

106108
::
107109

@@ -185,7 +187,7 @@ For more information about the class ``Call``, see ":doc:`Navigating the call gr
185187
Improvements
186188
~~~~~~~~~~~~
187189

188-
The Java standard library provides another annotation type ``java.lang.SupressWarnings`` that can be used to suppress certain categories of warnings. In particular, it can be used to turn off warnings about calls to deprecated methods. Therefore, it makes sense to improve our query to ignore calls to deprecated methods from inside methods that are marked with ``@SuppressWarnings("deprecation")``.
190+
The Java/Kotlin standard library provides another annotation type ``java.lang.SupressWarnings`` that can be used to suppress certain categories of warnings. In particular, it can be used to turn off warnings about calls to deprecated methods. Therefore, it makes sense to improve our query to ignore calls to deprecated methods from inside methods that are marked with ``@SuppressWarnings("deprecation")``.
189191

190192
For instance, consider this slightly updated example:
191193

docs/codeql/codeql-language-guides/codeql-for-java.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ Experiment and learn how to write effective and efficient queries for CodeQL dat
3232

3333
- :doc:`Analyzing data flow in Java and Kotlin <analyzing-data-flow-in-java>`: You can use CodeQL to track the flow of data through a Java/Kotlin program to its use.
3434

35-
- :doc:`Java types <types-in-java>`: You can use CodeQL to find out information about data types used in Java code. This allows you to write queries to identify specific type-related issues.
35+
- :doc:`Java and Kotlin types <types-in-java>`: You can use CodeQL to find out information about data types used in Java/Kotlin code. This allows you to write queries to identify specific type-related issues.
3636

37-
- :doc:`Overflow-prone comparisons in Java <overflow-prone-comparisons-in-java>`: You can use CodeQL to check for comparisons in Java code where one side of the comparison is prone to overflow.
37+
- :doc:`Overflow-prone comparisons in Java and Kotlin <overflow-prone-comparisons-in-java>`: You can use CodeQL to check for comparisons in Java/Kotlin code where one side of the comparison is prone to overflow.
3838

3939
- :doc:`Navigating the call graph <navigating-the-call-graph>`: CodeQL has classes for identifying code that calls other code, and code that can be called from elsewhere. This allows you to find, for example, methods that are never used.
4040

41-
- :doc:`Annotations in Java <annotations-in-java>`: CodeQL databases of Java projects contain information about all annotations attached to program elements.
41+
- :doc:`Annotations in Java and Kotlin <annotations-in-java>`: CodeQL databases of Java/Kotlin projects contain information about all annotations attached to program elements.
4242

43-
- :doc:`Javadoc <javadoc>`: You can use CodeQL to find errors in Javadoc comments in Java code.
43+
- :doc:`Javadoc <javadoc>`: You can use CodeQL to find errors in Javadoc comments in Java/Kotlin code.
4444

45-
- :doc:`Working with source locations <working-with-source-locations>`: You can use the location of entities within Java code to look for potential errors. Locations allow you to deduce the presence, or absence, of white space which, in some cases, may indicate a problem.
45+
- :doc:`Working with source locations <working-with-source-locations>`: You can use the location of entities within Java/Kotlin code to look for potential errors. Locations allow you to deduce the presence, or absence, of white space which, in some cases, may indicate a problem.
4646

4747
- :doc:`Abstract syntax tree classes for working with Java and Kotlin programs <abstract-syntax-tree-classes-for-working-with-java-programs>`: CodeQL has a large selection of classes for representing the abstract syntax tree of Java/Kotlin programs.

docs/codeql/codeql-language-guides/codeql-library-for-java.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ CodeQL library for Java and Kotlin
55

66
When you're analyzing a Java/Kotlin program, you can make use of the large collection of classes in the CodeQL library for Java/Kotlin.
77

8+
.. include:: ../reusables/kotlin-beta-note.rst
9+
810
About the CodeQL library for Java and Kotlin
911
--------------------------------------------
1012

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
:orphan:
44
:nosearch:
55

6-
Customizing Library Models for Java
6+
Customizing Library Models for Java and Kotlin
77
===================================
88

99
.. include:: ../reusables/beta-note-customizing-library-models.rst
1010

11-
The Java analysis can be customized by adding library models (summaries, sinks and sources) in data extension files.
11+
.. include:: ../reusables/kotlin-beta-note.rst
12+
13+
The Java/Kotlin analysis can be customized by adding library models (summaries, sinks and sources) in data extension files.
1214
A model is a definition of a behavior of a library element, such as a method, that is used to improve the data flow analysis precision by identifying more results.
1315
Most of the security related queries are taint tracking queries that try to find paths from a source of untrusted input to a sink that represents a vulnerability. Sources are the starting points of a taint tracking data flow analysis, and sinks are the end points of a taint tracking data flow analysis.
1416

@@ -30,7 +32,7 @@ A data extension file for Java is a YAML file in the form:
3032
3133
Data extensions contribute to the extensible predicates defined in the CodeQL library. For more information on how to define data extensions and extensible predicates as well as how to wire them up, see the :ref:`data-extensions` documentation.
3234

33-
The CodeQL library for Java exposes the following extensible predicates:
35+
The CodeQL library for Java/Kotlin exposes the following extensible predicates:
3436

3537
- **sourceModel**\(package, type, subtypes, name, signature, ext, output, kind, provenance). This is used for **source** models.
3638
- **sinkModel**\(package, type, subtypes, name, signature, ext, input, kind, provenance). This is used for **sink** models.
@@ -48,7 +50,7 @@ Example: Taint sink in the **java.sql** package
4850

4951
In this example we will show how to model the argument of the **execute** method as a SQL injection sink.
5052
This is the **execute** method in the **Statement** class, which is located in the **java.sql** package.
51-
Note that this sink is already added to the CodeQL Java analysis.
53+
Note that this sink is already added to the CodeQL Java/Kotlin analysis.
5254

5355
.. code-block:: java
5456
@@ -89,7 +91,7 @@ Example: Taint source from the **java.net** package
8991
----------------------------------------------------
9092
In this example we show how to model the return value from the **getInputStream** method as a **remote** source.
9193
This is the **getInputStream** method in the **Socket** class, which is located in the **java.net** package.
92-
Note that this source is already added to the CodeQL Java analysis.
94+
Note that this source is already added to the CodeQL Java/Kotlin analysis.
9395

9496
.. code-block:: java
9597
@@ -130,7 +132,7 @@ Example: Add flow through the **concat** method
130132
------------------------------------------------
131133
In this example we show how to model flow through a method for a simple case.
132134
This pattern covers many of the cases where we need to define flow through a method.
133-
Note that the flow through the **concat** method is already added to the CodeQL Java analysis.
135+
Note that the flow through the **concat** method is already added to the CodeQL Java/Kotlin analysis.
134136

135137
.. code-block:: java
136138
@@ -178,7 +180,7 @@ Example: Add flow through the **map** method
178180
---------------------------------------------
179181
In this example, we will see a more complex example of modeling flow through a method.
180182
This pattern shows how to model flow through higher order methods and collection types.
181-
Note that the flow through the **map** method is already added to the CodeQL Java analysis.
183+
Note that the flow through the **map** method is already added to the CodeQL Java/Kotlin analysis.
182184

183185
.. code-block:: java
184186
@@ -238,7 +240,7 @@ Example: Add a **neutral** method
238240
----------------------------------
239241
In this example we will show how to model the **now** method as being neutral with respect to flow.
240242
A neutral model is used to define that there is no flow through a method.
241-
Note that the neutral model for the **now** method is already added to the CodeQL Java analysis.
243+
Note that the neutral model for the **now** method is already added to the CodeQL Java/Kotlin analysis.
242244

243245
.. code-block:: java
244246

docs/codeql/codeql-language-guides/javadoc.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Javadoc
44
=======
55

6-
You can use CodeQL to find errors in Javadoc comments in Java code.
6+
You can use CodeQL to find errors in Javadoc comments in Java/Kotlin code.
7+
8+
.. include:: ../reusables/kotlin-beta-note.rst
79

810
About analyzing Javadoc
911
-----------------------

docs/codeql/codeql-language-guides/navigating-the-call-graph.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CodeQL has classes for identifying code that calls other code, and code that can
88
Call graph classes
99
------------------
1010

11-
The CodeQL library for Java provides two abstract classes for representing a program's call graph: ``Callable`` and ``Call``. The former is simply the common superclass of ``Method`` and ``Constructor``, the latter is a common superclass of ``MethodAccess``, ``ClassInstanceExpression``, ``ThisConstructorInvocationStmt`` and ``SuperConstructorInvocationStmt``. Simply put, a ``Callable`` is something that can be invoked, and a ``Call`` is something that invokes a ``Callable``.
11+
The CodeQL library for Java/Kotlin provides two abstract classes for representing a program's call graph: ``Callable`` and ``Call``. The former is simply the common superclass of ``Method`` and ``Constructor``, the latter is a common superclass of ``MethodAccess``, ``ClassInstanceExpression``, ``ThisConstructorInvocationStmt`` and ``SuperConstructorInvocationStmt``. Simply put, a ``Callable`` is something that can be invoked, and a ``Call`` is something that invokes a ``Callable``.
1212

1313
For example, in the following program all callables and calls have been annotated with comments:
1414

@@ -88,7 +88,7 @@ This simple query typically returns a large number of results.
8888

8989
We have to use ``polyCalls`` instead of ``calls`` here: we want to be reasonably sure that ``callee`` is not called, either directly or via overriding.
9090

91-
Running this query on a typical Java project results in lots of hits in the Java standard library. This makes sense, since no single client program uses every method of the standard library. More generally, we may want to exclude methods and constructors from compiled libraries. We can use the predicate ``fromSource`` to check whether a compilation unit is a source file, and refine our query:
91+
Running this query on a typical Java/Kotlin project results in lots of hits in the Java/Kotlin standard library. This makes sense, since no single client program uses every method of the standard library. More generally, we may want to exclude methods and constructors from compiled libraries. We can use the predicate ``fromSource`` to check whether a compilation unit is a source file, and refine our query:
9292

9393
.. code-block:: ql
9494

docs/codeql/codeql-language-guides/overflow-prone-comparisons-in-java.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
.. _overflow-prone-comparisons-in-java:
22

3-
Overflow-prone comparisons in Java
3+
Overflow-prone comparisons in Java and Kotlin
44
==================================
55

6-
You can use CodeQL to check for comparisons in Java code where one side of the comparison is prone to overflow.
6+
You can use CodeQL to check for comparisons in Java/Kotlin code where one side of the comparison is prone to overflow.
7+
8+
.. include:: ../reusables/kotlin-beta-note.rst
79

810
About this article
911
------------------

docs/codeql/codeql-language-guides/types-in-java.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
.. _types-in-java:
22

3-
Types in Java
3+
Types in Java and Kotlin
44
=============
55

6-
You can use CodeQL to find out information about data types used in Java code. This allows you to write queries to identify specific type-related issues.
6+
You can use CodeQL to find out information about data types used in Java/Kotlin code. This allows you to write queries to identify specific type-related issues.
7+
8+
.. include:: ../reusables/kotlin-beta-note.rst
79

810
About working with Java types
911
-----------------------------

docs/codeql/codeql-language-guides/working-with-source-locations.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Working with source locations
44
=============================
55

6-
You can use the location of entities within Java code to look for potential errors. Locations allow you to deduce the presence, or absence, of white space which, in some cases, may indicate a problem.
6+
You can use the location of entities within Java/Kotlin code to look for potential errors. Locations allow you to deduce the presence, or absence, of white space which, in some cases, may indicate a problem.
7+
8+
.. include:: ../reusables/kotlin-beta-note.rst
79

810
About source locations
911
----------------------
@@ -175,7 +177,7 @@ Now we can extend our query to discard results where the outer and the inner exp
175177
wsinner > wsouter
176178
select outer, "Whitespace around nested operators contradicts precedence."
177179
178-
Notice that we again use ``getOp``, this time to determine whether two binary expressions have the same operator. Running our improved query now finds the Java standard library bug described in the Overview. It also flags up the following suspicious code in `Hadoop HBase <https://hbase.apache.org/>`__:
180+
Notice that we again use ``getOp``, this time to determine whether two binary expressions have the same operator. Running our improved query now finds the Java/Kotlin standard library bug described in the Overview. It also flags up the following suspicious code in `Hadoop HBase <https://hbase.apache.org/>`__:
179181

180182
.. code-block:: java
181183

0 commit comments

Comments
 (0)