Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JavaMethod"/> class.
 /// </summary>
 /// <param name="accessFlags">The access flags.</param>
 /// <param name="nameIndex">Index of the name.</param>
 /// <param name="descriptorIndex">Index of the descriptor.</param>
 /// <param name="attributesCount">The attributes count.</param>
 /// <param name="attributes">The attributes.</param>
 public JavaMethod(JavaMethodAccessFlags accessFlags, ushort nameIndex, ushort descriptorIndex, ushort attributesCount, IJavaAttribute[] attributes)
 {
     AccessFlags     = accessFlags;
     NameIndex       = nameIndex;
     DescriptorIndex = descriptorIndex;
     AttributesCount = attributesCount;
     Attributes      = attributes;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads a method from the stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        /// <param name="constantPool">The constant pool used for finding the attribute names.</param>
        /// <returns>The method read from the stream.</returns>
        private static JavaMethod ReadMethod(Stream stream, JavaConstantPool constantPool)
        {
            JavaMethodAccessFlags flags = (JavaMethodAccessFlags)stream.ReadShort();
            ushort nameIndex            = stream.ReadShort();
            ushort descriptorIndex      = stream.ReadShort();
            ushort attributesCount      = stream.ReadShort();

            IJavaAttribute[] attributes = JavaAttribute.ReadFromStream(stream, attributesCount, constantPool);
            return(new JavaMethod(flags, nameIndex, descriptorIndex, attributesCount, attributes));
        }
Ejemplo n.º 3
0
        public static void ConstructorTest()
        {
            JavaMethodAccessFlags flags = JavaMethodAccessFlags.Native | JavaMethodAccessFlags.Private;
            ushort us1 = 1;
            ushort us2 = 2;
            ushort us3 = 3;

            IJavaAttribute[] attributes = new IJavaAttribute[2];
            JavaMethod       jm         = new JavaMethod(flags, us1, us2, us3, attributes);

            AssertThat(jm.AccessFlags).IsEqualTo(flags);
            AssertThat(jm.NameIndex).IsEqualTo(us1);
            AssertThat(jm.DescriptorIndex).IsEqualTo(us2);
            AssertThat(jm.AttributesCount).IsEqualTo(us3);
            AssertThat(jm.Attributes).ContainsExactly(attributes);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the type attributes.
        /// </summary>
        /// <param name="jm">The java method.</param>
        /// <returns>The type attributes of the method.</returns>
        public static MethodAttributes GetAttributes(this JavaMethod jm)
        {
            Guard.NotNull(ref jm, nameof(jm));
            JavaMethodAccessFlags accessFlags = jm.AccessFlags;

            MethodAttributes result = MethodAttributes.HideBySig;

            if (accessFlags.HasFlag(JavaMethodAccessFlags.Abstract))
            {
                result |= MethodAttributes.Abstract;
            }

            if (accessFlags.HasFlag(JavaMethodAccessFlags.Final))
            {
                result |= MethodAttributes.Final;
            }
            else
            {
                result |= MethodAttributes.Virtual;
            }

            if (accessFlags.HasFlag(JavaMethodAccessFlags.Public))
            {
                result |= MethodAttributes.Public;
            }

            if (accessFlags.HasFlag(JavaMethodAccessFlags.Private))
            {
                result |= MethodAttributes.Private;
            }

            if (accessFlags.HasFlag(JavaMethodAccessFlags.Protected))
            {
                result |= MethodAttributes.Family;
            }

            if (accessFlags.HasFlag(JavaMethodAccessFlags.Static))
            {
                result |= MethodAttributes.Static;
            }

            return(result);
        }