-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathBadlyOverriddenAdapter.ql
More file actions
38 lines (35 loc) · 1.34 KB
/
BadlyOverriddenAdapter.ql
File metadata and controls
38 lines (35 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* @name Bad implementation of an event Adapter
* @description In a class that extends a Swing or Abstract Window Toolkit event adapter, an
* event handler that does not have exactly the same name as the event handler that it
* overrides means that the overridden event handler is not called.
* @kind problem
* @problem.severity warning
* @precision medium
* @id java/wrong-swing-event-adapter-signature
* @tags reliability
* maintainability
* frameworks/swing
*/
import java
class Adapter extends Class {
Adapter() {
this.getName().matches("%Adapter") and
(
this.getPackage().hasName("java.awt.event") or
this.getPackage().hasName("javax.swing.event")
)
}
}
from Class c, Adapter adapter, Method m
where
adapter = c.getASupertype() and
c = m.getDeclaringType() and
exists(Method original | adapter = original.getDeclaringType() | m.getName() = original.getName()) and
not exists(Method overridden | adapter = overridden.getDeclaringType() | m.overrides(overridden)) and
// The method is not used for any other purpose.
not exists(MethodCall ma | ma.getMethod() = m)
select m,
"Method " + m.getName() + " attempts to override a method in " + adapter.getName() +
", but does not have the same argument types. " + m.getName() +
" will not be called when an event occurs."