1 32 33 package com.jeantessier.classreader; 34 35 import java.io.*; 36 import java.util.*; 37 38 public class Method_info extends Feature_info { 39 public static final int ACC_SYNCHRONIZED = 0x0020; 40 public static final int ACC_NATIVE = 0x0100; 41 public static final int ACC_ABSTRACT = 0x0400; 42 public static final int ACC_STRICT = 0x0800; 43 44 public Method_info(Classfile classfile, DataInputStream in) throws IOException { 45 super(classfile, in); 46 } 47 48 public String getFeatureType() { 49 return "method"; 50 } 51 52 public boolean isSynchronized() { 53 return (getAccessFlag() & ACC_SYNCHRONIZED) != 0; 54 } 55 56 public boolean isNative() { 57 return (getAccessFlag() & ACC_NATIVE) != 0; 58 } 59 60 public boolean isAbstract() { 61 return (getAccessFlag() & ACC_ABSTRACT) != 0; 62 } 63 64 public boolean isStrict() { 65 return (getAccessFlag() & ACC_STRICT) != 0; 66 } 67 68 public boolean isConstructor() { 69 return getName().equals("<init>"); 70 } 71 72 public boolean isStaticInitializer() { 73 return getName().equals("<clinit>"); 74 } 75 76 public Collection getExceptions() { 77 Collection result = Collections.EMPTY_LIST; 78 79 Iterator i = getAttributes().iterator(); 80 while (i.hasNext()) { 81 Object obj = i.next(); 82 if (obj instanceof Exceptions_attribute) { 83 result = ((Exceptions_attribute) obj).getExceptions(); 84 } 85 } 86 87 return result; 88 } 89 90 public String getSignature() { 91 StringBuffer result = new StringBuffer (); 92 93 if (isConstructor()) { 94 result.append(getClassfile().getClassName().substring(getClassfile().getClassName().lastIndexOf(".") + 1)); 95 result.append(SignatureHelper.getSignature(getDescriptor())); 96 } else if (isStaticInitializer()) { 97 result.append("static {}"); 98 } else { 99 result.append(getName()); 100 result.append(SignatureHelper.getSignature(getDescriptor())); 101 } 102 103 return result.toString(); 104 } 105 106 public String getReturnType() { 107 return SignatureHelper.getReturnType(getDescriptor()); 108 } 109 110 public String getDeclaration() { 111 StringBuffer result = new StringBuffer (); 112 113 if (isPublic()) result.append("public "); 114 if (isProtected()) result.append("protected "); 115 if (isPrivate()) result.append("private "); 116 if (isStatic()) result.append("static "); 117 if (isFinal()) result.append("final "); 118 if (isSynchronized()) result.append("synchronized "); 119 if (isNative()) result.append("native "); 120 if (isAbstract()) result.append("abstract "); 121 122 if (!getName().equals("<init>") && !getName().equals("<clinit>")) { 123 result.append((getReturnType() != null) ? getReturnType() : "void").append(" "); 124 } 125 126 result.append(getSignature()); 127 128 if (getExceptions().size() != 0) { 129 result.append(" throws "); 130 Iterator i = getExceptions().iterator(); 131 while (i.hasNext()) { 132 result.append(i.next()); 133 if (i.hasNext()) { 134 result.append(", "); 135 } 136 } 137 } 138 139 return result.toString(); 140 } 141 142 public void accept(Visitor visitor) { 143 visitor.visitMethod_info(this); 144 } 145 } 146 | Popular Tags |