Skip to content

Commit 1343121

Browse files
committed
MethodAccess has been deprecated, Change MethodAccess to MethodCall in query example.
1 parent 3230df0 commit 1343121

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ Accesses
231231
+--------------------------------+---------------------+
232232
| ``a[i]`` | ArrayAccess_ |
233233
+--------------------------------+---------------------+
234-
| ``f(...)`` | MethodAccess_ |
234+
| ``f(...)`` | MethodCall_ |
235235
+--------------------------------+ |
236236
| ``e.m(...)`` | |
237237
+--------------------------------+---------------------+
@@ -374,7 +374,7 @@ Further reading
374374
.. _ThisAccess: https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Expr.qll/type.Expr$ThisAccess.html
375375
.. _SuperAccess: https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Expr.qll/type.Expr$SuperAccess.html
376376
.. _ArrayAccess: https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Expr.qll/type.Expr$ArrayAccess.html
377-
.. _MethodAccess: https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Expr.qll/type.Expr$MethodAccess.html
377+
.. _MethodCall: https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Expr.qll/type.Expr$MethodCall.html
378378
.. _WildcardTypeAccess: https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Expr.qll/type.Expr$WildcardTypeAccess.html
379379
.. _FieldAccess: https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Expr.qll/type.Expr$FieldAccess.html
380380
.. _CastExpr: https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Expr.qll/type.Expr$CastExpr.html

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ Running a quick query
4242

4343
.. code-block:: ql
4444
45-
from MethodAccess ma
45+
from MethodCall mc
4646
where
47-
ma.getMethod().hasName("equals") and
48-
ma.getArgument(0).(StringLiteral).getValue() = ""
49-
select ma, "This comparison to empty string is inefficient, use isEmpty() instead."
47+
mc.getMethod().hasName("equals") and
48+
mc.getArgument(0).(StringLiteral).getValue() = ""
49+
select mc, "This comparison to empty string is inefficient, use isEmpty() instead."
5050
5151
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.
5252

@@ -55,7 +55,7 @@ Running a quick query
5555
.. image:: ../images/codeql-for-visual-studio-code/basic-java-query-results-1.png
5656
:align: center
5757

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

6060
.. image:: ../images/codeql-for-visual-studio-code/basic-java-query-results-2.png
6161
:align: center
@@ -72,15 +72,15 @@ After the initial ``import`` statement, this simple query comprises three parts
7272
+==================================================================================================+===================================================================================================================+===================================================================================================+
7373
| ``import java`` | Imports the standard CodeQL libraries for Java and Kotlin. | Every query begins with one or more ``import`` statements. |
7474
+--------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
75-
| ``from MethodAccess ma`` | Defines the variables for the query. | We use: |
75+
| ``from MethodCall mc`` | Defines the variables for the query. | We use: |
7676
| | Declarations are of the form: | |
77-
| | ``<type> <variable name>`` | - a ``MethodAccess`` variable for call expressions |
77+
| | ``<type> <variable name>`` | - a ``MethodCall`` variable for call expressions |
7878
+--------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
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``. |
79+
| ``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``. |
8080
| | | |
81-
| | | ``ma.getArgument(0).(StringLiteral).getValue() = ""`` says the argument must be literal ``""``. |
81+
| | | ``mc.getArgument(0).(StringLiteral).getValue() = ""`` says the argument must be literal ``""``. |
8282
+--------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
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. |
83+
| ``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. |
8484
| | | |
8585
| | ``select`` statements for queries that are used to find instances of poor coding practice are always in the form: | |
8686
| | ``select <program element>, "<alert message>"`` | |
@@ -110,16 +110,16 @@ In this case, it is not possible to simply use ``o.isEmpty()`` instead, as ``o``
110110

111111
.. code-block:: ql
112112
113-
ma.getQualifier().getType() instanceof TypeString
113+
mc.getQualifier().getType() instanceof TypeString
114114
115115
The ``where`` clause is now:
116116

117117
.. code-block:: ql
118118
119119
where
120-
ma.getQualifier().getType() instanceof TypeString and
121-
ma.getMethod().hasName("equals") and
122-
ma.getArgument(0).(StringLiteral).getValue() = ""
120+
mc.getQualifier().getType() instanceof TypeString and
121+
mc.getMethod().hasName("equals") and
122+
mc.getArgument(0).(StringLiteral).getValue() = ""
123123
124124
#. Re-run the query.
125125

@@ -141,4 +141,4 @@ Further reading
141141

142142
.. |image-quick-query| image:: ../images/codeql-for-visual-studio-code/quick-query-tab-java.png
143143

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.
144+
.. |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.

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

Lines changed: 1 addition & 1 deletion
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/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``.
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 ``MethodCall``, ``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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ To identify these cases, we can create two CodeQL classes that represent, respec
113113
}
114114
115115
/** class representing calls to java.util.Collection.toArray(T[]) */
116-
class CollectionToArrayCall extends MethodAccess {
116+
class CollectionToArrayCall extends MethodCall {
117117
CollectionToArrayCall() {
118118
exists(CollectionToArray m |
119119
this.getMethod().getSourceDeclaration().overridesOrInstantiates*(m)
@@ -210,7 +210,7 @@ Now we want to identify all calls to ``Collection.contains``, including any meth
210210

211211
.. code-block:: ql
212212
213-
class JavaUtilCollectionContainsCall extends MethodAccess {
213+
class JavaUtilCollectionContainsCall extends MethodCall {
214214
JavaUtilCollectionContainsCall() {
215215
exists(JavaUtilCollectionContains jucc |
216216
this.getMethod().getSourceDeclaration().overrides*(jucc)
@@ -297,7 +297,7 @@ Adding these three improvements, our final query becomes:
297297
}
298298
}
299299
300-
class JavaUtilCollectionContainsCall extends MethodAccess {
300+
class JavaUtilCollectionContainsCall extends MethodCall {
301301
JavaUtilCollectionContainsCall() {
302302
exists(JavaUtilCollectionContains jucc |
303303
this.getMethod().getSourceDeclaration().overrides*(jucc)

0 commit comments

Comments
 (0)