1 24 25 package org.aspectj.compiler.base.bcg; 26 27 import org.aspectj.compiler.base.bcg.pool.*; 28 import java.lang.reflect.Modifier ; 29 30 import java.io.IOException ; 31 import java.io.DataOutputStream ; 32 33 import org.aspectj.compiler.base.ast.NameType; 35 36 38 42 public class MethodBuilder { 43 44 47 ConstantPool pool; 48 ClassfileBuilder cfb; 49 Attributes attributes; 50 51 MethodBuilder(ClassfileBuilder cfb) { 52 this.cfb = cfb; 53 this.pool = cfb.pool; 54 attributes = new Attributes(pool); 55 } 56 57 int accessFlags = 0; 58 Constant name; 59 Constant descriptor; 60 61 64 public void writeTo(DataOutputStream stream) throws IOException { 65 stream.writeShort((short) accessFlags); 66 name.writeIndex(stream); 67 descriptor.writeIndex(stream); 68 attributes.writeTo(stream); 69 } 70 71 public String toString() { 72 return "(method " + 73 Modifier.toString(accessFlags) + " " + 74 name + " " + 75 descriptor + " " + attributes + ")"; 76 } 77 78 void display(int indent, boolean inline) { 79 indent += 2; 80 System.err.print("(method "); name.display(0, true); 81 System.err.print(" "); descriptor.display(0, true); 82 between(indent, inline); 83 System.err.print("(modifiers " + Modifier.toString(accessFlags) + ")"); 84 between(indent, inline); 85 attributes.display(indent, inline); 86 System.err.print(")"); 87 } 88 89 static void between(int indent, boolean inline) { 90 if (inline) { 91 System.err.print(" "); 92 } else { 93 System.err.println(); 94 for (int s=indent; s >= 0; s--) System.err.print(" "); 95 } 96 } 97 98 101 public void addAccessFlags(int newFlags) { 102 accessFlags = accessFlags | newFlags; 103 } 104 105 public void setName(String name) { 106 this.name = pool.addUtf8(name); 107 } 108 109 public void setDescriptor(String descriptor) { 110 this.descriptor = pool.addUtf8(descriptor); 111 } 112 113 public void setDeprecated() { 114 attributes.addDeprecatedAttribute(); 115 } 116 117 public void setSynthetic() { 118 attributes.addSyntheticAttribute(); 119 } 120 121 public void addToExceptionsAttribute(NameType exn) { 122 attributes.addToExceptionsAttribute(exn); 123 } 124 125 public CodeBuilder getCodeBuilder() { 126 return new CodeBuilder(cfb); 127 } 128 129 CodeBuilder cb = null; 130 public void setCode(CodeBuilder cb) { 131 this.cb = cb; 132 attributes.addCodeAttribute(cb); 133 } 134 135 void resolve() { 136 if (cb != null) cb.resolve(); 137 } 138 139 142 MethodBuilder readFrom(java.io.DataInputStream stream) throws java.io.IOException { 143 accessFlags = stream.readUnsignedShort(); 144 name = pool.get(stream.readUnsignedShort()); 145 descriptor = pool.get(stream.readUnsignedShort()); 146 attributes.readFrom(stream); 147 return this; 148 } 149 } 150 | Popular Tags |