Skip to content

Commit fab7955

Browse files
committed
Make small editorial changes
1 parent fdbc748 commit fab7955

8 files changed

Lines changed: 101 additions & 101 deletions

File tree

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ Annotations in Java
33

44
CodeQL databases of Java projects contain information about all annotations attached to program elements.
55

6-
Overview
7-
--------
6+
About working with annotations
7+
------------------------------
88

9-
Annotations are represented by the following CodeQL classes:
9+
Annotations are represented by these 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.
1313
- The class ``AnnotationElement`` represents an annotation element, that is, a member of an annotation type.
1414
- The class ``Annotation`` represents an annotation such as ``@Override``; annotation values can be accessed through member predicate ``getValue``.
1515

16-
As an example, recall that the Java standard library defines an annotation ``SuppressWarnings`` that instructs the compiler not to emit certain kinds of warnings. It is defined as follows:
16+
For example, the Java standard library defines an annotation ``SuppressWarnings`` that instructs the compiler not to emit certain kinds of warnings:
1717

1818
.. code-block:: java
1919
@@ -25,7 +25,7 @@ As an example, recall that the Java standard library defines an annotation ``Sup
2525
2626
``SuppressWarnings`` is represented as an ``AnnotationType``, with ``value`` as its only ``AnnotationElement``.
2727

28-
A typical usage of ``SuppressWarnings`` would be the following annotation to prevent a warning about using raw types:
28+
A typical usage of ``SuppressWarnings`` would be this annotation for preventing a warning about using raw types:
2929

3030
.. code-block:: java
3131
@@ -37,7 +37,7 @@ A typical usage of ``SuppressWarnings`` would be the following annotation to pre
3737
3838
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

40-
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:
40+
We could then write this query to find all ``@SuppressWarnings`` annotations attached to constructors, and return both the annotation itself and the value of its ``value`` element:
4141

4242
.. code-block:: ql
4343
@@ -69,9 +69,9 @@ As another example, this query finds all annotation types that only have a singl
6969
Example: Finding missing ``@Override`` annotations
7070
--------------------------------------------------
7171

72-
In newer versions of Java, it is recommended (though not required) to annotate methods that override another method with an ``@Override`` annotation. These annotations, which are checked by the compiler, serve as documentation, and also help you avoid accidental overloading where overriding was intended.
72+
In newer versions of Java, it's recommended (though not required) that you annotate methods that override another method with an ``@Override`` annotation. These annotations, which are checked by the compiler, serve as documentation, and also help you avoid accidental overloading where overriding was intended.
7373

74-
For example, consider the following example program:
74+
For example, consider this example program:
7575

7676
.. code-block:: java
7777
@@ -89,9 +89,9 @@ For example, consider the following example program:
8989
9090
Here, both ``Sub1.m`` and ``Sub2.m`` override ``Super.m``, but only ``Sub1.m`` is annotated with ``@Override``.
9191

92-
We will now develop a query for finding methods like ``Sub2.m`` that should be annotated with ``@Override``, but are not.
92+
We'll now develop a query for finding methods like ``Sub2.m`` that should be annotated with ``@Override``, but are not.
9393

94-
As a first step, let us write a query that finds all ``@Override`` annotations. Annotations are expressions, so their type can be accessed using ``getType``. Annotation types, on the other hand, are interfaces, so their qualified name can be queried using ``hasQualifiedName``. Therefore we can implement the query as follows:
94+
As a first step, let's write a query that finds all ``@Override`` annotations. Annotations are expressions, so their type can be accessed using ``getType``. Annotation types, on the other hand, are interfaces, so their qualified name can be queried using ``hasQualifiedName``. Therefore we can implement the query like this:
9595

9696
.. code-block:: ql
9797
@@ -111,7 +111,7 @@ As always, it is a good idea to try this query on a CodeQL database for a Java p
111111
}
112112
}
113113

114-
This makes it very easy to write our query for finding methods that override another method, but do not have an ``@Override`` annotation: we use predicate ``overrides`` to find out whether one method overrides another, and predicate ``getAnAnnotation`` (available on any ``Annotatable``) to retrieve some annotation.
114+
This makes it very easy to write our query for finding methods that override another method, but don't have an ``@Override`` annotation: we use predicate ``overrides`` to find out whether one method overrides another, and predicate ``getAnAnnotation`` (available on any ``Annotatable``) to retrieve some annotation.
115115

116116
.. code-block:: ql
117117
@@ -122,14 +122,14 @@ This makes it very easy to write our query for finding methods that override ano
122122
not overriding.getAnAnnotation() instanceof OverrideAnnotation
123123
select overriding, "Method overrides another method, but does not have an @Override annotation."
124124
125-
➤ `See this in the query console <https://lgtm.com/query/1505752756202/>`__. In practice, this query may yield many results from compiled library code, which are not very interesting. Therefore, it is a good idea to add another conjunct ``overriding.fromSource()`` to restrict the result to only report methods for which source code is available.
125+
➤ `See this in the query console <https://lgtm.com/query/1505752756202/>`__. In practice, this query may yield many results from compiled library code, which aren't very interesting. It's therefore a good idea to add another conjunct ``overriding.fromSource()`` to restrict the result to only report methods for which source code is available.
126126

127127
Example: Finding calls to deprecated methods
128128
--------------------------------------------
129129

130130
As another example, we can write a query that finds calls to methods marked with a ``@Deprecated`` annotation.
131131

132-
For example, consider the following example program:
132+
For example, consider this example program:
133133

134134
.. code-block:: java
135135
@@ -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 class for representing ``@Deprecated`` annotations:
150+
As in the previous example, we'll start by defining a class for representing ``@Deprecated`` annotations:
151151

152152
.. code-block:: ql
153153
@@ -235,8 +235,8 @@ Now we can extend our query to filter out calls in methods carrying a ``Suppress
235235
236236
➤ `See this in the query console <https://lgtm.com/query/665760001>`__. It's fairly common for projects to contain calls to methods that appear to be deprecated.
237237

238-
What next?
239-
----------
238+
Further reading
239+
---------------
240240

241241
- Take a look at some of the other tutorials: :doc:`Tutorial: Javadoc <javadoc>` and :doc:`Tutorial: Working with source locations <source-locations>`.
242242
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`AST class reference <ast-class-reference>`.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Class ``Call`` provides two call graph navigation predicates:
5858

5959
For instance, in our example ``getCallee`` of the second call in ``Client.main`` would return ``Super.getX``. At runtime, though, this call would actually invoke ``Sub.getX``.
6060

61-
Class ``Callable`` defines a large number of member predicates; for our purposes, the two most important ones are as follows:
61+
Class ``Callable`` defines a large number of member predicates; for our purposes, the two most important ones are:
6262

6363
- ``calls(Callable target)`` succeeds if this callable contains a call whose callee is ``target``.
6464
- ``polyCalls(Callable target)`` succeeds if this callable may call ``target`` at runtime; this is the case if it contains a call whose callee is either ``target`` or a method that ``target`` overrides.
@@ -86,7 +86,7 @@ Given this API, we can easily write a query that finds methods that are not call
8686

8787
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.
8888

89-
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 as follows:
89+
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:
9090

9191
.. code-block:: ql
9292
@@ -144,7 +144,7 @@ A further special case is non-public default constructors: in the singleton patt
144144
145145
➤ `See this in the query console <https://lgtm.com/query/673060008/>`__. This change has a large effect on the results for some projects but little effect on the results for others. Use of this pattern varies widely between different projects.
146146

147-
Finally, on many Java projects there are methods that are invoked indirectly by reflection. Thus, while there are no calls invoking these methods, they are, in fact, used. It is in general very hard to identify such methods. A very common special case, however, is JUnit test methods, which are reflectively invoked by a test runner. The QL Java library has support for recognizing test classes of JUnit and other testing frameworks, which we can employ to filter out methods defined in such classes:
147+
Finally, on many Java projects there are methods that are invoked indirectly by reflection. So, while there are no calls invoking these methods, they are, in fact, used. It is in general very hard to identify such methods. A very common special case, however, is JUnit test methods, which are reflectively invoked by a test runner. The QL Java library has support for recognizing test classes of JUnit and other testing frameworks, which we can employ to filter out methods defined in such classes:
148148

149149
.. code-block:: ql
150150
@@ -161,8 +161,8 @@ Finally, on many Java projects there are methods that are invoked indirectly by
161161
162162
➤ `See this in the query console <https://lgtm.com/query/665760002/>`__. This should give a further reduction in the number of results returned.
163163

164-
What next?
165-
----------
164+
Further reading
165+
---------------
166166

167167
- 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>`.
168168
- Find out how specific classes in the AST are represented in the standard library for Java: :doc:`AST class reference <ast-class-reference>`.

0 commit comments

Comments
 (0)