Esempio n. 1
0
        public ArrayType(JavaType memberType)
        {
            if (memberType == null)
            {
                throw new ArgumentNullException("memberType");
            }

            _memberType = memberType;
        }
Esempio n. 2
0
		public ArrayType(JavaType memberType)
		{
			if (memberType == null)
			{
				throw new ArgumentNullException("memberType");
			}

			_memberType = memberType;
		}
Esempio n. 3
0
		public override bool IsAssignableFrom(JavaType other)
		{
			if (other is NullType)
			{
				return false; // You can't use null's with primitives.
			}
			PrimitiveType asPrimitive = other as PrimitiveType;
			if (asPrimitive != null)
			{
				return asPrimitive.IsWideningOrIdentityConvertibleTo(this);
			}
			JavaClass asClass = (JavaClass)other;
			JavaClass boxed = GetBoxClass();
			return boxed.IsAssignableFrom(asClass);
		}
Esempio n. 4
0
		public override bool IsAssignableFrom(JavaType other)
		{
			if (other is NullType)
			{
				return true;
			}

			ArrayType asArray = other as ArrayType;
			
			if (asArray == null)
			{
				return false;
			}

			return _memberType.IsAssignableFrom(asArray._memberType) &&
				(_memberType is JavaClass || asArray._memberType.IsAssignableFrom(_memberType));
		}
Esempio n. 5
0
        public override bool IsAssignableFrom(JavaType other)
        {
            if (other is NullType)
            {
                return(true);
            }

            ArrayType asArray = other as ArrayType;

            if (asArray == null)
            {
                return(false);
            }

            return(_memberType.IsAssignableFrom(asArray._memberType) &&
                   (_memberType is JavaClass || asArray._memberType.IsAssignableFrom(_memberType)));
        }
Esempio n. 6
0
        public override bool IsAssignableFrom(JavaType other)
        {
            if (other is NullType)
            {
                return(false);                // You can't use null's with primitives.
            }
            PrimitiveType asPrimitive = other as PrimitiveType;

            if (asPrimitive != null)
            {
                return(asPrimitive.IsWideningOrIdentityConvertibleTo(this));
            }
            JavaClass asClass = (JavaClass)other;
            JavaClass boxed   = GetBoxClass();

            return(boxed.IsAssignableFrom(asClass));
        }
Esempio n. 7
0
        public override bool IsAssignableFrom(JavaType other)
        {
            if (other is NullType)
            {
                return(true);                // Reference types should accept null.
            }
            if (other is ArrayType)
            {
                return(false);
            }
            JavaClass asClass = other as JavaClass;

            if (asClass == null)
            {
                asClass = ((PrimitiveType)other).GetBoxClass();
            }
            return(_classClass.IsAssignableFrom(_reflectedClass, asClass._reflectedClass));
        }
Esempio n. 8
0
        private bool ParameterTypesMatch(IEnumerable <JavaType> actualParameterTypes, IntPtr[] formalParameterTypes, out bool[] needBoxing,
                                         out JavaType[] formalParameterTypeInfo)
        {
            // See http://docs.oracle.com/javase/specs/jls/se5.0/html/expressions.html#15.12
            // 1. Accepts the same number of parameters as given and
            // 2. The parameter types are assignable (I forgive unknown parametery types now and just assume they're equivalent to anything).

            if (formalParameterTypes.Length != actualParameterTypes.Count())
            {
                needBoxing = null;
                formalParameterTypeInfo = null;
                return(false);
            }
            int currentIndex = 0;

            needBoxing = new bool[formalParameterTypes.Length];
            formalParameterTypeInfo = new JavaType[formalParameterTypes.Length];
            foreach (JavaType actualParameter in actualParameterTypes)
            {
                if (actualParameter != null)
                {
                    formalParameterTypeInfo[currentIndex] = JavaType.FromReflectedType(_vm, formalParameterTypes[currentIndex]);
                    if (!formalParameterTypeInfo[currentIndex].IsAssignableFrom(actualParameter))
                    {
                        needBoxing = null;
                        return(false);
                    }
                    ArrayType formalAsArray, actualAsArray;
                    needBoxing[currentIndex] = (actualParameter is PrimitiveType && !(formalParameterTypeInfo[currentIndex] is PrimitiveType)) ||
                                               ((actualAsArray = actualParameter as ArrayType) != null && (formalAsArray = formalParameterTypeInfo[currentIndex] as ArrayType) != null &&
                                                actualAsArray.MemberType is PrimitiveType && !(formalAsArray.MemberType is PrimitiveType));
                }
                else
                {
                    needBoxing[currentIndex] = false;
                }
                currentIndex++;
            }
            return(true);
        }
Esempio n. 9
0
 public override bool IsAssignableFrom(JavaType other)
 {
     return(true);            // Anything can be assigned to null. That's not the normal case though.
 }
Esempio n. 10
0
 private JavaObjectFactory(Func <object, JValue> factory, JavaType javaType)
 {
     _javaType = javaType;
     _factory  = factory;
 }
Esempio n. 11
0
 private ParameterInfo(JValue value, JavaType type)
 {
     _value = value;
     _type  = type;
 }
Esempio n. 12
0
 public abstract bool IsAssignableFrom(JavaType other);
Esempio n. 13
0
		public abstract bool IsAssignableFrom(JavaType other);
Esempio n. 14
0
        private object InvokeMethod(IntPtr method, ParameterInfo[] parameterInfo, bool[] needBoxing)
        {
            object result;
            IntPtr methodReturn   = _methodClass.GetReturnType(method);
            IntPtr jniMethodPtr   = _vm.FromReflectedMethod(method);
            string returnTypeName = _classClass.GetName(methodReturn);

            JValue[]      parameters            = parameterInfo.Select((p, i) => p.Value(_vm, needBoxing[i])).ToArray();
            PrimitiveType returnTypeAsPrimitive = PrimitiveType.FromString(_vm, returnTypeName);

            if (methodReturn == IntPtr.Zero || returnTypeName == "void")
            {
                result = null;
                _vm.CallVoidMethod(_objectPointer, jniMethodPtr, parameters);
            }
            else if (returnTypeAsPrimitive != null)
            {
                switch (returnTypeAsPrimitive.Kind)
                {
                case PrimitiveTypeKind.Boolean:
                    result = _vm.CallBooleanMethod(_objectPointer, jniMethodPtr, parameters);
                    break;

                case PrimitiveTypeKind.Byte:
                    result = _vm.CallByteMethod(_objectPointer, jniMethodPtr, parameters);
                    break;

                case PrimitiveTypeKind.Char:
                    result = _vm.CallCharMethod(_objectPointer, jniMethodPtr, parameters);
                    break;

                case PrimitiveTypeKind.Double:
                    result = _vm.CallDoubleMethod(_objectPointer, jniMethodPtr, parameters);
                    break;

                case PrimitiveTypeKind.Float:
                    result = _vm.CallFloatMethod(_objectPointer, jniMethodPtr, parameters);
                    break;

                case PrimitiveTypeKind.Int:
                    result = _vm.CallIntMethod(_objectPointer, jniMethodPtr, parameters);
                    break;

                case PrimitiveTypeKind.Long:
                    result = _vm.CallLongMethod(_objectPointer, jniMethodPtr, parameters);
                    break;

                case PrimitiveTypeKind.Short:
                    result = _vm.CallShortMethod(_objectPointer, jniMethodPtr, parameters);
                    break;

                default:
                    throw new InvalidOperationException("Unknown primitive type: " + returnTypeAsPrimitive.Kind);
                }
            }
            else
            {
                IntPtr methodResult = _vm.CallObjectMethod(_objectPointer, jniMethodPtr, parameters);
                if (methodResult != IntPtr.Zero)
                {
                    if (returnTypeName.StartsWith("["))
                    {
                        result = new JavaArray(_vm, methodResult, (ArrayType)JavaType.FromReflectedType(_vm, methodReturn));
                    }
                    else
                    {
                        result = new JavaObject(_vm, methodResult, null);
                    }
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }
Esempio n. 15
0
		public override bool IsAssignableFrom(JavaType other)
		{
			return true; // Anything can be assigned to null. That's not the normal case though.
		}
Esempio n. 16
0
			private JavaObjectFactory(Func<object, JValue> factory, JavaType javaType)
			{
				_javaType = javaType;
				_factory = factory;
			}
Esempio n. 17
0
		private ParameterInfo(JValue value, JavaType type)
		{
			_value = value;
			_type = type;
		}