예제 #1
0
        internal static AnnotationNode Parse(Stream stream, ClassReaderState readerState)
        {
            var annotation = new AnnotationNode
            {
                Type = TypeDescriptor.Parse(readerState.ConstantPool
                                            .GetEntry <Utf8Entry>(Binary.BigEndian.ReadUInt16(stream)).String)
            };
            var elementValuePairsCount = Binary.BigEndian.ReadUInt16(stream);

            annotation.ElementValuePairs.Capacity = elementValuePairsCount;
            for (var i = 0; i < elementValuePairsCount; i++)
            {
                annotation.ElementValuePairs.Add(new ElementValuePair
                {
                    ElementName = readerState.ConstantPool
                                  .GetEntry <Utf8Entry>(Binary.BigEndian.ReadUInt16(stream)).String,
                    Value = ElementValue.Parse(stream, readerState)
                });
            }
            return(annotation);
        }
예제 #2
0
        internal static ElementValue Parse(Stream stream, ClassReaderState readerState)
        {
            var elementValue = new ElementValue
            {
                Tag = (ElementValueTag)stream.ReadByteFully()
            };

            switch (elementValue.Tag)
            {
            case ElementValueTag.Byte:
            case ElementValueTag.Character:
            case ElementValueTag.Integer:
            case ElementValueTag.Short:
            case ElementValueTag.Boolean:
                elementValue.ConstValue = readerState.ConstantPool.GetEntry <IntegerEntry>(Binary.BigEndian.ReadUInt16(stream)).Value;
                break;

            case ElementValueTag.Double:
                elementValue.ConstValue = readerState.ConstantPool.GetEntry <DoubleEntry>(Binary.BigEndian.ReadUInt16(stream)).Value;
                break;

            case ElementValueTag.Float:
                elementValue.ConstValue = readerState.ConstantPool.GetEntry <FloatEntry>(Binary.BigEndian.ReadUInt16(stream)).Value;
                break;

            case ElementValueTag.Long:
                elementValue.ConstValue = readerState.ConstantPool.GetEntry <LongEntry>(Binary.BigEndian.ReadUInt16(stream)).Value;
                break;

            case ElementValueTag.String:
                elementValue.ConstValue = readerState.ConstantPool.GetEntry <Utf8Entry>(Binary.BigEndian.ReadUInt16(stream)).String;
                break;

            case ElementValueTag.Enum:
                elementValue.EnumConstValue = new EnumConstValueType
                {
                    TypeName = TypeDescriptor.Parse(readerState.ConstantPool
                                                    .GetEntry <Utf8Entry>(Binary.BigEndian.ReadUInt16(stream)).String),
                    ConstName = readerState.ConstantPool.GetEntry <Utf8Entry>(Binary.BigEndian.ReadUInt16(stream))
                                .String
                };
                break;

            case ElementValueTag.Class:
                elementValue.Class = TypeDescriptor.Parse(readerState.ConstantPool
                                                          .GetEntry <Utf8Entry>(Binary.BigEndian.ReadUInt16(stream)).String, true);
                break;

            case ElementValueTag.Annotation:
                elementValue.AnnotationNode = AnnotationNode.Parse(stream, readerState);
                break;

            case ElementValueTag.Array:
                var arraySize = Binary.BigEndian.ReadUInt16(stream);
                elementValue.ArrayValue = new List <ElementValue>(arraySize);
                for (var i = 0; i < arraySize; i++)
                {
                    elementValue.ArrayValue.Add(Parse(stream, readerState));
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(elementValue.Tag));
            }

            return(elementValue);
        }