/// <summary> /// Read a Exceptions attribute /// </summary> private ExceptionsAttribute ReadExceptionsAttribute(ConstantPool cp) { var result = new ExceptionsAttribute(); var count = stream.ReadU2(); for (var i = 0; i < count; i++) { var index = stream.ReadU2(); result.Exceptions.Add(cp.GetEntry <ConstantPoolClass>(index).Type); } return(result); }
internal MethodDefinition(JavaClassImage classImage, MethodInfo methodInfo) { // Name _name = new LazyValue <string>(() => classImage.ClassFile.ConstantPool.ResolveString(methodInfo.NameIndex) ?? $"<<<INVALID({methodInfo.NameIndex})>>>"); // Flags AccessFlags = methodInfo.AccessFlags; //Descriptor _descriptor = new LazyValue <MethodDescriptor>(() => classImage.ResolveMethodDescriptor(methodInfo.DescriptorIndex)); // Attributes foreach (var attribute in methodInfo.Attributes) { string name = classImage.ClassFile.ConstantPool.ResolveString(attribute.NameIndex); switch (name) { // Code case CodeAttribute.AttributeName: _body = new LazyValue <ByteCodeMethodBody>(() => { var reader = new MemoryBigEndianReader(attribute.Contents); return(new ByteCodeMethodBody(classImage, CodeAttribute.FromReader(reader))); }); break; // Exceptions case ExceptionsAttribute.AttributeName: _exceptions = new LazyValue <IList <ClassReference> >(() => { var reader = new MemoryBigEndianReader(attribute.Contents); var attr = ExceptionsAttribute.FromReader(reader); return(attr.Exceptions .Select(index => classImage.ResolveClass(index)) .ToList()); }); break; default: ExtraAttributes.Add(name, attribute.Clone()); break; } } }
public MethodInfo(ref ReadOnlySpan <byte> data, ClassFile classFile) { AccessFlags = data.ReadTwo(); NameIndex = data.ReadTwo(); Name = ((CUtf8Info)classFile.Constants[NameIndex]).String; DescriptorIndex = data.ReadTwo(); Descriptor = ((CUtf8Info)classFile.Constants[DescriptorIndex]).String; AttributesCount = data.ReadTwo(); Attributes = new AttributeInfo[AttributesCount]; for (int i = 0; i < AttributesCount; i++) { ushort nameIndexNonSwapped = MemoryMarshal.Cast <byte, ushort>(data)[0]; ushort nameIndex = nameIndexNonSwapped.SwapEndian(); string name = ((CUtf8Info)classFile.Constants[nameIndex]).String; switch (name) { case "Code": CodeAttribute code = new CodeAttribute(ref data, classFile.Constants); Attributes[i] = code; MaxStack = code.MaxStack; MaxLocals = code.MaxLocals; CodeAttribute = code; break; case "Exceptions": ExceptionsAttribute exceptionsAttribute = new ExceptionsAttribute(ref data, classFile.Constants); Attributes[i] = exceptionsAttribute; ExceptionsAttribute = exceptionsAttribute; break; case "Deprecated": Attributes[i] = new DeprecatedAttribute(ref data, classFile.Constants); Deprecated = true; break; case "RuntimeVisibleAnnotations": Attributes[i] = new RuntimeVisibleAnnotationsAttribute(ref data, classFile.Constants); break; case "Synthetic": Attributes[i] = new SyntheticAttribute(ref data, classFile.Constants); break; case "Signature": Attributes[i] = new SignatureAttribute(ref data, classFile.Constants); break; case "RuntimeInvisibleAnnotations": case "RuntimeVisibleParameterAnnotations": case "RuntimeInvisibleParameterAnnotations": case "AnnotationDefault": throw new NotImplementedException(); default: Attributes[i] = new AttributeInfo(ref data, classFile.Constants); break; } } ClassFile = classFile; }
public void GetExceptionsSetEmpty() { var attribute = new ExceptionsAttribute(); Assert.That(attribute.GetExceptionsSet(), Is.Empty); }
public void HasAttribute() { Assert.That(ExceptionsAttribute.HasAttribute(typeof(ExceptionsAttributeTest).GetMethod("FunctionWithAttribute")), Is.True); Assert.That(ExceptionsAttribute.HasAttribute(typeof(ExceptionsAttributeTest).GetMethod("FunctionWithoutAttribute")), Is.False); }
public void GetExceptionsSetSeveralElements() { var attribute = new ExceptionsAttribute(10, 20, 30); Assert.That(attribute.GetExceptionsSet(), Is.EquivalentTo(new[] { 30, 20, 10 })); }
public void GetExceptionsSetOneElement() { var attribute = new ExceptionsAttribute(10); Assert.That(attribute.GetExceptionsSet(), Is.EquivalentTo(new[] { 10 })); }