Java.Method INamesController.GetAnonumousAccessMethod()
        {
            int index = 0;

            while (currentJavaClass.Methods.Where(M => M.Name == ClassNames.AccessMethodPrefix + index.ToString()).Count() > 0)
            {
                index++;
            }

            Java.Method result = new Java.Method();
            result.Name = ClassNames.AccessMethodPrefix + index.ToString();

            currentJavaClass.Methods.Add(result);

            return(result);
        }
Esempio n. 2
0
        private void GenerateBaseByRefType(JavaPrimitiveType type)
        {
            if ((baseTypesGenerated & (1 << (int)type)) != 0)
            {
                return;
            }

            Java.Class javaClass = new Java.Class();
            javaClass.AccessFlag = Java.ClassAccessFlag.Abstract | Java.ClassAccessFlag.Public | Java.ClassAccessFlag.Super;
            javaClass.ThisClass  = TypeNameToJava(new JavaByRefType(ByRefPlace.Unknown, type).ToString());
            javaClass.SuperClass = TypeNameToJava(ClassNames.JavaObject);

            Java.Method ctor = new Java.Method();
            ctor.AccessFlags = Java.MethodAccessFlags.Public;
            ctor.Name        = ClassNames.JavaConstructorMethodName;
            ctor.Descriptor  = "()V";

            JavaBytecodeWriter ctorCodeGenerator = new JavaBytecodeWriter();

            ctorCodeGenerator
            .AddLocalVarInstruction(LocalVarInstruction.Load, JavaPrimitiveType.Ref, 0, null)
            .AddInstruction(new JavaInstruction(Java.OpCodes.invokespecial, ClassNames.JavaObjectCtorMethodRef))
            .AddReturn(JavaPrimitiveType.Void, null);
            Java.Attributes.Code ctorCode = new Java.Attributes.Code();
            ctorCode.CodeBytes = ctorCodeGenerator.Link(javaClass.ConstantPool);
            ctorCode.MaxLocals = 1;
            ctorCode.MaxStack  = 1;
            ctor.Attributes.Add(ctorCode);
            javaClass.Methods.Add(ctor);

            Java.Method getValue = new Java.Method();
            getValue.AccessFlags = Java.MethodAccessFlags.Abstract | Java.MethodAccessFlags.Public;
            getValue.Name        = ClassNames.ByRef.GetValueMethodName;
            getValue.Descriptor  = GetByRefGetValueDescriptor(type);
            javaClass.Methods.Add(getValue);

            Java.Method setValue = new Java.Method();
            setValue.AccessFlags = Java.MethodAccessFlags.Abstract | Java.MethodAccessFlags.Public;
            setValue.Name        = ClassNames.ByRef.SetValueMethodName;
            setValue.Descriptor  = GetByRefSetValueDescriptor(type);
            javaClass.Methods.Add(setValue);

            WriteClass(javaClass);

            baseTypesGenerated |= (1 << (int)type);
        }
Esempio n. 3
0
        private void GenerateLocalByRefType(JavaPrimitiveType type)
        {
            GenerateBaseByRefType(type);

            string valueFieldDesc = "L" + TypeNameToJava(ClassNames.JavaObject) + ";";

            if (type != JavaPrimitiveType.Ref)
            {
                valueFieldDesc = JavaPrimitive2FieldChar[(int)type].ToString();
            }

            Java.Class javaClass = new Java.Class();
            javaClass.AccessFlag = Java.ClassAccessFlag.Final | Java.ClassAccessFlag.Public | Java.ClassAccessFlag.Super;
            javaClass.ThisClass  = TypeNameToJava(new JavaByRefType(ByRefPlace.Local, type).ToString());
            javaClass.SuperClass = TypeNameToJava(new JavaByRefType(ByRefPlace.Unknown, type).ToString());

            Java.Field valueField = new Java.Field();
            valueField.AccessFlags = Java.FieldAccessFlags.Private;
            valueField.Name        = "value";
            valueField.Descriptor  = valueFieldDesc;
            javaClass.Fields.Add(valueField);

            Java.Constants.FieldRef  valueRef     = new Java.Constants.FieldRef(javaClass.ThisClass, "value", valueFieldDesc);
            Java.Constants.MethodRef superCtorRef =
                new Java.Constants.MethodRef(javaClass.SuperClass, ClassNames.JavaConstructorMethodName, "()V");

            Java.Method ctor = new Java.Method();
            ctor.AccessFlags = Java.MethodAccessFlags.Public;
            ctor.Name        = ClassNames.JavaConstructorMethodName;
            ctor.Descriptor  = "(" + valueFieldDesc + ")V";
            ctor.Attributes.Add(new JavaBytecodeWriter()
                                .Add(OpCodes.aload_0)
                                .Add(OpCodes.invokespecial, superCtorRef)
                                .Add(OpCodes.aload_0)
                                .AddLoad(type, 1)
                                .Add(OpCodes.putfield, valueRef)
                                .AddReturn(JavaPrimitiveType.Void)
                                .End(javaClass.ConstantPool)
                                );
            javaClass.Methods.Add(ctor);

            Java.Method get = new Method();
            get.AccessFlags = Java.MethodAccessFlags.Public;
            get.Name        = ClassNames.ByRef.GetValueMethodName;
            get.Descriptor  = "()" + valueFieldDesc;
            get.Attributes.Add(new JavaBytecodeWriter()
                               .Add(OpCodes.aload_0)
                               .Add(OpCodes.getfield, valueRef)
                               .AddReturn(type)
                               .End(javaClass.ConstantPool));
            javaClass.Methods.Add(get);

            Java.Method set = new Method();
            set.AccessFlags = MethodAccessFlags.Public;
            set.Name        = ClassNames.ByRef.SetValueMethodName;
            set.Descriptor  = "(" + valueFieldDesc + ")V";
            set.Attributes.Add(new JavaBytecodeWriter()
                               .Add(OpCodes.aload_0)
                               .AddLoad(type, 1)
                               .Add(OpCodes.putfield, valueRef)
                               .AddReturn(JavaPrimitiveType.Void)
                               .End(javaClass.ConstantPool));
            javaClass.Methods.Add(set);

            WriteClass(javaClass);
        }