1 8 package jas; 9 10 import java.io.*; 11 import java.util.*; 12 13 public class Method 14 { 15 short acc; 16 CP name, sig; 17 CodeAttr code; 18 ExceptAttr excepts; 19 SyntheticAttr synthAttr = null; 20 DeprecatedAttr deprAttr = null; 21 SignatureAttr sigAttr = null; 22 VisibilityAnnotationAttr vis_annot_attr = null; 23 ParameterVisibilityAnnotationAttr param_vis_annot_attr = null; 24 AnnotationDefaultAttr annotDef = null; 25 Vector genericAttrs = new Vector(); 26 27 35 public Method (short macc, CP name, CP sig, CodeAttr cd, ExceptAttr ex) 36 { 37 acc = macc; 38 this.name = name; 39 this.sig = sig; 40 code = cd; excepts = ex; 41 } 42 43 public Method (short macc, CP name, CP sig, CodeAttr cd, ExceptAttr ex, SyntheticAttr synth) 44 { 45 acc = macc; 46 this.name = name; 47 this.sig = sig; 48 code = cd; excepts = ex; 49 synthAttr = synth; 50 } 51 public void addGenericAttr(GenericAttr g) 52 { 53 genericAttrs.addElement(g); 54 } 55 56 public void addDeprecatedAttr(DeprecatedAttr d) 57 { 58 deprAttr = d; 59 } 60 61 public void addSignatureAttr(SignatureAttr s) 62 { 63 sigAttr = s; 64 } 65 66 public void addAnnotationAttr(VisibilityAnnotationAttr v) 67 { 68 vis_annot_attr = v; 69 } 70 71 public void addParamAnnotationAttr(ParameterVisibilityAnnotationAttr v) 72 { 73 param_vis_annot_attr = v; 74 } 75 76 public void addAnnotationDef(AnnotationDefaultAttr v) 77 { 78 annotDef = v; 79 } 80 81 void resolve(ClassEnv e) 82 { 83 e.addCPItem(name); 84 e.addCPItem(sig); 85 if (code != null) code.resolve(e); 86 if (excepts != null) excepts.resolve(e); 87 if (synthAttr != null) synthAttr.resolve(e); 88 if (deprAttr != null) deprAttr.resolve(e); 89 if (sigAttr != null) sigAttr.resolve(e); 90 if (vis_annot_attr != null) vis_annot_attr.resolve(e); 91 if (param_vis_annot_attr != null) param_vis_annot_attr.resolve(e); 92 if (annotDef != null) annotDef.resolve(e); 93 } 94 95 void write(ClassEnv e, DataOutputStream out) 96 throws IOException, jasError 97 { 98 short cnt = 0; 99 out.writeShort(acc); 100 out.writeShort(e.getCPIndex(name)); 101 out.writeShort(e.getCPIndex(sig)); 102 if (code != null) cnt ++; 103 if (excepts != null) cnt++; 104 cnt += genericAttrs.size(); 105 if (synthAttr != null){ 106 cnt++; 107 } 108 if (deprAttr != null){ 109 cnt++; 110 } 111 if (sigAttr != null){ 112 cnt++; 113 } 114 if (vis_annot_attr != null){ 115 cnt++; 116 } 117 if (param_vis_annot_attr != null){ 118 cnt++; 119 } 120 if (annotDef != null){ 121 cnt++; 122 } 123 out.writeShort(cnt); 124 if (code != null) code.write(e, out); 125 if (excepts != null) excepts.write(e, out); 126 if (synthAttr != null) synthAttr.write(e, out); 127 if (deprAttr != null) deprAttr.write(e, out); 128 if (sigAttr != null) sigAttr.write(e, out); 129 if (vis_annot_attr != null) vis_annot_attr.write(e, out); 130 if (param_vis_annot_attr != null) param_vis_annot_attr.write(e, out); 131 if (annotDef != null) annotDef.write(e, out); 132 133 for(Enumeration enu = genericAttrs.elements(); enu.hasMoreElements();) { 134 ((GenericAttr)enu.nextElement()).write(e, out); 135 } 136 137 } 138 } 139 | Popular Tags |