1 24 25 package org.aspectj.compiler.base.bcg; 26 27 import org.aspectj.compiler.base.bcg.pool.*; 28 29 import java.io.IOException ; 30 import java.io.DataOutputStream ; 31 32 import java.lang.reflect.Modifier ; 34 35 import org.aspectj.compiler.base.ast.TypeDec; 37 38 42 public final class FieldBuilder { 43 44 47 ConstantPool pool; 48 Attributes attributes; 50 51 FieldBuilder(ClassfileBuilder cfb) { 52 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 "(field " + 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("(field "); 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 setConstantValue(boolean b) { 122 attributes.addConstantValueAttribute(pool.addInt(b ? 1 : 0)); 123 } 124 public void setConstantValue(String s) { 125 attributes.addConstantValueAttribute(pool.addString(s)); 126 } 127 public void setConstantValue(int i) { 128 attributes.addConstantValueAttribute(pool.addInt(i)); 129 } 130 public void setConstantValue(float f) { 131 attributes.addConstantValueAttribute(pool.addFloat(f)); 132 } 133 public void setConstantValue(long l) { 134 attributes.addConstantValueAttribute(pool.addLong(l)); 135 } 136 public void setConstantValue(double d) { 137 attributes.addConstantValueAttribute(pool.addDouble(d)); 138 } 139 140 143 FieldBuilder readFrom(java.io.DataInputStream stream) throws java.io.IOException { 144 accessFlags = stream.readUnsignedShort(); 145 name = pool.get(stream.readUnsignedShort()); 146 descriptor = pool.get(stream.readUnsignedShort()); 147 attributes.readFrom(stream); 148 return this; 149 } 150 } 151 | Popular Tags |