Skip to content

Commit 6090867

Browse files
author
Shati Patel
committed
Docs: Update Java
1 parent fbc11e5 commit 6090867

File tree

10 files changed

+76
-76
lines changed

10 files changed

+76
-76
lines changed

docs/language/learn-ql/java/annotations.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Tutorial: Annotations
44
Overview
55
--------
66

7-
Snapshots of Java projects contain information about all annotations attached to program elements.
7+
CodeQL databases of Java projects contain information about all annotations attached to program elements.
88

9-
In QL, annotations are represented as follows:
9+
Annotations are represented by the following CodeQL classes:
1010

1111
- The class ``Annotatable`` represents all entities that may have an annotation attached to them (that is, packages, reference types, fields, methods, and local variables).
1212
- The class ``AnnotationType`` represents a Java annotation type, such as ``java.lang.Override``; annotation types are interfaces.
@@ -23,7 +23,7 @@ As an example, recall that the Java standard library defines an annotation ``Sup
2323
String[] value;
2424
}
2525
26-
In QL, ``SuppressWarnings`` is represented as an ``AnnotationType``, with ``value`` as its only ``AnnotationElement``.
26+
``SuppressWarnings`` is represented as an ``AnnotationType``, with ``value`` as its only ``AnnotationElement``.
2727

2828
A typical usage of ``SuppressWarnings`` would be the following annotation to prevent a warning about using raw types:
2929

@@ -35,7 +35,7 @@ A typical usage of ``SuppressWarnings`` would be the following annotation to pre
3535
}
3636
}
3737
38-
In QL, the expression ``@SuppressWarnings("rawtypes")`` is represented as an ``Annotation``. The string literal ``"rawtypes"`` is used to initialize the annotation element ``value``, and its value can be extracted from the annotation by means of the ``getValue`` predicate.
38+
The expression ``@SuppressWarnings("rawtypes")`` is represented as an ``Annotation``. The string literal ``"rawtypes"`` is used to initialize the annotation element ``value``, and its value can be extracted from the annotation by means of the ``getValue`` predicate.
3939

4040
We could then write the following query to find all ``@SuppressWarnings`` annotations attached to constructors, and return both the annotation itself and the value of its ``value`` element:
4141

@@ -101,7 +101,7 @@ As a first step, let us write a query that finds all ``@Override`` annotations.
101101
where ann.getType().hasQualifiedName("java.lang", "Override")
102102
select ann
103103
104-
As always, it is a good idea to try this query on a Java snapshot 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 QL class:
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:
105105

106106
::
107107

@@ -147,7 +147,7 @@ For example, consider the following example program:
147147
148148
Here, both ``A.m`` and ``A.n`` are marked as deprecated. Methods ``n`` and ``r`` both call ``m``, but note that ``n`` itself is deprecated, so we probably should not warn about this call.
149149

150-
Like in the previous example, we start by defining a QL class for representing ``@Deprecated`` annotations:
150+
Like in the previous example, we start by defining a class for representing ``@Deprecated`` annotations:
151151

152152
.. code-block:: ql
153153
@@ -204,7 +204,7 @@ For instance, consider this slightly updated example:
204204
205205
Here, the programmer has explicitly suppressed warnings about deprecated calls in ``A.r``, so our query should not flag the call to ``A.m`` any more.
206206

207-
To do so, we first introduce a QL class for representing all ``@SuppressWarnings`` annotations where the string ``deprecated`` occurs among the list of warnings to suppress:
207+
To do so, we first introduce a class for representing all ``@SuppressWarnings`` annotations where the string ``deprecated`` occurs among the list of warnings to suppress:
208208

209209
.. code-block:: ql
210210
@@ -238,6 +238,6 @@ Now we can extend our query to filter out calls in methods carrying a ``Suppress
238238
What next?
239239
----------
240240

241-
- Take a look at some of the other tutorials: :doc:`Tutorial: Javadoc <javadoc>`, :doc:`Tutorial: Working with source locations <source-locations>`.
242-
- Find out how specific classes in the AST are represented in the QL standard library for Java: :doc:`AST class reference <ast-class-reference>`.
241+
- Take a look at some of the other tutorials: :doc:`Tutorial: Javadoc <javadoc>` and :doc:`Tutorial: Working with source locations <source-locations>`.
242+
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`AST class reference <ast-class-reference>`.
243243
- Find out more about QL in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__ and `QL language specification <https://help.semmle.com/QL/ql-spec/language.html>`__.

docs/language/learn-ql/java/ast-class-reference.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Statement classes
1515
This table lists all subclasses of `Stmt`_.
1616

1717
+------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+---------------------------------------------+
18-
| Statement syntax | QL class | Superclasses | Remarks |
18+
| Statement syntax | CodeQL class | Superclasses | Remarks |
1919
+========================================================================+===========================================================================================================================================================+===================================+=============================================+
2020
| ``;`` | `EmptyStmt <https://help.semmle.com/qldoc/java/semmle/code/java/Statement.qll/type.Statement$EmptyStmt.html>`__ | | |
2121
+------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+---------------------------------------------+
@@ -87,7 +87,7 @@ Literals
8787
All classes in this subsection are subclasses of `Literal <https://help.semmle.com/qldoc/java/semmle/code/java/Expr.qll/type.Expr$Literal.html>`__.
8888

8989
+---------------------------+--------------------------+
90-
| Expression syntax example | QL class |
90+
| Expression syntax example | CodeQL class |
9191
+===========================+==========================+
9292
| ``true`` | ``BooleanLiteral`` |
9393
+---------------------------+--------------------------+
@@ -112,7 +112,7 @@ Unary expressions
112112
All classes in this subsection are subclasses of `UnaryExpr <https://help.semmle.com/qldoc/java/semmle/code/java/Expr.qll/type.Expr$UnaryExpr.html>`__.
113113

114114
+---------------------------+-----------------+---------------------+---------------------------------------------------+
115-
| Expression syntax example | QL class | Superclasses | Remarks |
115+
| Expression syntax example | CodeQL class | Superclasses | Remarks |
116116
+===========================+=================+=====================+===================================================+
117117
| ``x++`` | ``PostIncExpr`` | ``UnaryAssignExpr`` | |
118118
+---------------------------+-----------------+---------------------+---------------------------------------------------+
@@ -137,7 +137,7 @@ Binary expressions
137137
All classes in this subsection are subclasses of `BinaryExpr <https://help.semmle.com/qldoc/java/semmle/code/java/Expr.qll/type.Expr$BinaryExpr.html>`__.
138138

139139
+---------------------------+--------------------+--------------------+
140-
| Expression syntax example | QL class | Superclasses |
140+
| Expression syntax example | CodeQL class | Superclasses |
141141
+===========================+====================+====================+
142142
| ``x * y`` | ``MulExpr`` | |
143143
+---------------------------+--------------------+--------------------+
@@ -184,7 +184,7 @@ Assignment expressions
184184
All classes in this table are subclasses of `Assignment <https://help.semmle.com/qldoc/java/semmle/code/java/Expr.qll/type.Expr$Assignment.html>`__.
185185

186186
+---------------------------+-----------------------+--------------+
187-
| Expression syntax example | QL class | Superclasses |
187+
| Expression syntax example | CodeQL class | Superclasses |
188188
+===========================+=======================+==============+
189189
| ``x = y`` | ``AssignExpr`` | |
190190
+---------------------------+-----------------------+--------------+
@@ -215,7 +215,7 @@ Accesses
215215
~~~~~~~~
216216

217217
+--------------------------------------+-------------------------------------------------------------------------------------------------------------------------+
218-
| Expression syntax examples | QL class |
218+
| Expression syntax examples | CodeQL class |
219219
+======================================+=========================================================================================================================+
220220
| ``this`` | `ThisAccess <https://help.semmle.com/qldoc/java/semmle/code/java/Expr.qll/type.Expr$ThisAccess.html>`__ |
221221
+--------------------------------------+ +
@@ -250,7 +250,7 @@ Miscellaneous
250250
~~~~~~~~~~~~~
251251

252252
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------+
253-
| Expression syntax examples | QL class | Remarks |
253+
| Expression syntax examples | CodeQL class | Remarks |
254254
+==================================================================+=======================================================================================================================+=============================================================================+
255255
| ``(int) f`` | `CastExpr <https://help.semmle.com/qldoc/java/semmle/code/java/Expr.qll/type.Expr$CastExpr.html>`__ | |
256256
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------+

docs/language/learn-ql/java/call-graph.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tutorial: Navigating the call graph
44
Call graph API
55
--------------
66

7-
The QL Java library 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``.
7+
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``.
88

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

@@ -160,6 +160,6 @@ Finally, on many Java projects there are methods that are invoked indirectly by
160160
What next?
161161
----------
162162

163-
- Find out how to query metadata and white space: :doc:`Tutorial: Annotations <annotations>`, :doc:`Tutorial: Javadoc <javadoc>`, :doc:`Tutorial: Working with source locations <source-locations>`.
164-
- Find out how specific classes in the AST are represented in the QL standard library for Java: :doc:`AST class reference <ast-class-reference>`.
163+
- Find out how to query metadata and white space: :doc:`Tutorial: Annotations <annotations>`, :doc:`Tutorial: Javadoc <javadoc>`, and :doc:`Tutorial: Working with source locations <source-locations>`.
164+
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`AST class reference <ast-class-reference>`.
165165
- Find out more about QL in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__ and `QL language specification <https://help.semmle.com/QL/ql-spec/language.html>`__.

docs/language/learn-ql/java/dataflow.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Analyzing data flow in Java
44
Overview
55
--------
66

7-
This topic describes how data flow analysis is implemented in the QL for Java library and includes examples to help you write your own data flow queries.
8-
The following sections describe how to utilize the QL libraries for local data flow, global data flow and taint tracking.
7+
This topic describes how data flow analysis is implemented in the CodeQL libraries for Java and includes examples to help you write your own data flow queries.
8+
The following sections describe how to utilize the libraries for local data flow, global data flow, and taint tracking.
99

10-
For a more general introduction to modeling data flow in QL, see :doc:`Introduction to data flow analysis in QL <../intro-to-data-flow>`.
10+
For a more general introduction to modeling data flow, see :doc:`Introduction to data flow analysis with CodeQL <../intro-to-data-flow>`.
1111

1212
Local data flow
1313
---------------

docs/language/learn-ql/java/expressions-statements.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ If ``l`` is bigger than 2\ :sup:`31`\ - 1 (the largest positive value of type ``
2222

2323
All primitive numeric types have a maximum value, beyond which they will wrap around to their lowest possible value (called an "overflow"). For ``int``, this maximum value is 2\ :sup:`31`\ - 1. Type ``long`` can accommodate larger values up to a maximum of 2\ :sup:`63`\ - 1. In this example, this means that ``l`` can take on a value that is higher than the maximum for type ``int``; ``i`` will never be able to reach this value, instead overflowing and returning to a low value.
2424

25-
We will develop a query that finds code that looks like it might exhibit this kind of behavior. We will be using several of the standard QL library classes for representing statements and functions, a full list of which can be found in the :doc:`AST class reference <ast-class-reference>`.
25+
We will develop a query that finds code that looks like it might exhibit this kind of behavior. We will be using several of the standard library classes for representing statements and functions, a full list of which can be found in the :doc:`AST class reference <ast-class-reference>`.
2626

2727
Initial query
2828
-------------
2929

30-
We start out by writing a query that finds less-than expressions (QL class ``LTExpr``) where the left operand is of type ``int`` and the right operand is of type ``long``:
30+
We start out by writing a query that finds less-than expressions (CodeQL class ``LTExpr``) where the left operand is of type ``int`` and the right operand is of type ``long``:
3131

3232
.. code-block:: ql
3333
@@ -57,7 +57,7 @@ Notice that we use the predicate ``getType`` (available on all subclasses of ``E
5757

5858
The class ``LoopStmt`` is a common superclass of all loops, including, in particular, ``for`` loops as in our example above. While different kinds of loops have different syntax, they all have a loop condition, which can be accessed through predicate ``getCondition``. We use the reflexive transitive closure operator ``*`` applied to the ``getAChildExpr`` predicate to express the requirement that ``expr`` should be nested inside the loop condition. In particular, it can be the loop condition itself.
5959

60-
The final conjunct in the ``where`` clause takes advantage of the fact that QL predicates can return more than one value (they are really relations). In particular, ``getAnOperand`` may return *either* operand of ``expr``, so ``expr.getAnOperand().isCompileTimeConstant()`` holds if at least one of the operands is constant. Negating this condition means that the query will only find expressions where *neither* of the operands is constant.
60+
The final conjunct in the ``where`` clause takes advantage of the fact that `predicates <https://help.semmle.com/QL/ql-handbook/predicates.html>`__ can return more than one value (they are really relations). In particular, ``getAnOperand`` may return *either* operand of ``expr``, so ``expr.getAnOperand().isCompileTimeConstant()`` holds if at least one of the operands is constant. Negating this condition means that the query will only find expressions where *neither* of the operands is constant.
6161

6262
Generalizing the query
6363
----------------------
@@ -76,7 +76,7 @@ In order to compare the ranges of types, we define a predicate that returns the
7676
(pt.hasName("long") and result=64)
7777
}
7878
79-
We now want to generalize our query to apply to any comparison where the width of the type on the smaller end of the comparison is less than the width of the type on the greater end. Let us call such a comparison *overflow prone*, and introduce an abstract QL class to model it:
79+
We now want to generalize our query to apply to any comparison where the width of the type on the smaller end of the comparison is less than the width of the type on the greater end. Let us call such a comparison *overflow prone*, and introduce an abstract class to model it:
8080

8181
.. code-block:: ql
8282
@@ -121,6 +121,6 @@ Now we rewrite our query to make use of these new classes:
121121
What next?
122122
----------
123123

124-
- Have a look at some of the other tutorials: :doc:`Tutorial: Types and the class hierarchy <types-class-hierarchy>`, :doc:`Tutorial: Navigating the call graph <call-graph>`, :doc:`Tutorial: Annotations <annotations>`, :doc:`Tutorial: Javadoc <javadoc>`, :doc:`Tutorial: Working with source locations <source-locations>`.
125-
- Find out how specific classes in the AST are represented in the QL standard library for Java: :doc:`AST class reference <ast-class-reference>`.
124+
- Have a look at some of the other tutorials: :doc:`Tutorial: Types and the class hierarchy <types-class-hierarchy>`, :doc:`Tutorial: Navigating the call graph <call-graph>`, :doc:`Tutorial: Annotations <annotations>`, :doc:`Tutorial: Javadoc <javadoc>`, and :doc:`Tutorial: Working with source locations <source-locations>`.
125+
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`AST class reference <ast-class-reference>`.
126126
- Find out more about QL in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__ and `QL language specification <https://help.semmle.com/QL/ql-spec/language.html>`__.

0 commit comments

Comments
 (0)