blob: 2743ad4d1df306e135ee18179e7f929efb9e5d5b (
plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/*
* OverridingClass.oj
*
* Apr 29, 1999, by Michiaki Tatsubori
* Feb 2, 1999, by Michiaki Tatsubori
*/
package examples.orcheck;
import openjava.mop.*;
import openjava.ptree.*;
import openjava.syntax.*;
/**
* The metaclass <code>OverloadCheckerClass</code> provides classes
* with a facility of checking if a method overrides the method of
* its superclass.
* <p>
* The class <code>MyObject</code> following is a use-case of
* this metaclass:
* <pre>
* class MyObject instantiates OverridingClass {
* public overriding tostring( Object[] arg ) { .. }
* }
* </pre>
* Here, you intend to override the method <tt>toString()</tt> surely.
* Compilation of this class shows warning that you do not
* override any method. This can help you to become aware of potential
* bugs.
*
* @author Michiaki Tatsubori
* @version 1.0
* @see openjava.mop.OJClass#translateDefinition()
* @see openjava.mop.OJClass#isRegisteredModifier()
*/
public class OverridingClass instantiates Metaclass extends OJClass
{
private static final String OVERRIDING = "overriding";
public void translateDefinition() throws MOPException {
OJMethod[] methods = getDeclaredMethods();
for (int i = 0; i < methods.length; ++i) {
if (! methods[i].getModifiers().has( OVERRIDING )) continue;
OJClass[] paramtypes = methods[i].getParameterTypes();
String name = methods[i].getName();
OJClass[] ptypes = methods[i].getParameterTypes();
try {
getSuperclass().getMethod( name, ptypes, this );
} catch (Exception e) {
System.err.println( "WARNING: " + methods[i] + " doesn't " +
"override any method in superclasses." );
}
}
}
public static boolean isRegisteredModifier( String keyword ) {
if (keyword.equals( OVERRIDING )) return true;
return false;
}
}
|