Example #1
0
 public AnnotationDefaultAttribute Parse(Stream attributeDataStream, uint attributeDataLength, ClassReaderState readerState, AttributeScope scope)
 {
     return(new AnnotationDefaultAttribute
     {
         Value = ElementValue.Parse(attributeDataStream, readerState)
     });
 }
Example #2
0
        internal static TypeAnnotationNode Parse(Stream stream, ClassReaderState readerState, AttributeScope scope)
        {
            var typeAnnotation = new TypeAnnotationNode
            {
                TargetType = (TargetType)stream.ReadByteFully()
            };

            typeAnnotation.Target = typeAnnotation.TargetType switch
            {
                TargetType.GenericClassOrInterfaceDeclaration when scope == AttributeScope.Class => (TypeAnnotationTarget) new TypeParameterTarget(),
                TargetType.GenericMethodOrConstructorDeclaration when scope == AttributeScope.Method => new TypeParameterTarget(),
                TargetType.ExtendsOrImplements when scope == AttributeScope.Class => new SupertypeTarget(),
                TargetType.TypeInBoundInGenericClassOrInterface when scope == AttributeScope.Class => new TypeParameterBoundTarget(),
                TargetType.TypeInBoundInGenericMethodOrConstructor when scope == AttributeScope.Method => new TypeParameterBoundTarget(),
                TargetType.FieldDeclaration when scope == AttributeScope.Field => new EmptyTarget(),
                TargetType.ReturnTypeOrNewObject when scope == AttributeScope.Method => new EmptyTarget(),
                TargetType.ReceiverTypeOfMethodOrConstructor when scope == AttributeScope.Method => new EmptyTarget(),
                TargetType.TypeInFormalParameterOfMethodOrConstructorOrLambda when scope == AttributeScope.Method => new FormalParameterTarget(),
                TargetType.ThrowsClause when scope == AttributeScope.Method => new ThrowsTarget(),
                TargetType.LocalVariableDeclaration when scope == AttributeScope.Code => new LocalvarTarget(),
                TargetType.ResourceVariableDeclaration when scope == AttributeScope.Code => new LocalvarTarget(),
                TargetType.ExceptionParameterDeclaration when scope == AttributeScope.Code => new CatchTarget(),
                TargetType.InstanceOfExpression when scope == AttributeScope.Code => new OffsetTarget(),
                TargetType.NewExpression when scope == AttributeScope.Code => new OffsetTarget(),
                TargetType.MethodReferenceExpressionNew when scope == AttributeScope.Code => new OffsetTarget(),
                TargetType.MethodReferenceExpressionIdentifier when scope == AttributeScope.Code => new OffsetTarget(),
                TargetType.CastExpression when scope == AttributeScope.Code => new TypeArgumentTarget(),
                TargetType.ArgumentForGenericConstructorInvocation when scope == AttributeScope.Code => new TypeArgumentTarget(),
                TargetType.ArgumentForGenericMethodInvocation when scope == AttributeScope.Code => new TypeArgumentTarget(),
                TargetType.ArgumentForGenericMethodReferenceExpressionNew when scope == AttributeScope.Code => new TypeArgumentTarget(),
                TargetType.ArgumentForGenericMethodReferenceExpressionIdentifier when scope == AttributeScope.Code => new TypeArgumentTarget(),
                _ => throw new ArgumentOutOfRangeException(nameof(TargetType))
            };
            typeAnnotation.Target.Read(stream, readerState);
            typeAnnotation.TypePath = new TypePath();
            typeAnnotation.TypePath.Read(stream, readerState);
            var elementValuePairsCount = Binary.BigEndian.ReadUInt16(stream);

            typeAnnotation.ElementValuePairs.Capacity = elementValuePairsCount;
            for (var i = 0; i < elementValuePairsCount; i++)
            {
                typeAnnotation.ElementValuePairs.Add(new ElementValuePair
                {
                    ElementName = readerState.ConstantPool
                                  .GetEntry <Utf8Entry>(Binary.BigEndian.ReadUInt16(stream)).String,
                    Value = ElementValue.Parse(stream, readerState)
                });
            }
            return(typeAnnotation);
        }