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/codeql/codeql-language-guides/basic-query-for-java-code.rst
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,11 +42,11 @@ Running a quick query
42
42
43
43
.. code-block:: ql
44
44
45
-
from MethodAccess ma
45
+
from MethodCall mc
46
46
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."
50
50
51
51
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.
| ``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``. |
80
80
||||
81
-
||| ``ma.getArgument(0).(StringLiteral).getValue() = ""`` says the argument must be literal ``""``. |
81
+
||| ``mc.getArgument(0).(StringLiteral).getValue() = ""`` says the argument must be literal ``""``. |
| ``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. |
84
84
||||
85
85
|| ``select`` statements for queries that are used to find instances of poor coding practice are always in the form: ||
.. |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.
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/navigating-the-call-graph.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
@@ -8,7 +8,7 @@ CodeQL has classes for identifying code that calls other code, and code that can
8
8
Call graph classes
9
9
------------------
10
10
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``.
12
12
13
13
For example, in the following program all callables and calls have been annotated with comments:
0 commit comments