setXXX methods

write methods
new attribute handling


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@621 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 7aac88b69d
commit a2c0b6b6d7
  1. 165
      jode/jode/bytecode/FieldInfo.java

@ -18,64 +18,177 @@
*/
package jode.bytecode;
import jode.type.Type;
import java.io.*;
import java.lang.reflect.Modifier;
public class FieldInfo extends BinaryInfo {
ClassInfo clazzInfo;
int modifier;
String name;
Type type;
String typeSig;
Object constant;
boolean syntheticFlag;
boolean deprecatedFlag;
public FieldInfo() {
public FieldInfo(ClassInfo ci) {
this.clazzInfo = ci;
}
public FieldInfo(String name, Type type, int modifier) {
public FieldInfo(ClassInfo ci, String name, String typeSig, int modifier) {
this.clazzInfo = ci;
this.name = name;
this.type = type;
this.typeSig = typeSig;
this.modifier = modifier;
}
protected void readAttribute(String name, int length,
ConstantPool cp,
DataInputStream input,
int howMuch) throws IOException {
if (name.equals("ConstantValue")) {
if (length != 2)
throw new ClassFormatException("ConstantValue attribute"
+ " has wrong length");
int index = input.readUnsignedShort();
constant = cp.getConstant(index);
} else if (name.equals("Synthetic")) {
syntheticFlag = true;
if (length != 0)
throw new ClassFormatException
("Synthetic attribute has wrong length");
} else if (name.equals("Deprecated")) {
deprecatedFlag = true;
if (length != 0)
throw new ClassFormatException
("Deprecated attribute has wrong length");
} else
super.readAttribute(name, length, cp, input, howMuch);
}
public void read(ConstantPool constantPool,
DataInputStream input, int howMuch) throws IOException {
modifier = input.readUnsignedShort();
name = constantPool.getUTF8(input.readUnsignedShort());
typeSig = constantPool.getUTF8(input.readUnsignedShort());
readAttributes(constantPool, input, howMuch);
}
public void reserveSmallConstants(GrowableConstantPool gcp) {
}
public void prepareWriting(GrowableConstantPool gcp) {
gcp.putUTF8(name);
gcp.putUTF8(typeSig);
if (constant != null) {
gcp.putUTF8("ConstantValue");
if (typeSig.charAt(0) == 'J' || typeSig.charAt(0) == 'D')
gcp.putLongConstant(constant);
else
gcp.putConstant(constant);
}
if (syntheticFlag)
gcp.putUTF8("Synthetic");
if (deprecatedFlag)
gcp.putUTF8("Deprecated");
prepareAttributes(gcp);
}
protected int getKnownAttributeCount() {
int count = 0;
if (constant != null)
count++;
if (syntheticFlag)
count++;
if (deprecatedFlag)
count++;
return count;
}
public void writeKnownAttributes(GrowableConstantPool gcp,
DataOutputStream output)
throws IOException {
if (constant != null) {
output.writeShort(gcp.putUTF8("ConstantValue"));
output.writeInt(2);
int index;
if (typeSig.charAt(0) == 'J'
|| typeSig.charAt(0) == 'D')
index = gcp.putLongConstant(constant);
else
index = gcp.putConstant(constant);
output.writeShort(index);
}
if (syntheticFlag) {
output.writeShort(gcp.putUTF8("Synthetic"));
output.writeInt(0);
}
if (deprecatedFlag) {
output.writeShort(gcp.putUTF8("Deprecated"));
output.writeInt(0);
}
}
public void write(GrowableConstantPool constantPool,
DataOutputStream output) throws IOException {
output.writeShort(modifier);
output.writeShort(constantPool.putUTF8(name));
output.writeShort(constantPool.putUTF8(typeSig));
writeAttributes(constantPool, output);
}
public String getName() {
return name;
}
public Type getType() {
return type;
public String getType() {
return typeSig;
}
public int getModifiers() {
return modifier;
}
public boolean isSynthetic() {
return syntheticFlag;
}
public boolean isDeprecated() {
return deprecatedFlag;
}
public Object getConstant() {
return constant;
return constant;
}
public void read(ConstantPool constantPool,
DataInputStream input, int howMuch) throws IOException {
modifier = input.readUnsignedShort();
name = constantPool.getUTF8(input.readUnsignedShort());
type = Type.tType(constantPool.getUTF8(input.readUnsignedShort()));
public void setName(String newName) {
name = newName;
}
readAttributes(constantPool, input, howMuch);
public void setType(String newType) {
typeSig = newType;
}
if ((howMuch & ClassInfo.ALL_ATTRIBUTES) != 0) {
AttributeInfo attribute = findAttribute("ConstantValue");
if (attribute != null) {
byte[] contents = attribute.getContents();
if (contents.length != 2)
throw new ClassFormatException("ConstantValue attribute"
+ " has wrong length");
int index = (contents[0] & 0xff) << 8 | (contents[1] & 0xff);
constant = constantPool.getConstant(index);
}
}
public void setModifiers(int newModifier) {
modifier = newModifier;
}
public void setSynthetic(boolean flag) {
syntheticFlag = flag;
}
public void setDeprecated(boolean flag) {
deprecatedFlag = flag;
}
public void setConstant(Object newConstant) {
constant = newConstant;
}
public String toString() {
return "Field "+Modifier.toString(modifier)+" "+
type.toString()+" "+name;
typeSig+" "+name;
}
}

Loading…
Cancel
Save