1 package net.sf.clirr.core.internal.bcel; 2 3 import org.apache.bcel.classfile.Attribute; 4 import org.apache.bcel.classfile.JavaClass; 5 import org.apache.bcel.classfile.Method; 6 import org.apache.bcel.generic.Type; 7 8 import net.sf.clirr.core.spi.JavaType; 9 import net.sf.clirr.core.spi.Scope; 10 11 final class BcelMethod implements net.sf.clirr.core.spi.Method 12 { 13 14 private Method method; 15 private JavaClass owningClass; 16 17 public BcelMethod(JavaClass owningClass, Method method) 18 { 19 this.owningClass = owningClass; 20 this.method = method; 21 } 22 23 public JavaType getReturnType() { 24 return convertType(method.getReturnType()); 25 } 26 27 public String getName() { 28 return method.getName(); 29 } 30 31 public boolean isFinal() { 32 return method.isFinal(); 33 } 34 35 public boolean isStatic() { 36 return method.isStatic(); 37 } 38 39 public boolean isAbstract() { 40 return method.isAbstract(); 41 } 42 43 public boolean isDeprecated() { 44 Attribute[] attrs = method.getAttributes(); 45 for (int i = 0; i < attrs.length; ++i) 46 { 47 if (attrs[i] instanceof org.apache.bcel.classfile.Deprecated) 48 { 49 return true; 50 } 51 } 52 53 return false; 54 } 55 56 public Scope getDeclaredScope() { 57 58 return BcelScopeHelper.getScope(method.getAccessFlags()); 59 } 60 61 public Scope getEffectiveScope() { 62 return getDeclaredScope(); 64 } 65 66 public JavaType[] getArgumentTypes() { 67 final Type[] types = method.getArgumentTypes(); 68 return convertTypes(types); 69 } 70 71 private JavaType convertType(Type bcelType) { 72 return new BcelJavaType(bcelType, owningClass.getRepository()); 73 } 74 75 79 private JavaType[] convertTypes(final Type[] types) { 80 JavaType[] retval = new JavaType[types.length]; 81 for (int i = 0; i < retval.length; i++) { 82 retval[i] = convertType(types[i]); 83 } 84 return retval; 85 } 86 } 87 | Popular Tags |