1 23 24 25 package com.sun.jdo.api.persistence.enhancer.classfile; 26 27 import java.io.*; 28 import java.util.Vector ; 29 import java.util.Enumeration ; 30 31 35 36 public class ClassMethod extends ClassMember { 37 38 public final static String intializerName = "<init>"; 40 41 public final static String staticIntializerName = "<clinit>"; 43 44 private int accessFlags; 45 46 47 private ConstUtf8 methodName; 48 49 50 private ConstUtf8 methodSignature; 51 52 53 private AttributeVector methodAttributes; 54 55 56 57 58 61 public int access() { 62 return accessFlags; 63 } 64 65 68 public void setAccess(int newFlags) { 69 accessFlags = newFlags; 70 } 71 72 75 public boolean isAbstract() { 76 return (accessFlags & ACCAbstract) != 0; 77 } 78 79 82 public boolean isNative() { 83 return (accessFlags & ACCNative) != 0; 84 } 85 86 89 public ConstUtf8 name() { 90 return methodName; 91 } 92 93 96 public void changeName(ConstUtf8 name) { 97 methodName = name; 98 } 99 100 103 public ConstUtf8 signature() { 104 return methodSignature; 105 } 106 107 110 public void changeSignature(ConstUtf8 newSig) { 111 methodSignature = newSig; 112 } 113 114 117 public AttributeVector attributes() { 118 return methodAttributes; 119 } 120 121 124 125 public ClassMethod(int accFlags, ConstUtf8 name, ConstUtf8 sig, 126 AttributeVector methodAttrs) { 127 accessFlags = accFlags; 128 methodName = name; 129 methodSignature = sig; 130 methodAttributes = methodAttrs; 131 } 132 133 136 int codeSize() { 137 CodeAttribute codeAttr = codeAttribute(); 138 return (codeAttr == null) ? 0 : codeAttr.codeSize(); 139 } 140 141 144 public CodeAttribute codeAttribute() { 145 Enumeration e = methodAttributes.elements(); 146 while (e.hasMoreElements()) { 147 ClassAttribute attr = (ClassAttribute) e.nextElement(); 148 if (attr instanceof CodeAttribute) 149 return (CodeAttribute) attr; 150 } 151 return null; 152 } 153 154 155 156 157 static ClassMethod read(DataInputStream data, ConstantPool pool) 158 throws IOException { 159 int accessFlags = data.readUnsignedShort(); 160 int nameIndex = data.readUnsignedShort(); 161 int sigIndex = data.readUnsignedShort(); 162 ClassMethod f = 163 new ClassMethod(accessFlags, 164 (ConstUtf8) pool.constantAt(nameIndex), 165 (ConstUtf8) pool.constantAt(sigIndex), 166 null); 167 168 f.methodAttributes = AttributeVector.readAttributes(data, pool); 169 return f; 170 } 171 172 void write(DataOutputStream data) throws IOException { 173 CodeAttribute codeAttr = codeAttribute(); 174 data.writeShort(accessFlags); 175 data.writeShort(methodName.getIndex()); 176 data.writeShort(methodSignature.getIndex()); 177 methodAttributes.write(data); 178 } 179 180 void print(PrintStream out, int indent) { 181 ClassPrint.spaces(out, indent); 182 out.print("'" + methodName.asString() + "'"); out.print(" sig = " + methodSignature.asString()); out.print(" accessFlags = " + Integer.toString(accessFlags)); out.println(" attributes:"); methodAttributes.print(out, indent+2); 187 } 188 189 } 190 191 192 | Popular Tags |