public JavaObject(JniWrapper vm, IntPtr objectPointer, JavaClass javaClass) { _vm = vm; _objectPointer = objectPointer; _methodClass = new JMethodClass(_vm); _classClass = new JClassClass(_vm); _objectClass = new JObjectClass(_vm); if (javaClass == null && _objectPointer != IntPtr.Zero) { _class = new JavaClass(vm, jniClass: vm.GetObjectClass(_objectPointer), reflectedClass: _objectClass.GetClass(_objectPointer), name: null); } else { _class = javaClass; } }
public static JavaType FromReflectedType(JniWrapper vm, IntPtr reflectedType) { string name = new JClassClass(vm).GetName(reflectedType); if (name.StartsWith("[")) { return(TypeByJniName(vm, name)); } PrimitiveType primitiveType = PrimitiveType.FromString(vm, name); if (primitiveType != null) { return(primitiveType); } return(new JavaClass(vm, IntPtr.Zero, reflectedType, name)); }
internal JavaClass(JniWrapper vm, IntPtr jniClass, IntPtr reflectedClass, string name) { _vm = vm; _classClass = new JClassClass(vm); _methodClass = new JMethodClass(vm); _fieldClass = new JFieldClass(vm); _constructorClass = new JConstructorClass(vm); _classLoaderClass = new JClassLoaderClass(vm); _jniClass = jniClass; _reflectedClass = reflectedClass; if (_reflectedClass == IntPtr.Zero) { if (name == null) { throw new ArgumentNullException("I can't infer the name from just the JNI class (I should be able to, but I have no idea how)."); } _reflectedClass = _classClass.ForName(name.Replace('/', '.'), true, _classLoaderClass.GetSystemClassLoader()); if (_reflectedClass == IntPtr.Zero) { ThrowClassNotFoundException(name); } } if (name == null) { name = _classClass.GetName(_reflectedClass); } if (_jniClass == IntPtr.Zero) { _jniClass = vm.FindClass(name.Replace('.', '/')); if (_jniClass == IntPtr.Zero) { ThrowClassNotFoundException(name); } } _name = name.Replace('/', '.'); _allMethods = _classClass.GetMethods(_reflectedClass).ToList().AsReadOnly(); _allConstructors = _classClass.GetConstructors(_reflectedClass).ToList().AsReadOnly(); }