/* useNamedValues = */ // ----------------------------------------------------------------------------------------------- // Implementation of the AnnotationVisitor abstract class // ----------------------------------------------------------------------------------------------- public override void Visit(string name, object value) { // Case of an element_value with a const_value_index, class_info_index or array_index field. // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.16.1. ++numElementValuePairs; if (useNamedValues) { annotation.PutShort(symbolTable.AddConstantUtf8(name)); } if (value is string) { annotation.Put12('s', symbolTable.AddConstantUtf8((string)value)); } else if (value is byte) { annotation.Put12('B', symbolTable.AddConstantInteger((byte)value).index); } else if (value is bool) { var booleanValue = (bool)value ? 1 : 0; annotation.Put12('Z', symbolTable.AddConstantInteger(booleanValue).index); } else if (value is char) { annotation.Put12('C', symbolTable.AddConstantInteger((char)value).index); } else if (value is short) { annotation.Put12('S', symbolTable.AddConstantInteger((short)value).index); } else if (value is Type) { annotation.Put12('c', symbolTable.AddConstantUtf8(((Type)value).GetDescriptor())); } else if (value is byte[]) { var byteArray = (byte[])value; annotation.Put12('[', byteArray.Length); foreach (var byteValue in byteArray) { annotation.Put12('B', symbolTable.AddConstantInteger(byteValue).index); } } else if (value is bool[]) { var booleanArray = (bool[])value; annotation.Put12('[', booleanArray.Length); foreach (var booleanValue in booleanArray) { annotation.Put12('Z', symbolTable.AddConstantInteger(booleanValue ? 1 : 0).index); } } else if (value is short[]) { var shortArray = (short[])value; annotation.Put12('[', shortArray.Length); foreach (var shortValue in shortArray) { annotation.Put12('S', symbolTable.AddConstantInteger(shortValue).index); } } else if (value is char[]) { var charArray = (char[])value; annotation.Put12('[', charArray.Length); foreach (var charValue in charArray) { annotation.Put12('C', symbolTable.AddConstantInteger(charValue).index); } } else if (value is int[]) { var intArray = (int[])value; annotation.Put12('[', intArray.Length); foreach (var intValue in intArray) { annotation.Put12('I', symbolTable.AddConstantInteger(intValue).index); } } else if (value is long[]) { var longArray = (long[])value; annotation.Put12('[', longArray.Length); foreach (var longValue in longArray) { annotation.Put12('J', symbolTable.AddConstantLong(longValue).index); } } else if (value is float[]) { var floatArray = (float[])value; annotation.Put12('[', floatArray.Length); foreach (var floatValue in floatArray) { annotation.Put12('F', symbolTable.AddConstantFloat(floatValue).index); } } else if (value is double[]) { var doubleArray = (double[])value; annotation.Put12('[', doubleArray.Length); foreach (var doubleValue in doubleArray) { annotation.Put12('D', symbolTable.AddConstantDouble(doubleValue).index); } } else { var symbol = symbolTable.AddConstant(value); annotation.Put12(".s.IFJDCS"[symbol.tag], symbol.index); } }