private static bool IsStaticallyInvocable(FieldWrapper fw)
 {
     return(fw != null &&
            !fw.FieldTypeWrapper.IsUnloadable &&
            !fw.FieldTypeWrapper.IsGhost &&
            !fw.FieldTypeWrapper.IsNonPrimitiveValueType);
 }
Example #2
0
    // this overload is called via a map.xml patch to the MemberName(Method, boolean) constructor, because we need wantSpecial
    public static void init(MemberName self, object refObj, bool wantSpecial)
    {
#if !FIRST_PASS
        JlReflect.Method      method;
        JlReflect.Constructor constructor;
        JlReflect.Field       field;
        if ((method = refObj as JlReflect.Method) != null)
        {
            InitMethodImpl(self, MethodWrapper.FromExecutable(method), wantSpecial);
        }
        else if ((constructor = refObj as JlReflect.Constructor) != null)
        {
            InitMethodImpl(self, MethodWrapper.FromExecutable(constructor), wantSpecial);
        }
        else if ((field = refObj as JlReflect.Field) != null)
        {
            FieldWrapper fw = FieldWrapper.FromField(field);
            self._clazz(fw.DeclaringType.ClassObject);
            int flags = (int)fw.Modifiers | MethodHandleNatives.Constants.MN_IS_FIELD;
            flags |= (fw.IsStatic ? MethodHandleNatives.Constants.REF_getStatic : MethodHandleNatives.Constants.REF_getField) << MethodHandleNatives.Constants.MN_REFERENCE_KIND_SHIFT;
            self._flags(flags);
        }
        else
        {
            throw new InvalidOperationException();
        }
#endif
    }
Example #3
0
        private static FieldWrapper GetFieldWrapper(object thisObj, RuntimeTypeHandle type, string clazz, string name, string sig, bool isStatic)
        {
            TypeWrapper  caller  = ClassLoaderWrapper.GetWrapperFromType(Type.GetTypeFromHandle(type));
            TypeWrapper  wrapper = LoadTypeWrapper(type, clazz);
            FieldWrapper field   = wrapper.GetFieldWrapper(name, sig);

            if (field == null)
            {
                throw new java.lang.NoSuchFieldError(clazz + "." + name);
            }
            // TODO check loader constraints
            if (field.IsStatic != isStatic)
            {
                throw new java.lang.IncompatibleClassChangeError(clazz + "." + name);
            }
            TypeWrapper objType = null;

            if (thisObj != null)
            {
                objType = ClassLoaderWrapper.GetWrapperFromType(thisObj.GetType());
            }
            if (field.IsAccessibleFrom(wrapper, caller, objType))
            {
                return(field);
            }
            throw new java.lang.IllegalAccessError(field.DeclaringType.Name + "." + name);
        }
Example #4
0
        static ProxyGenerator()
        {
            ClassLoaderWrapper bootClassLoader = ClassLoaderWrapper.GetBootstrapClassLoader();

            proxyClass            = bootClassLoader.LoadClassByDottedNameFast("java.lang.reflect.Proxy");
            errorClass            = bootClassLoader.LoadClassByDottedNameFast("java.lang.Error");
            runtimeExceptionClass = bootClassLoader.LoadClassByDottedNameFast("java.lang.RuntimeException");
            undeclaredThrowableExceptionConstructor = bootClassLoader.LoadClassByDottedNameFast("java.lang.reflect.UndeclaredThrowableException").GetMethodWrapper("<init>", "(Ljava.lang.Throwable;)V", false);
            undeclaredThrowableExceptionConstructor.Link();
            invocationHandlerField = proxyClass.GetFieldWrapper("h", "Ljava.lang.reflect.InvocationHandler;");
            invocationHandlerField.Link();
            javaLangReflectMethod                   = bootClassLoader.LoadClassByDottedNameFast("java.lang.reflect.Method");
            javaLangNoSuchMethodException           = bootClassLoader.LoadClassByDottedNameFast("java.lang.NoSuchMethodException");
            javaLangNoClassDefFoundErrorConstructor = bootClassLoader.LoadClassByDottedNameFast("java.lang.NoClassDefFoundError").GetMethodWrapper("<init>", "(Ljava.lang.String;)V", false);
            javaLangNoClassDefFoundErrorConstructor.Link();
            javaLangThrowable_getMessage = bootClassLoader.LoadClassByDottedNameFast("java.lang.Throwable").GetMethodWrapper("getMessage", "()Ljava.lang.String;", false);
            javaLangThrowable_getMessage.Link();
            javaLangClass_getMethod = CoreClasses.java.lang.Class.Wrapper.GetMethodWrapper("getMethod", "(Ljava.lang.String;[Ljava.lang.Class;)Ljava.lang.reflect.Method;", false);
            javaLangClass_getMethod.Link();
            invocationHandlerClass = bootClassLoader.LoadClassByDottedNameFast("java.lang.reflect.InvocationHandler");
            invokeMethod           = invocationHandlerClass.GetMethodWrapper("invoke", "(Ljava.lang.Object;Ljava.lang.reflect.Method;[Ljava.lang.Object;)Ljava.lang.Object;", false);
            proxyConstructor       = proxyClass.GetMethodWrapper("<init>", "(Ljava.lang.reflect.InvocationHandler;)V", false);
            proxyConstructor.Link();
            hashCodeMethod = CoreClasses.java.lang.Object.Wrapper.GetMethodWrapper("hashCode", "()I", false);
            equalsMethod   = CoreClasses.java.lang.Object.Wrapper.GetMethodWrapper("equals", "(Ljava.lang.Object;)Z", false);
            toStringMethod = CoreClasses.java.lang.Object.Wrapper.GetMethodWrapper("toString", "()Ljava.lang.String;", false);
        }
Example #5
0
        internal override void Generate(CodeGenContext context, CodeEmitter ilgen)
        {
            FieldWrapper fw = ClassLoaderWrapper.LoadClassCritical(Class).GetFieldWrapper(Name, Sig);

            fw.Link();
            ilgen.Emit(OpCodes.Ldflda, fw.GetField());
        }
Example #6
0
        public void AddField(string name, int col)
        {
            if (parsers.ContainsKey(name))
            {
                throw new FieldException("allready constains a field with that name");
            }
            if (!Array.Exists(fi, f => f.Name == name))
            {
                throw new FieldException($"No such field found in {type.Name}");
            }

            CsvBasicInfo bInfo     = new CsvBasicInfo(type, name, col, separator);
            FieldInfo    fInfo     = type.GetField(name);
            Type         fieldType = fInfo.FieldType;                           // prop Type
            FieldWrapper fw;
            IReflection  reflect;

            if (ReflectorsCache.cache.TryGetValue(fieldType, out reflect))
            {
                fw = new FieldWrapper((FieldReflect)reflect, bInfo);
                parsers.Add(name, fw);
            }
            else
            {
                FieldReflect fr = new FieldReflect(fieldType);
                ReflectorsCache.cache.Add(fieldType, fr);
                fw = new FieldWrapper(fr, bInfo);
                parsers.Add(name, fw);
            }
        }
        public void 필드래퍼는_값이변경될때_알려줍니다()
        {
            // Arrange (데이터 정렬)
            int iTestValue     = Random.Range(0, 5);
            int iTestValue_Add = Random.Range(6, 10);
            FieldWrapper <int> pFieldWrapper_Int = new FieldWrapper <int>(iTestValue, 알람을_받았다_1);

            iListenCount = 0;



            // Act (기능 실행)
            pFieldWrapper_Int.Value += iTestValue_Add;

            // Assert (맞는지 체크)
            Assert.AreEqual(iListenCount, 1);



            // Act (기능 실행)
            pFieldWrapper_Int.Subscribe += 알람을_받았다_2;
            pFieldWrapper_Int.Value     += iTestValue_Add;

            // Assert (맞는지 체크)
            Assert.AreEqual(iListenCount, 3);
        }
        public void 필드래퍼는_옵저버를추가할때_조건함수를_붙일수있습니다()
        {
            // Arrange (데이터 정렬)
            int iTestValue = 3;
            FieldWrapper <int> pFieldWrapper_Int = new FieldWrapper <int>(iTestValue);

            pFieldWrapper_Int.DoAddObserver_WithCondition(값이_5이상일때, 알람을_받았다_1);
            iListenCount = 0;



            // Act (기능 실행)
            pFieldWrapper_Int.Value += 1;

            // Assert (맞는지 체크)
            Assert.AreEqual(pFieldWrapper_Int.Value, 4);
            Assert.AreEqual(iListenCount, 0);



            // Act (기능 실행)
            pFieldWrapper_Int.Value += 1;

            // Assert (맞는지 체크)
            Assert.AreEqual(pFieldWrapper_Int.Value, 5);
            Assert.AreEqual(iListenCount, 1);
        }
        public void 필드래퍼는_초기값을_할당할수_있습니다()
        {
            // Arrange (데이터 정렬)
            int    iTestValue = Random.Range(0, 5);
            string strValue   = Random.Range(5, 10).ToString();



            // Act (기능 실행)
            // 디폴트 버전
            FieldWrapper <int>    pFieldWrapper_Int_0       = new FieldWrapper <int>();
            FieldWrapper <string> pFieldWrapper_String_Null = new FieldWrapper <string>();

            // 초기값 할당 버전
            FieldWrapper <int>    pFieldWrapper_Int_1  = new FieldWrapper <int>(iTestValue);
            FieldWrapper <string> pFieldWrapper_String = new FieldWrapper <string>(strValue);



            // Assert (맞는지 체크)
            Assert.AreEqual(pFieldWrapper_Int_0.Value, default(int));
            Assert.AreEqual(pFieldWrapper_String_Null.Value, default(string));

            Assert.AreEqual(pFieldWrapper_Int_1.Value, iTestValue);
            Assert.AreEqual(pFieldWrapper_String.Value, strValue);
        }
Example #10
0
 internal static bool Emit(DynamicTypeWrapper.FinishContext context, TypeWrapper wrapper, CodeEmitter ilgen, ClassFile classFile, int i, ClassFile.Method.Instruction[] code, InstructionFlags[] flags)
 {
     if (i >= 3 &&
         (flags[i - 0] & InstructionFlags.BranchTarget) == 0 &&
         (flags[i - 1] & InstructionFlags.BranchTarget) == 0 &&
         (flags[i - 2] & InstructionFlags.BranchTarget) == 0 &&
         (flags[i - 3] & InstructionFlags.BranchTarget) == 0 &&
         code[i - 1].NormalizedOpCode == NormalizedByteCode.__ldc_nothrow &&
         code[i - 2].NormalizedOpCode == NormalizedByteCode.__ldc &&
         code[i - 3].NormalizedOpCode == NormalizedByteCode.__ldc)
     {
         // we now have a structural match, now we need to make sure that the argument values are what we expect
         TypeWrapper tclass    = classFile.GetConstantPoolClassType(code[i - 3].Arg1);
         TypeWrapper vclass    = classFile.GetConstantPoolClassType(code[i - 2].Arg1);
         string      fieldName = classFile.GetConstantPoolConstantString(code[i - 1].Arg1);
         if (tclass == wrapper && !vclass.IsUnloadable && !vclass.IsPrimitive && !vclass.IsNonPrimitiveValueType)
         {
             FieldWrapper field = wrapper.GetFieldWrapper(fieldName, vclass.SigName);
             if (field != null && !field.IsStatic && field.IsVolatile && field.DeclaringType == wrapper && field.FieldTypeWrapper == vclass)
             {
                 // everything matches up, now call the actual emitter
                 ilgen.Emit(OpCodes.Pop);
                 ilgen.Emit(OpCodes.Pop);
                 ilgen.Emit(OpCodes.Pop);
                 ilgen.Emit(OpCodes.Newobj, context.GetAtomicReferenceFieldUpdater(field));
                 return(true);
             }
         }
     }
     return(false);
 }
Example #11
0
 internal IEditorValue CreateValue(TypeInformation typeInformation, FieldWrapper currentWrapper, JToken token)
 {
     if (currentWrapper == null)
     {
         if ((typeInformation.Fields?.Count ?? 0) == 0)
         {
             return(new EditorValue(this, typeInformation, token));
         }
         else
         {
             return(new EditorObject(this, typeInformation, token));
         }
     }
     else
     {
         if (currentWrapper.Type == FieldWrapperType.Dictionary)
         {
             return(new EditorDictionary(this, typeInformation, token));
         }
         else if (currentWrapper.Type == FieldWrapperType.List)
         {
             return(new EditorList(this, typeInformation, token));
         }
         else
         {
             throw new InvalidOperationException("Unsupported wrapper type");
         }
     }
 }
Example #12
0
        internal override void Generate(CodeGenContext context, CodeEmitter ilgen)
        {
            FieldWrapper fw = StaticCompiler.GetClassForMapXml(context.ClassLoader, Class).GetFieldWrapper(Name, Sig);

            fw.Link();
            ilgen.Emit(OpCodes.Ldflda, fw.GetField());
        }
        public void 필드래퍼는_한번만알림기능을_지원합니다()
        {
            // Arrange (데이터 정렬)
            int iTestValue = 3;
            FieldWrapper <int> pFieldWrapper_Int = new FieldWrapper <int>(iTestValue);

            pFieldWrapper_Int.DoAddObserver_WithCondition(값이_5이상일때, 알람을_받았다_1, true);
            iListenCount = 0;



            // Act (기능 실행)
            pFieldWrapper_Int.Value += 1;

            // Assert (맞는지 체크)
            Assert.AreEqual(iListenCount, 0);
            Assert.AreEqual(pFieldWrapper_Int.iObserverCount, 1);


            // Act (기능 실행)
            pFieldWrapper_Int.Value += 1;

            // Assert (맞는지 체크)
            Assert.AreEqual(iListenCount, 1);
            Assert.AreEqual(pFieldWrapper_Int.iObserverCount, 0);
        }
Example #14
0
        internal override void Generate(CodeGenContext context, CodeEmitter ilgen)
        {
            FieldWrapper fw = ClassLoaderWrapper.LoadClassCritical(Class).GetFieldWrapper(Name, Sig);

            fw.Link();
            // we don't use fw.EmitSet because we don't want automatic unboxing and whatever
            ilgen.Emit(OpCodes.Stsfld, fw.GetField());
        }
Example #15
0
        internal override void Generate(CodeGenContext context, CodeEmitter ilgen)
        {
            FieldWrapper fw = StaticCompiler.GetClassForMapXml(context.ClassLoader, Class).GetFieldWrapper(Name, Sig);

            fw.Link();
            // we don't use fw.EmitSet because we don't want automatic unboxing and whatever
            ilgen.Emit(OpCodes.Stsfld, fw.GetField());
        }
Example #16
0
    private static FieldInfo GetFieldInfo(long offset)
    {
        FieldWrapper fw = FieldWrapper.FromField(sun.misc.Unsafe.getField(offset));

        fw.Link();
        fw.ResolveField();
        return(fw.GetField());
    }
Example #17
0
        public void TestFieldType()
        {
            FieldWrapper wrapper1 = new FieldWrapper(typeof(DummyClass).GetField(nameof(DummyClass.b)));
            FieldWrapper wrapper2 = new FieldWrapper(typeof(DummyClass).GetField(nameof(DummyClass.i)));

            Assert.Same(typeof(bool), wrapper1.FieldType);
            Assert.Same(typeof(int), wrapper2.FieldType);
        }
Example #18
0
        internal static void Log(string key, long offset)
        {
#if !FIRST_PASS && UNSAFE_STATISTICS
            FieldWrapper field = FieldWrapper.FromField(sun.misc.Unsafe.getField(offset));
            key += field.DeclaringType.Name + "::" + field.Name;
            Log(key);
#endif
        }
    public static void resolve(MemberName self, jlClass caller)
    {
#if !FIRST_PASS
        if (self.isMethod() || self.isConstructor())
        {
            TypeWrapper tw = TypeWrapper.FromClass(self.getDeclaringClass());
            if (tw == CoreClasses.java.lang.invoke.MethodHandle.Wrapper &&
                (self.getName() == "invoke" || self.getName() == "invokeExact"))
            {
                typeof(MemberName).GetField("vmindex", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(self, Int32.MaxValue);
                return;
            }
            MethodWrapper mw = tw.GetMethodWrapper(self.getName(), self.getSignature().Replace('/', '.'), true);
            if (mw != null)
            {
                tw = mw.DeclaringType;
                int index = Array.IndexOf(tw.GetMethods(), mw);
                if (index != -1)
                {
                    // TODO self.setVMIndex(index);
                    typeof(MemberName).GetField("vmindex", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(self, index);
                    typeof(MemberName).GetField("vmtarget", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(self, tw);
                    int flags = (int)mw.Modifiers;
                    if (self.isMethod())
                    {
                        flags |= MemberName.IS_METHOD;
                    }
                    else
                    {
                        flags |= MemberName.IS_CONSTRUCTOR;
                    }
                    typeof(MemberName).GetField("flags", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(self, flags);
                }
            }
        }
        else if (self.isField())
        {
            TypeWrapper tw = TypeWrapper.FromClass(self.getDeclaringClass());
            // TODO should we look in base classes?
            FieldWrapper fw = tw.GetFieldWrapper(self.getName(), self.getSignature().Replace('/', '.'));
            if (fw != null)
            {
                int index = Array.IndexOf(fw.DeclaringType.GetFields(), fw);
                if (index != -1)
                {
                    // TODO self.setVMIndex(index);
                    typeof(MemberName).GetField("vmindex", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(self, index);
                    typeof(MemberName).GetField("flags", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(self, (int)fw.Modifiers | MemberName.IS_FIELD);
                }
            }
        }
        else
        {
            throw new InvalidOperationException();
        }
#endif
    }
Example #20
0
            public static bool isFieldDeprecated(object field)
            {
                FieldWrapper fieldWrapper = FieldWrapper.FromField(field);
                FieldInfo    fi           = fieldWrapper.GetField();

                if (fi != null)
                {
                    return(fi.IsDefined(typeof(ObsoleteAttribute), false));
                }
                return(false);
            }
Example #21
0
        /// <summary>
        /// Attempts to resolve member reference to a field or a property.
        /// </summary>
        private void resolveSelf(Context ctx)
        {
            var type = StaticType != null
                                ? ctx.ResolveType(StaticType)
                                : Expression.Resolve(ctx);

            checkTypeInSafeMode(ctx, type);

            // check for field
            try
            {
                _Field    = ctx.ResolveField(type, MemberName);
                _IsStatic = _Field.IsStatic;
                if (Expression == null && !_IsStatic)
                {
                    error(CompilerMessages.DynamicMemberFromStaticContext, type, MemberName);
                }
            }
            catch (KeyNotFoundException)
            {
                try
                {
                    _Property = ctx.ResolveProperty(type, MemberName);
                    if (!_Property.CanSet)
                    {
                        error(CompilerMessages.PropertyNoSetter, MemberName, type);
                    }

                    _IsStatic = _Property.IsStatic;
                    if (Expression == null && !_IsStatic)
                    {
                        error(CompilerMessages.DynamicMemberFromStaticContext, type, MemberName);
                    }
                }
                catch (KeyNotFoundException)
                {
                    error(CompilerMessages.TypeSettableIdentifierNotFound, type, MemberName);
                }
            }

            var destType = _Field != null ? _Field.FieldType : _Property.PropertyType;

            ensureLambdaInferred(ctx, Value, destType);

            var valType = Value.Resolve(ctx);

            ctx.CheckTypedExpression(Value, valType, true);

            if (!destType.IsExtendablyAssignableFrom(valType))
            {
                error(CompilerMessages.ImplicitCastImpossible, valType, destType);
            }
        }
Example #22
0
 internal override void Generate(CodeGenContext context, CodeEmitter ilgen)
 {
     if (Type != null)
     {
         ilgen.Emit(OpCodes.Ldsfld, StaticCompiler.GetType(context.ClassLoader, Type).GetField(Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
     }
     else
     {
         FieldWrapper fw = ClassLoaderWrapper.LoadClassCritical(Class).GetFieldWrapper(Name, Sig);
         fw.Link();
         // we don't use fw.EmitGet because we don't want automatic unboxing and whatever
         ilgen.Emit(OpCodes.Ldsfld, fw.GetField());
     }
 }
        internal static FieldWrapper GetInstance()
        {
            Field real = default(Field);

            RealInstanceFactory(ref real);
            var instance = (FieldWrapper)FieldWrapper.GetWrapper(real);

            InstanceFactory(ref instance);
            if (instance == null)
            {
                Assert.Inconclusive("Could not Create Test Instance");
            }
            return(instance);
        }
Example #24
0
        public static object DynamicGetstatic(string name, string sig, RuntimeTypeHandle type, string clazz, [email protected] callerID)
        {
            Profiler.Count("DynamicGetstatic");
            FieldWrapper fw = GetFieldWrapper(null, type, clazz, name, sig, true);

            java.lang.reflect.Field field = (java.lang.reflect.Field)fw.ToField(false);
            object val = field.get(null, callerID);

            if (fw.FieldTypeWrapper.IsPrimitive)
            {
                val = JVM.Unbox(val);
            }
            return(val);
        }
Example #25
0
        public static object DynamicGetfield(object obj, string name, string sig, RuntimeTypeHandle type, string clazz, [email protected] callerID)
        {
            Profiler.Count("DynamicGetfield");
            FieldWrapper fw = GetFieldWrapper(ClassLoaderWrapper.GetWrapperFromType(obj.GetType()), type, clazz, name, sig, false);

            java.lang.reflect.Field field = (java.lang.reflect.Field)fw.ToField(false);
            object val = field.get(obj, callerID);

            if (fw.FieldTypeWrapper.IsPrimitive)
            {
                val = JVM.Unbox(val);
            }
            return(val);
        }
Example #26
0
        /// <summary>
        /// Retrieves the field info matching the specified property path on the object given
        /// </summary>
        /// <typeparam name="T">The type of the object</typeparam>
        /// <param name="obj">The object to retrieve the property from</param>
        /// <param name="propertyPath">The path of the property</param>
        /// <param name="type">The Type object corresponding to the object's type</param>
        /// <returns>The property's info</returns>
        private GetSettable GetTargetProperty <T>(T obj, string propertyPath, System.Type type = null)
        {
            System.Type targetType = type ?? typeof(T);
            int         pointIndex = propertyPath.IndexOf(".");

            if (pointIndex != -1)
            {
                string       propertyName = propertyPath.Substring(0, pointIndex);
                GetSettable  property;
                FieldInfo    fieldInfo    = targetType.GetField(propertyName);
                PropertyInfo propertyInfo = targetType.GetProperty(propertyName);
                if (fieldInfo != null)
                {
                    property = new FieldWrapper(fieldInfo, obj);
                }
                else if (propertyInfo != null)
                {
                    property = new PropertyWrapper(propertyInfo, obj);
                }
                else
                {
                    Debug.Log("Property " + propertyName + " not found on object type " + type.ToString());
                    return(null);
                }
                var propertyObj = property.GetValue(obj);
                return(GetTargetProperty(propertyObj, propertyPath.Substring(pointIndex + 1), property.GetSettableType));
            }
            else
            {
                GetSettable  property;
                FieldInfo    fieldInfo    = targetType.GetField(propertyPath);
                PropertyInfo propertyInfo = targetType.GetProperty(propertyPath);
                if (fieldInfo != null)
                {
                    property = new FieldWrapper(fieldInfo, obj);
                }
                else if (propertyInfo != null)
                {
                    property = new PropertyWrapper(propertyInfo, obj);
                }
                else
                {
                    property = null;
                    Debug.Log("Property " + propertyPath + " not found on object type " + type.ToString());
                }
                return(property);
            }
        }
Example #27
0
        /// <summary>
        /// copy field value from source to target. Deep cloning used if necessary
        /// </summary>
        private static void CopyFieldValue(object source, object target, FieldWrapper fieldWrapper, Dictionary <object, object> clonedObjects)
        {
            var value = fieldWrapper.GetValue(source);

            if (value == null)
            {
                return;
            }

            if (fieldWrapper.CloningMode == CloningMode.Deep)
            {
                value = Clone(fieldWrapper.TypeWrapper, value, clonedObjects);
            }

            fieldWrapper.SetValue(target, value);
        }
Example #28
0
        public static void DynamicPutstatic(object val, string name, string sig, RuntimeTypeHandle type, string clazz, [email protected] callerID)
        {
            Profiler.Count("DynamicPutstatic");
            FieldWrapper fw = GetFieldWrapper(null, type, clazz, name, sig, true);

            if (fw.IsFinal)
            {
                throw new java.lang.IllegalAccessError("Field " + fw.DeclaringType.Name + "." + fw.Name + " is final");
            }
            java.lang.reflect.Field field = (java.lang.reflect.Field)fw.ToField(false);
            if (fw.FieldTypeWrapper.IsPrimitive)
            {
                val = JVM.Box(val);
            }
            field.set(null, val, callerID);
        }
Example #29
0
 private MemberInfo Resolve(CodeGenContext context)
 {
     if (type != null)
     {
         if (Class != null || Method != null || Field != null || Sig != null)
         {
             throw new NotImplementedException();
         }
         return(StaticCompiler.GetTypeForMapXml(context.ClassLoader, type));
     }
     else if (Class != null)
     {
         TypeWrapper tw = context.ClassLoader.LoadClassByDottedNameFast(Class);
         if (tw == null)
         {
             return(null);
         }
         else if (Method != null)
         {
             MethodWrapper mw = tw.GetMethodWrapper(Method, Sig, false);
             if (mw == null)
             {
                 return(null);
             }
             return(mw.GetMethod());
         }
         else if (Field != null)
         {
             FieldWrapper fw = tw.GetFieldWrapper(Field, Sig);
             if (fw == null)
             {
                 return(null);
             }
             return(fw.GetField());
         }
         else
         {
             return(tw.TypeAsBaseType);
         }
     }
     else
     {
         return(null);
     }
 }
Example #30
0
    public static bool compareAndSwapObject(object thisUnsafe, object obj, long offset, object expect, object update)
    {
#if FIRST_PASS
        return(false);
#else
        object[] array = obj as object[];
        if (array != null)
        {
            Stats.Log("compareAndSwapObject.array");
            return(Atomic.CompareExchange(array, (int)offset, update, expect) == expect);
        }
        else
        {
            Stats.Log("compareAndSwapObject.", offset);
            FieldInfo field = FieldWrapper.FromField(sun.misc.Unsafe.getField(offset)).GetField();
            return(Atomic.CompareExchange(obj, new FieldInfo[] { field }, update, expect) == expect);
        }
#endif
    }
        public static void WrapPartActionFieldItem(Part part, Action<BaseField, bool> passthrough)
        {
            var controller = UIPartActionController.Instance;
            if (!controller)
                return;

            // get the part action window corresponding to the part
            var window = controller.GetItem(part);
            if (window == null)
                return;

            // get all the items that makes this window (toggle buttons, sliders, etc.)
            var partActionItems = window.ListItems;

            // loop through all of those UI components
            for (var i = 0; i < partActionItems.Count(); i++)
            {
                // check that the part action item is actually a UIPartActionFieldItem (it could be a UIPartActionEventItem)
                var uiPartActionFieldItem = (partActionItems[i] as UIPartActionFieldItem);
                if (uiPartActionFieldItem == null)
                    continue;

                // now check that the UIPartActionFieldItem type (e.g UIPartActionToggle; UIPartActionCycle; UIPartActionFloatRange, etc.)
                // is actually something we can handle.
                if (UIPartActionFieldItemAllowedTypes.All(type => uiPartActionFieldItem.GetType() != type))
                    continue;

                var fieldWrapper = new FieldWrapper(uiPartActionFieldItem, passthrough, false);
            }
        }
Example #32
0
        /// <summary>
        /// Attempts to resolve member reference to a field or a property.
        /// </summary>
        private void resolveSelf(Context ctx)
        {
            var type = StaticType != null
                ? ctx.ResolveType(StaticType)
                : Expression.Resolve(ctx);

            checkTypeInSafeMode(ctx, type);

            // check for field
            try
            {
                _Field = ctx.ResolveField(type, MemberName);
                _IsStatic = _Field.IsStatic;
                if (Expression == null && !_IsStatic)
                    error(CompilerMessages.DynamicMemberFromStaticContext, type, MemberName);
            }
            catch (KeyNotFoundException)
            {
                try
                {
                    _Property = ctx.ResolveProperty(type, MemberName);
                    if (!_Property.CanSet)
                        error(CompilerMessages.PropertyNoSetter, MemberName, type);

                    _IsStatic = _Property.IsStatic;
                    if (Expression == null && !_IsStatic)
                        error(CompilerMessages.DynamicMemberFromStaticContext, type, MemberName);
                }
                catch (KeyNotFoundException)
                {
                    error(CompilerMessages.TypeSettableIdentifierNotFound, type, MemberName);
                }
            }

            var destType = _Field != null ? _Field.FieldType : _Property.PropertyType;
            ensureLambdaInferred(ctx, Value, destType);

            var valType = Value.Resolve(ctx);
            ctx.CheckTypedExpression(Value, valType, true);

            if (!destType.IsExtendablyAssignableFrom(valType))
                error(CompilerMessages.ImplicitCastImpossible, valType, destType);
        }
Example #33
0
 public void SetMember_Sets_The_MemberInfo()
 {
     var fieldWrapper = new FieldWrapper().SetMember<Customer>(c=>c.Name);
     Assert.AreEqual("Name", fieldWrapper.Name);
     Assert.AreEqual(typeof(string),fieldWrapper.Type);
 }
Example #34
0
        /// <summary>
        /// Attempts to resolve current node and sets either of the following fields:
        /// _Field, _Method, _Property
        /// 
        /// The following fields are also set:
        /// _Type, _Static
        /// </summary>
        private void resolveSelf(Context ctx)
        {
            Action check = () =>
            {
                if (Expression == null && !_IsStatic)
                    error(CompilerMessages.DynamicMemberFromStaticContext, _Type, MemberName);

                if (_Method == null && TypeHints.Count > 0)
                    error(CompilerMessages.TypeArgumentsForNonMethod, _Type, MemberName);
            };

            _Type = StaticType != null
                ? ctx.ResolveType(StaticType)
                : Expression.Resolve(ctx);

            // special case: array length
            if (_Type.IsArray && MemberName == "Length")
            {
                check();
                return;
            }

            // check for field
            try
            {
                _Field = ctx.ResolveField(_Type, MemberName);
                _IsStatic = _Field.IsStatic;

                check();
                return;
            }
            catch (KeyNotFoundException) { }

            // check for property
            try
            {
                _Property = ctx.ResolveProperty(_Type, MemberName);

                if(!_Property.CanGet)
                    error(CompilerMessages.PropertyNoGetter, _Type, MemberName);

                _IsStatic = _Property.IsStatic;

                check();
                return;
            }
            catch (KeyNotFoundException) { }

            // check for event: events are only allowed at the left side of += and -=
            try
            {
                ctx.ResolveEvent(_Type, MemberName);
                error(CompilerMessages.EventAsExpr);
            }
            catch (KeyNotFoundException) { }

            // find method
            var argTypes = TypeHints.Select(t => t.FullSignature == "_" ? null : ctx.ResolveType(t)).ToArray();
            var methods = ctx.ResolveMethodGroup(_Type, MemberName).Where(m => checkMethodArgs(argTypes, m)).ToArray();

            if (methods.Length == 0)
                error(argTypes.Length == 0 ? CompilerMessages.TypeIdentifierNotFound : CompilerMessages.TypeMethodNotFound, _Type.Name, MemberName);

            if (methods.Length > 1)
                error(CompilerMessages.TypeMethodAmbiguous, _Type.Name, MemberName);

            _Method = methods[0];
            if (_Method.ArgumentTypes.Length > 16)
                error(CompilerMessages.CallableTooManyArguments);

            _IsStatic = _Method.IsStatic;

            check();
        }
			internal override void Link(TypeWrapper thisType)
			{
				base.Link(thisType);
				lock(this)
				{
					if(fieldTypeWrapper != null)
					{
						return;
					}
				}
				FieldWrapper fw = null;
				TypeWrapper wrapper = GetClassType();
				if(wrapper == null)
				{
					return;
				}
				if(!wrapper.IsUnloadable)
				{
					fw = wrapper.GetFieldWrapper(Name, Signature);
					if(fw != null)
					{
						fw.Link();
					}
				}
				ClassLoaderWrapper classLoader = thisType.GetClassLoader();
				TypeWrapper fld = classLoader.FieldTypeWrapperFromSigNoThrow(this.Signature);
				lock(this)
				{
					if(fieldTypeWrapper == null)
					{
						fieldTypeWrapper = fld;
						field = fw;
					}
				}
			}