You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/language/learn-ql/java/annotations.rst
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -167,7 +167,7 @@ Now we can define a class for representing deprecated methods:
167
167
}
168
168
}
169
169
170
-
Finally, we use these classes to find calls to deprecated methods, excluding calls that themselves appear in deprecated methods (see :doc:`Tutorial: Navigating the call graph <call-graph>` for more information on class ``Call``):
170
+
Finally, we use these classes to find calls to deprecated methods, excluding calls that themselves appear in deprecated methods:
171
171
172
172
.. code-block:: ql
173
173
@@ -178,7 +178,9 @@ Finally, we use these classes to find calls to deprecated methods, excluding cal
178
178
and not call.getCaller() instanceof DeprecatedMethod
179
179
select call, "This call invokes a deprecated method."
180
180
181
-
On our example, this query flags the call to ``A.m`` in ``A.r``, but not the one in ``A.n``.
181
+
In our example, this query flags the call to ``A.m`` in ``A.r``, but not the one in ``A.n``.
182
+
183
+
For more information about the class ``Call``, see :doc:`Navigating the call graph <call-graph>`.
182
184
183
185
Improvements
184
186
~~~~~~~~~~~~
@@ -238,6 +240,6 @@ Now we can extend our query to filter out calls in methods carrying a ``Suppress
238
240
Further reading
239
241
---------------
240
242
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>`.
243
+
- Take a look at some of the other articles in this section: :doc:`Javadoc <javadoc>` and :doc:`Working with source locations <source-locations>`.
244
+
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`Classes for working with Java code<ast-class-reference>`.
243
245
- 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>`__.
Copy file name to clipboardExpand all lines: docs/language/learn-ql/java/call-graph.rst
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
Navigating the call graph
2
2
=========================
3
3
4
-
CodeQL provides an API 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.
4
+
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.
5
5
6
-
Call graph API
7
-
--------------
6
+
Call graph classes
7
+
------------------
8
8
9
9
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``.
10
10
@@ -68,7 +68,7 @@ In our example, ``Client.main`` calls the constructor ``Sub(int)`` and the metho
68
68
Example: Finding unused methods
69
69
-------------------------------
70
70
71
-
Given this API, we can easily write a query that finds methods that are not called by any other method:
71
+
We can use the ``Callable`` class to write a query that finds methods that are not called by any other method:
72
72
73
73
.. code-block:: ql
74
74
@@ -164,6 +164,6 @@ Finally, on many Java projects there are methods that are invoked indirectly by
164
164
Further reading
165
165
---------------
166
166
167
-
- 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>`.
168
-
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`AST class reference<ast-class-reference>`.
167
+
- Find out how to query metadata and white space: :doc:`Annotations in Java <annotations>`, :doc:`Javadoc <javadoc>`, and :doc:`Working with source locations <source-locations>`.
168
+
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`Classes for working with Java code<ast-class-reference>`.
169
169
- 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>`__.
Copy file name to clipboardExpand all lines: docs/language/learn-ql/java/dataflow.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -256,7 +256,7 @@ Exercise 4: Using the answers from 2 and 3, write a query which finds all global
256
256
What next?
257
257
----------
258
258
259
-
- Try the worked examples in these articles: :doc:`Tutorial: Navigating the call graph <call-graph>` and :doc:`Tutorial: Working with source locations <source-locations>`.
259
+
- Try the worked examples in these articles: :doc:`Navigating the call graph <call-graph>` and :doc:`Working with source locations <source-locations>`.
260
260
- 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>`__.
261
261
- Learn more about the query console in `Using the query console <https://lgtm.com/help/lgtm/using-query-console>`__.
Copy file name to clipboardExpand all lines: docs/language/learn-ql/java/expressions-statements.rst
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
Expressions and statements in Java
1
+
Overflow-prone comparisons in Java
2
2
==================================
3
3
4
4
You can use CodeQL to check for comparisons in Java code where one side of the comparison is prone to overflow.
@@ -26,7 +26,7 @@ If ``l`` is bigger than 2\ :sup:`31`\ - 1 (the largest positive value of type ``
26
26
27
27
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.
28
28
29
-
We're going to develop a query that finds code that looks like it might exhibit this kind of behavior. We'll 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>`.
29
+
We're going to develop a query that finds code that looks like it might exhibit this kind of behavior. We'll be using several of the standard library classes for representing statements and functions. For a full list, see :doc:`Classes for working with Java code<ast-class-reference>`.
30
30
31
31
Initial query
32
32
-------------
@@ -125,6 +125,6 @@ Now we rewrite our query to make use of these new classes:
125
125
Further reading
126
126
---------------
127
127
128
-
- 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>`.
129
-
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`AST class reference<ast-class-reference>`.
128
+
- Have a look at some of the other articles in this section: :doc:`Java types <types-class-hierarchy>`, :doc:`Navigating the call graph <call-graph>`, :doc:`Annotations in Java <annotations>`, :doc:`Javadoc <javadoc>`, and :doc:`Working with source locations <source-locations>`.
129
+
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`Classes for working with Java code<ast-class-reference>`.
130
130
- 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>`__.
Copy file name to clipboardExpand all lines: docs/language/learn-ql/java/introduce-libraries-java.rst
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
CodeQL library for Java
2
2
=======================
3
3
4
-
When you need to analyze a Java program, you can make use of the large collection of classes in the Java library for CodeQL.
4
+
When you're analyzing a Java program in {{ site.data.variables.product.prodname_dotcom }}, you can make use of the large collection of classes in the CodeQL library for Java.
5
5
6
-
About the Java library
7
-
----------------------
6
+
About the CodeQL library for Java
7
+
---------------------------------
8
8
9
9
There is an extensive library for analyzing CodeQL databases extracted from Java projects. The classes in this library present the data from a database in an object-oriented form and provide abstractions and predicates to help you with common analysis tasks.
10
10
@@ -14,13 +14,13 @@ The library is implemented as a set of QL modules, that is, files with the exten
14
14
15
15
import java
16
16
17
-
The rest of this topic briefly summarizes the most important classes and predicates provided by this library.
17
+
The rest of this article briefly summarizes the most important classes and predicates provided by this library.
18
18
19
19
.. pull-quote::
20
20
21
21
Note
22
22
23
-
The example queries in this topic illustrate the types of results returned by different library classes. The results themselves are not interesting but can be used as the basis for developing a more complex query. The tutorial topics show how you can take a simple query and fine-tune it to find precisely the results you're interested in.
23
+
The example queries in this article illustrate the types of results returned by different library classes. The results themselves are not interesting but can be used as the basis for developing a more complex query. The other articles in this section of the help show how you can take a simple query and fine-tune it to find precisely the results you're interested in.
24
24
25
25
Summary of the library classes
26
26
------------------------------
@@ -196,7 +196,7 @@ The wildcards ``? extends Number`` and ``? super Float`` are represented by clas
196
196
197
197
For dealing with generic methods, there are classes ``GenericMethod``, ``ParameterizedMethod`` and ``RawMethod``, which are entirely analogous to the like-named classes for representing generic types.
198
198
199
-
For more information on working with types, see the :doc:`tutorial on types and the class hierarchy<types-class-hierarchy>`.
199
+
For more information on working with types, see the :doc:`article on Java types<types-class-hierarchy>`.
200
200
201
201
Variables
202
202
~~~~~~~~~
@@ -210,7 +210,7 @@ Class ``Variable`` represents a variable `in the Java sense <http://docs.oracle.
210
210
Abstract syntax tree
211
211
--------------------
212
212
213
-
Classes in this category represent abstract syntax tree (AST) nodes, that is, statements (class ``Stmt``) and expressions (class ``Expr``). See the :doc:`AST class reference <ast-class-reference>` for an exhaustive list of all expression and statement types available in the standard QL library.
213
+
Classes in this category represent abstract syntax tree (AST) nodes, that is, statements (class ``Stmt``) and expressions (class ``Expr``). For a full list of expression and statement types available in the standard QL library, see :doc:`Classes for working with Java code <ast-class-reference>`.
214
214
215
215
Both ``Expr`` and ``Stmt`` provide member predicates for exploring the abstract syntax tree of a program:
216
216
@@ -260,7 +260,7 @@ Finally, here is a query that finds method bodies:
260
260
261
261
As these examples show, the parent node of an expression is not always an expression: it may also be a statement, for example, an ``IfStmt``. Similarly, the parent node of a statement is not always a statement: it may also be a method or a constructor. To capture this, the QL Java library provides two abstract class ``ExprParent`` and ``StmtParent``, the former representing any node that may be the parent node of an expression, and the latter any node that may be the parent node of a statement.
262
262
263
-
For more information on working with AST classes, see the :doc:`tutorial on expressions and statements<expressions-statements>`.
263
+
For more information on working with AST classes, see the :doc:`article on overflow-prone comparisons in Java<expressions-statements>`.
264
264
265
265
Metadata
266
266
--------
@@ -292,7 +292,7 @@ These annotations are represented by class ``Annotation``. An annotation is simp
292
292
293
293
➤ `See this in the query console <https://lgtm.com/query/659662167/>`__. Only constructors with the ``@deprecated`` annotation are reported this time.
294
294
295
-
For more information on working with annotations, see the :doc:`tutorial on annotations <annotations>`.
295
+
For more information on working with annotations, see the :doc:`article on annotations <annotations>`.
296
296
297
297
For Javadoc, class ``Element`` has a member predicate ``getDoc`` that returns a delegate ``Documentable`` object, which can then be queried for its attached Javadoc comments. For example, the following query finds Javadoc comments on private fields:
298
298
@@ -327,7 +327,7 @@ Class ``Javadoc`` represents an entire Javadoc comment as a tree of ``JavadocEle
327
327
328
328
On line 5 we used ``getParent+`` to capture tags that are nested at any depth within the Javadoc comment.
329
329
330
-
For more information on working with Javadoc, see the :doc:`tutorial on Javadoc <javadoc>`.
330
+
For more information on working with Javadoc, see the :doc:`article on Javadoc <javadoc>`.
331
331
332
332
Metrics
333
333
-------
@@ -381,11 +381,11 @@ Conversely, ``Callable.getAReference`` returns a ``Call`` that refers to it. So
381
381
382
382
➤ `See this in the query console <https://lgtm.com/query/666680036/>`__. The LGTM.com demo projects all appear to have many methods that are not called directly, but this is unlikely to be the whole story. To explore this area further, see :doc:`Navigating the call graph <call-graph>`.
383
383
384
-
For more information about callables and calls, see the :doc:`call graph tutorial<call-graph>`.
384
+
For more information about callables and calls, see the :doc:`article on the call graph <call-graph>`.
385
385
386
386
Further reading
387
387
---------------
388
388
389
-
- Experiment with the worked examples in the CodeQL for Java tutorial topics: :doc:`Types and the class hierarchy <types-class-hierarchy>`, :doc:`Expressions and statements <expressions-statements>`, :doc:`Navigating the call graph <call-graph>`, :doc:`Annotations <annotations>`, :doc:`Javadoc <javadoc>` and :doc:`Working with source locations <source-locations>`.
390
-
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`AST class reference<ast-class-reference>`.
389
+
- Experiment with the worked examples in the CodeQL for Java articles: :doc:`Java types <types-class-hierarchy>`, :doc:`Overflow-prone comparisons in Java <expressions-statements>`, :doc:`Navigating the call graph <call-graph>`, :doc:`Annotations in Java<annotations>`, :doc:`Javadoc <javadoc>` and :doc:`Working with source locations <source-locations>`.
390
+
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`Classes for working with Java code<ast-class-reference>`.
391
391
- 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>`__.
Copy file name to clipboardExpand all lines: docs/language/learn-ql/java/javadoc.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -221,6 +221,6 @@ Currently, ``visibleIn`` only considers single-type imports, but you could exten
221
221
Further reading
222
222
---------------
223
223
224
-
- Find out how you can use the location API to define queries on whitespace: :doc:`Tutorial: Working with source locations <source-locations>`.
225
-
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`AST class reference<ast-class-reference>`.
224
+
- Find out how you can use the location API to define queries on whitespace: :doc:`Working with source locations <source-locations>`.
225
+
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`Classes for working with Java code<ast-class-reference>`.
226
226
- 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>`__.
Copy file name to clipboardExpand all lines: docs/language/learn-ql/java/source-locations.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
Working with source locations
2
2
=============================
3
3
4
-
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.
4
+
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.
5
5
6
6
About source locations
7
7
----------------------
@@ -186,5 +186,5 @@ Whitespace suggests that the programmer meant to toggle ``i`` between zero and o
186
186
Further reading
187
187
---------------
188
188
189
-
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`AST class reference<ast-class-reference>`.
189
+
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`Classes for working with Java code<ast-class-reference>`.
190
190
- 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>`__.
Copy file name to clipboardExpand all lines: docs/language/learn-ql/java/types-class-hierarchy.rst
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
-
Types in Java
2
-
=============
1
+
Java types
2
+
==========
3
3
4
4
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.
5
5
@@ -299,6 +299,6 @@ Adding these three improvements, our final query becomes:
299
299
Further reading
300
300
---------------
301
301
302
-
- Take a look at some of the other tutorials: :doc:`Tutorial: Expressions and statements<expressions-statements>`, :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>`.
303
-
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`AST class reference<ast-class-reference>`.
302
+
- Take a look at some of the other articles in this section: :doc:`Overflow-prone comparisons in Java<expressions-statements>`, :doc:`Navigating the call graph <call-graph>`, :doc:`Annotations in Java <annotations>`, :doc:`Javadoc <javadoc>`, and :doc:`Working with source locations <source-locations>`.
303
+
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`Classes for working with Java code<ast-class-reference>`.
304
304
- 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