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
Removes 'eclipse-cdt/cdt' and 'gradle/gradle' from the queried projects
because they cannot be queried currently, and instead queries all demo
projects which are currently available.
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
@@ -78,7 +78,7 @@ We can use the ``Callable`` class to write a query that finds methods that are n
78
78
where not exists(Callable caller | caller.polyCalls(callee))
79
79
select callee
80
80
81
-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/665280012/>`__. This simple query typically returns a large number of results.
81
+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/8376915232270534450/>`__. This simple query typically returns a large number of results.
82
82
83
83
.. pull-quote::
84
84
@@ -97,7 +97,7 @@ Running this query on a typical Java project results in lots of hits in the Java
97
97
callee.getCompilationUnit().fromSource()
98
98
select callee, "Not called."
99
99
100
-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/668510015/>`__. This change reduces the number of results returned for most projects.
100
+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/8711624074465690976/>`__. This change reduces the number of results returned for most projects.
101
101
102
102
We might also notice several unused methods with the somewhat strange name ``<clinit>``: these are class initializers; while they are not explicitly called anywhere in the code, they are called implicitly whenever the surrounding class is loaded. Hence it makes sense to exclude them from our query. While we are at it, we can also exclude finalizers, which are similarly invoked implicitly:
103
103
@@ -111,7 +111,7 @@ We might also notice several unused methods with the somewhat strange name ``<cl
111
111
not callee.hasName("<clinit>") and not callee.hasName("finalize")
112
112
select callee, "Not called."
113
113
114
-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/672230002/>`__. This also reduces the number of results returned by most projects.
114
+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/925473733866047471/>`__. This also reduces the number of results returned by most projects.
115
115
116
116
We may also want to exclude public methods from our query, since they may be external API entry points:
117
117
@@ -126,7 +126,7 @@ We may also want to exclude public methods from our query, since they may be ext
126
126
not callee.isPublic()
127
127
select callee, "Not called."
128
128
129
-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/667290016/>`__. This should have a more noticeable effect on the number of results returned.
129
+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/6284320987237954610/>`__. This should have a more noticeable effect on the number of results returned.
130
130
131
131
A further special case is non-public default constructors: in the singleton pattern, for example, a class is provided with private empty default constructor to prevent it from being instantiated. Since the very purpose of such constructors is their not being called, they should not be flagged up:
132
132
@@ -142,7 +142,7 @@ A further special case is non-public default constructors: in the singleton patt
142
142
not callee.(Constructor).getNumberOfParameters() = 0
143
143
select callee, "Not called."
144
144
145
-
➤ `See this in the query console on LGTM.com <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.
145
+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/2625028545869146918/>`__. 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.
146
146
147
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 CodeQL library for Java has support for recognizing test classes of JUnit and other testing frameworks, which we can employ to filter out methods defined in such classes:
148
148
@@ -159,7 +159,7 @@ Finally, on many Java projects there are methods that are invoked indirectly by
159
159
not callee.getDeclaringType() instanceof TestClass
160
160
select callee, "Not called."
161
161
162
-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/665760002/>`__. This should give a further reduction in the number of results returned.
162
+
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/2055862421970264112/>`__. This should give a further reduction in the number of results returned.
0 commit comments