Esempio n. 1
0
func testparse(c *Class, members []member_info, method bool, t *testing.T) {
	for i := range members {
		var p descriptors.DESCRIPTORS
		desc := c.Constant_pool.Lut(members[i].Descriptor_index).String()
		if !p.Parse(desc) || p.RootNode().Range.End != len(desc) {
			t.Errorf("Failed to parse descriptor: %s\n%s\n%s", p.Error(), desc, p.RootNode())
		}
		var p2 signatures.SIGNATURES
		for _, attr := range members[i].Attributes {
			if c.Constant_pool.Lut(attr.Attribute_name_index).String() == "Signature" {
				br := util.BinaryReader{bytes.NewReader(attr.Info), util.BigEndian}
				if i16, err := br.Uint16(); err != nil {
					t.Error(err)
				} else {
					sign := c.Constant_pool.Lut(u2(i16)).String()
					p2.SetData(sign)
					var ret bool
					if method {
						ret = p2.MethodTypeSignature()
					} else {
						ret = p2.FieldTypeSignature()
					}
					p2.RootNode().UpdateRange()
					if !ret || p2.RootNode().Range.End != len(sign) {
						t.Errorf("Failed to parse signature: %s\n%s\n%s", p2.Error(), desc, p2.RootNode())
					}
				}
			}
		}
	}
}
Esempio n. 2
0
func (c *Class) Methods() (methods []content.Method, err error) {
	cn := c.Constant_pool.Lut(c.This_class).String()
	for i, inf := range c.RawMethods {
		var p descriptors.DESCRIPTORS
		desc := c.Constant_pool.Lut(inf.Descriptor_index).String()
		p.Parse(desc)
		outf := descriptors.ToContentMethod(p.RootNode().Children[0])
		outf.Flags = inf.Access_flags.ToContentFlags()
		outf.Name.Relative = c.Constant_pool.Lut(inf.Name_index).String()
		outf.Name.Absolute = fmt.Sprintf("java://method/%s;%d", cn, i)
		methods = append(methods, outf)
	}
	return
}