Example #1
0
            public override void Write(JavaWriter wtr)
            {
                wtr.Write16(wtr.ConstUtf8(tag));
                wtr.Fork();
                wtr.Write16(methods.Length);
                for (int i = 0; i < methods.Length; i++)
                {
                    wtr.Write16(wtr.ConstMethodHandle(methods[i].mh));
                    var args = methods[i].args;
                    wtr.Write16(args.Length);
                    for (int j = 0; j < args.Length; j++)
                    {
                        ushort constantIndex;
                        var    value = args[j];

                        if (value is int intValue)
                        {
                            constantIndex = wtr.ConstInteger(intValue);
                        }

                        else if (value is float floatValue)
                        {
                            constantIndex = wtr.ConstFloat(floatValue);
                        }

                        else if (value is long longValue)
                        {
                            constantIndex = wtr.ConstLong(longValue);
                        }

                        else if (value is double doubleValue)
                        {
                            constantIndex = wtr.ConstDouble(doubleValue);
                        }

                        else if (value is JavaType classValue)
                        {
                            constantIndex = wtr.ConstClass(classValue);
                        }

                        else if (value is string stringValue)
                        {
                            constantIndex = wtr.ConstString(stringValue);
                        }

                        else if (value is JavaMethodHandle methodHandleValue)
                        {
                            constantIndex = wtr.ConstMethodHandle(methodHandleValue);
                        }

                        else if (value is JavaMethodType methodTypeValue)
                        {
                            constantIndex = wtr.ConstMethodType(methodTypeValue);
                        }
                        else
                        {
                            throw wtr.Where.Exception($"invalid constant value");
                        }

                        wtr.Write16(constantIndex);
                    }
                }
                wtr.Join();
            }