Skip to content

Commit cb31f82

Browse files
authored
Also rename variable from ma to mc
This is slightly less confusing, given the type name is now `MethodCall`.
1 parent 21fc06c commit cb31f82

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

docs/codeql/codeql-language-guides/basic-query-for-java-code.rst

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ Running a quick query
4646
where
4747
ma.getMethod().hasName("equals") and
4848
ma.getArgument(0).(StringLiteral).getValue() = ""
49-
select ma, "This comparison to empty string is inefficient, use isEmpty() instead."
49+
from MethodCall mc
50+
where
51+
mc.getMethod().hasName("equals") and
52+
mc.getArgument(0).(StringLiteral).getValue() = ""
53+
select mc, "This comparison to empty string is inefficient, use isEmpty() instead."
5054
5155
Note that CodeQL treats Java and Kotlin as part of the same language, so even though this query starts with ``import java``, it will work for both Java and Kotlin code.
5256

@@ -55,7 +59,7 @@ Running a quick query
5559
.. image:: ../images/codeql-for-visual-studio-code/basic-java-query-results-1.png
5660
:align: center
5761

58-
If any matching code is found, click a link in the ``ma`` column to view the ``.equals`` expression in the code viewer.
62+
If any matching code is found, click a link in the ``mc`` column to view the ``.equals`` expression in the code viewer.
5963

6064
.. image:: ../images/codeql-for-visual-studio-code/basic-java-query-results-2.png
6165
:align: center
@@ -72,15 +76,15 @@ After the initial ``import`` statement, this simple query comprises three parts
7276
+==================================================================================================+===================================================================================================================+===================================================================================================+
7377
| ``import java`` | Imports the standard CodeQL libraries for Java and Kotlin. | Every query begins with one or more ``import`` statements. |
7478
+--------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
75-
| ``from MethodCall ma`` | Defines the variables for the query. | We use: |
79+
| ``from MethodCall mc`` | Defines the variables for the query. | We use: |
7680
| | Declarations are of the form: | |
7781
| | ``<type> <variable name>`` | - a ``MethodCall`` variable for call expressions |
7882
+--------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
79-
| ``where ma.getMethod().hasName("equals") and ma.getArgument(0).(StringLiteral).getValue() = ""`` | Defines a condition on the variables. | ``ma.getMethod().hasName("equals")`` restricts ``ma`` to only calls to methods call ``equals``. |
83+
| ``where mc.getMethod().hasName("equals") and mc.getArgument(0).(StringLiteral).getValue() = ""`` | Defines a condition on the variables. | ``mc.getMethod().hasName("equals")`` restricts ``mc`` to only calls to methods call ``equals``. |
8084
| | | |
81-
| | | ``ma.getArgument(0).(StringLiteral).getValue() = ""`` says the argument must be literal ``""``. |
85+
| | | ``mc.getArgument(0).(StringLiteral).getValue() = ""`` says the argument must be literal ``""``. |
8286
+--------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
83-
| ``select ma, "This comparison to empty string is inefficient, use isEmpty() instead."`` | Defines what to report for each match. | Reports the resulting ``.equals`` expression with a string that explains the problem. |
87+
| ``select mc, "This comparison to empty string is inefficient, use isEmpty() instead."`` | Defines what to report for each match. | Reports the resulting ``.equals`` expression with a string that explains the problem. |
8488
| | | |
8589
| | ``select`` statements for queries that are used to find instances of poor coding practice are always in the form: | |
8690
| | ``select <program element>, "<alert message>"`` | |
@@ -110,7 +114,7 @@ In this case, it is not possible to simply use ``o.isEmpty()`` instead, as ``o``
110114

111115
.. code-block:: ql
112116
113-
ma.getQualifier().getType() instanceof TypeString
117+
mc.getQualifier().getType() instanceof TypeString
114118
115119
The ``where`` clause is now:
116120

@@ -119,7 +123,9 @@ In this case, it is not possible to simply use ``o.isEmpty()`` instead, as ``o``
119123
where
120124
ma.getQualifier().getType() instanceof TypeString and
121125
ma.getMethod().hasName("equals") and
122-
ma.getArgument(0).(StringLiteral).getValue() = ""
126+
mc.getQualifier().getType() instanceof TypeString and
127+
mc.getMethod().hasName("equals") and
128+
mc.getArgument(0).(StringLiteral).getValue() = ""
123129
124130
#. Re-run the query.
125131

@@ -137,8 +143,6 @@ Further reading
137143

138144
.. |language-code| replace:: ``java``
139145

140-
.. |example-url| replace:: https://github.com/apache/activemq
141-
142146
.. |image-quick-query| image:: ../images/codeql-for-visual-studio-code/quick-query-tab-java.png
143147

144-
.. |result-col-1| replace:: The first column corresponds to the expression ``ma`` and is linked to the location in the source code of the project where ``ma`` occurs.
148+
.. |result-col-1| replace:: The first column corresponds to the expression ``mc`` and is linked to the location in the source code of the project where ``mc`` occurs.

0 commit comments

Comments
 (0)