private int addFieldAttributes(FieldBinding fieldBinding, int fieldAttributeOffset) {
int attributesNumber = 0;
// 4.7.2 only static constant fields get a ConstantAttribute
// Generate the constantValueAttribute
Constant fieldConstant = fieldBinding.constant();
if (fieldConstant != Constant.NotAConstant){
if (this.contentsOffset + 8 >= this.contents.length) {
resizeContents(8);
}
// Now we generate the constant attribute corresponding to the fieldBinding
int constantValueNameIndex =
this.constantPool.literalIndex(AttributeNamesConstants.ConstantValueName);
this.contents[this.contentsOffset++] = (byte) (constantValueNameIndex >> 8);
this.contents[this.contentsOffset++] = (byte) constantValueNameIndex;
// The attribute length = 2 in case of a constantValue attribute
this.contents[this.contentsOffset++] = 0;
this.contents[this.contentsOffset++] = 0;
this.contents[this.contentsOffset++] = 0;
this.contents[this.contentsOffset++] = 2;
attributesNumber++;
// Need to add the constant_value_index
switch (fieldConstant.typeID()) {
case T_boolean :
int booleanValueIndex =
this.constantPool.literalIndex(fieldConstant.booleanValue() ? 1 : 0);
this.contents[this.contentsOffset++] = (byte) (booleanValueIndex >> 8);
this.contents[this.contentsOffset++] = (byte) booleanValueIndex;
break;
case T_byte :
case T_char :
case T_int :
case T_short :
int integerValueIndex =
this.constantPool.literalIndex(fieldConstant.intValue());
this.contents[this.contentsOffset++] = (byte) (integerValueIndex >> 8);
this.contents[this.contentsOffset++] = (byte) integerValueIndex;
break;
case T_float :
int floatValueIndex =
this.constantPool.literalIndex(fieldConstant.floatValue());
this.contents[this.contentsOffset++] = (byte) (floatValueIndex >> 8);
this.contents[this.contentsOffset++] = (byte) floatValueIndex;
break;
case T_double :
int doubleValueIndex =
this.constantPool.literalIndex(fieldConstant.doubleValue());
this.contents[this.contentsOffset++] = (byte) (doubleValueIndex >> 8);
this.contents[this.contentsOffset++] = (byte) doubleValueIndex;
break;
case T_long :
int longValueIndex =
this.constantPool.literalIndex(fieldConstant.longValue());
this.contents[this.contentsOffset++] = (byte) (longValueIndex >> 8);
this.contents[this.contentsOffset++] = (byte) longValueIndex;
break;
case T_JavaLangString :
int stringValueIndex =