01: package net.sf.clirr.core.internal.bcel;
02:
03: import org.apache.bcel.classfile.Attribute;
04: import org.apache.bcel.classfile.JavaClass;
05: import org.apache.bcel.classfile.Method;
06: import org.apache.bcel.generic.Type;
07:
08: import net.sf.clirr.core.spi.JavaType;
09: import net.sf.clirr.core.spi.Scope;
10:
11: final class BcelMethod implements net.sf.clirr.core.spi.Method {
12:
13: private Method method;
14: private JavaClass owningClass;
15:
16: public BcelMethod(JavaClass owningClass, Method method) {
17: this .owningClass = owningClass;
18: this .method = method;
19: }
20:
21: public JavaType getReturnType() {
22: return convertType(method.getReturnType());
23: }
24:
25: public String getName() {
26: return method.getName();
27: }
28:
29: public boolean isFinal() {
30: return method.isFinal();
31: }
32:
33: public boolean isStatic() {
34: return method.isStatic();
35: }
36:
37: public boolean isAbstract() {
38: return method.isAbstract();
39: }
40:
41: public boolean isDeprecated() {
42: Attribute[] attrs = method.getAttributes();
43: for (int i = 0; i < attrs.length; ++i) {
44: if (attrs[i] instanceof org.apache.bcel.classfile.Deprecated) {
45: return true;
46: }
47: }
48:
49: return false;
50: }
51:
52: public Scope getDeclaredScope() {
53:
54: return BcelScopeHelper.getScope(method.getAccessFlags());
55: }
56:
57: public Scope getEffectiveScope() {
58: // TODO: real impl
59: return getDeclaredScope();
60: }
61:
62: public JavaType[] getArgumentTypes() {
63: final Type[] types = method.getArgumentTypes();
64: return convertTypes(types);
65: }
66:
67: private JavaType convertType(Type bcelType) {
68: return new BcelJavaType(bcelType, owningClass.getRepository());
69: }
70:
71: /**
72: * @param types
73: * @return
74: */
75: private JavaType[] convertTypes(final Type[] types) {
76: JavaType[] retval = new JavaType[types.length];
77: for (int i = 0; i < retval.length; i++) {
78: retval[i] = convertType(types[i]);
79: }
80: return retval;
81: }
82: }
|