public JClass toJClass() { global::System.IntPtr cPtr = JNIPINVOKE.JObject_toJClass(swigCPtr); JClass ret = (cPtr == global::System.IntPtr.Zero) ? null : new JClass(cPtr, false); return(ret); }
private static JClass visitClass(Class <Q> ce) { JClass ce2 = new JClass(); ce2.IsAnonymousClass = ce.IsAnonymousClass; ce2.IsSynthetic = ce.IsSynthetic; ce2.Interfaces = visitEachType(ce.GenericInterfaces); ce2.BaseClass = visitType(ce.GenericSuperclass); ce2.Name = ce.Name; visitModifiers(ce2, ce.Modifiers); ce2.IsInterface = ce.IsInterface; ce2.IsEnum = ce.IsEnum; ce2.IsArray = ce.IsArray; if (ce.IsArray) { ce2.ArrayItemType = visitType(ce.ComponentType); } ce2.GenericArguments.AddRange(visitEachTypeVariable(ce.TypeParameters.As <TypeVariable <Q>[]>())); ce2.Classes = visitEachClass(ce.DeclaredClasses.As <Class <Q>[]>().ToList()); List <Constructor <Q> > ctors = ce.DeclaredConstructors.As <Constructor <Q>[]>().ToList(); ce2.Ctors = visitEachCtor(ctors); //TODO:ce.getDeclaredAnnotations(); ce2.Methods = visitEachMethod(ce.DeclaredMethods.ToList()); ce2.Fields = visitEachField(ce.DeclaredFields.ToList()); return(ce2); }
void FixClass(JClass ce) { ce.Classes = ce.Classes.NotNull(); ce.Methods = ce.Methods.NotNull(); ce.Fields = ce.Fields.NotNull(); ce.Ctors = ce.Ctors.NotNull(); ce.Classes.RemoveAll(t => t.IsAnonymousClass || IsNonPublic(t) || t.IsSynthetic); ce.Fields.RemoveAll(t => IsNonPublic(t) || t.IsSynthetic); ce.Methods.RemoveAll(t => IsNonPublic(t) || t.IsSynthetic); ce.Ctors.RemoveAll(t => IsNonPublic(t) || t.IsSynthetic); ce.Methods.ForEach(t => t.Parameters = t.Parameters.NotNull()); ce.Methods.ForEach(t => t.TypeParameters = t.TypeParameters.NotNull()); ce.Ctors.ForEach(t => t.Parameters = t.Parameters.NotNull()); ce.Ctors.ForEach(t => t.TypeParameters = t.TypeParameters.NotNull()); ce.Classes.ForEach(t => t.DeclaringClass = ce); ce.Methods.ForEach(t => t.DeclaringClass = ce); ce.Fields.ForEach(t => t.DeclaringClass = ce); ce.Ctors.ForEach(t => t.DeclaringClass = ce); ce.Methods.RemoveAll(t => t.Name.Contains("$")); ce.Classes.ForEach(FixClass); ce.Ctors.RemoveAll(t => t.TypeParameters.IsNotNullOrEmpty()); }
public static JObjectArray New(JNIEnv env, int len, JClass clazz, JObject init) { global::System.IntPtr cPtr = JNIPINVOKE.JObjectArray_New(JNIEnv.getCPtr(env), len, JClass.getCPtr(clazz), JObject.getCPtr(init)); JObjectArray ret = (cPtr == global::System.IntPtr.Zero) ? null : new JObjectArray(cPtr, false); return(ret); }
private void GC(JNIEnv jniEnv) { JClass systemClass = jniEnv.FindClass("java/lang/System"); JMethodID systemGCMethod = jniEnv.GetStaticMethodID(systemClass, "gc", "()V"); jniEnv.CallStaticVoidMethod(systemClass, systemGCMethod, JValue.Empty); }
public void TestMethod1() { Setup(); // NO FUNCIONA... ????? JavaVMOption options = new JavaVMOption(); //options.optionString = $@"-Djava.class.path={jdkPath}"; options.optionString = ""; JavaVMInitArgs vm_args = JavaVMInitArgs.create(JNI.JNI_VERSION_1_8, 1); vm_args.set(0, options); int flags; Ref_JavaVM refJavaVM = new Ref_JavaVM(); Ref_JNIEnv refJNIEnv = new Ref_JNIEnv(); flags = JavaVM.CreateJavaVM(refJavaVM, refJNIEnv, vm_args); if (flags == JNI.JNI_ERR) { String msg = "Error creando la maquina virtual"; Debug.WriteLine(msg); throw new Exception(msg); } JNIEnv jniEnv = refJNIEnv.getValue(); JClass clazz = jniEnv.FindClass("java/lang/Object"); Debug.WriteLine("Class " + clazz); }
private void Test(JNIEnv jniEnv, JClass jclazz) { JMethodID jgetConstructors = jniEnv.GetMethodID(jclazz, "getConstructors", "()[Ljava.lang.reflect;"); JObject ret = jniEnv.CallObjectMethod(jclazz, jgetConstructors, JValue.Empty); JObjectArray array = ret.toJObjectArray(); foreach (JObject jobj in array.GetEnumerator(jniEnv)) { } }
Class Visit(JClass ce) { var name = ce.Name; if (ce.DeclaringClass != null) { name = name.Substring(name.LastIndexOf("$") + 1); } var ce2 = new Class { FullName = name, IsInternal = !ce.IsProtected && !ce.IsPrivate && !ce.IsPublic, IsInterface = ce.IsInterface, IsProtected = ce.IsProtected, IsStatic = ce.IsStatic, IsSealed = ce.IsFinal, IsVirtual = !ce.IsFinal && ce.IsClass, IsAbstract = ce.IsAbstract && !ce.IsInterface, //TODO: }; foreach (var ceRef in ce.GenericArguments.NotNull()) { if (ceRef.IsTypeVariable) { ce2.GenericArguments.Add(new Class { IsGenericTypeArgument = true, Name = ceRef.Name, GenericClassDefinition = ce2 }); } else { throw new Exception(); } //Resolve(ceRef); } ce2.Members.AddRange(ce.Classes.Where(t => !t.IsSynthetic).Select(Visit)); ce2.Members.ForEach(t => t.DeclaringClass = ce2); OnProcessBases.Do(() => { ce2.BaseClass = ResolveAndFix(ce.BaseClass, ce2); ce2.Interfaces = ce.Interfaces.NotNull().Select(t => ResolveAndFix(t, ce2)).ToList(); }); OnProcessMembers.Do(() => { //ce2.GenericArgumentRefs = ce.GenericArguments.NotNull().Select(Visit).ToList(); ce2.Members.AddRange(ce.Fields.Where(t => !t.IsSynthetic).Select(Visit)); ce2.Members.AddRange(ce.Ctors.Where(t => !t.IsSynthetic).Select(Visit)); ce2.Members.AddRange(ce.Methods.Where(t => !t.IsSynthetic).Select(Visit)); ce2.Members.ForEach(t => t.DeclaringClass = ce2); }); OnVisit(ce, ce2); return(ce2); }
static void Main(string[] args) { // Create Java Runtime using (JavaRuntime jre = new JavaRuntime()) { // Load Java Virtual Machine jre.Load(); // This is equal with -> String myValue = System.getProperty("java.version") // Splitted if for easier debugging. JClass javaType = jre.GetClass("java.lang.System"); // Invokes static method "getProperty" with parameter "java.version" which returns "java.lang.String" and casts it to generic parameter "string". string javaVersion = javaType.InvokeStaticMethod<string>("getProperty", "java.lang.String", "java.version"); Console.WriteLine($"Currently used Java version: { javaVersion }"); } }
public void TestMethod1() { Setup(); es.jni.JavaVMOption options = new JavaVMOption(); //options.optionString = $@"-Djava.class.path={jdkPath}"; options.optionString = ""; JavaVMInitArgs vm_args = JavaVMInitArgs.create(JNI.JNI_VERSION_1_8, 1); vm_args.set(0, options); int flags; Ref_JavaVM refJavaVM = new Ref_JavaVM(); Ref_JNIEnv refJNIEnv = new Ref_JNIEnv(); flags = JavaVM.CreateJavaVM(refJavaVM, refJNIEnv, vm_args); if (flags == JNI.JNI_ERR) { String msg = "Error creando la maquina virtual"; Debug.WriteLine(msg); throw new Exception(msg); } JavaVM javaVM = refJavaVM.getValue(); JNIEnv jniEnv = refJNIEnv.getValue(); JClass jclazz = jniEnv.FindClass("java/lang/Object"); Debug.WriteLine("jclazz " + jclazz); GC(jniEnv); JMethodID jinit = jniEnv.GetMethodID(jclazz, "<init>", "()V"); JObject jinstance = jniEnv.NewObject(jclazz, jinit, new JValue[0]); JObject jref = jniEnv.NewGlobalRef(jinstance); Test(jniEnv, jclazz); jniEnv.DeleteLocalRef(jclazz); }
public override JClass GetClass() { if (_jclass == null) { if (string.IsNullOrWhiteSpace(this.jclassName)) _jclass = JObject.Class; _jclass = NXDO.RJava.JClass.ForName(this.jclassName); } return _jclass; }
public void ChangeJavaClass(IntPtr javaClassPtr) { _jclass = new JClass(javaClassPtr); this.jclassName = _jclass.FullName; }
private JDynamic(String javaClassName, Object value) { jclass = JClass.ForName(javaClassName); this.Value = value; }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(JClass obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
internal JDynamicObject(JObject instanceObj, JClass instanceOfClass) { this.jobject = instanceObj; this.jclass = instanceOfClass; this.jclassName = instanceOfClass.FullName; }
/// <summary> /// Returns Java type with optional generic parameters. /// </summary> /// <param name="typeName"></param> /// <param name="genericTypes"></param> /// <returns></returns> public JClass GetClass(string typeName, params object[] genericTypes) { JClass jt = this.Gateway.LoadClass(typeName, genericTypes); return(jt); }
/// <summary> /// Adds archive to runtime. /// </summary> /// <param name="pathOrName"></param> public void AddArchive(string pathOrName) { JClass javaClass = this.Gateway.LoadClass("java.lang.System"); javaClass.InvokeStaticMethod <object>("loadLibrary", "V", pathOrName); }
public void InClassAry(JClass[] cls) { JObject.JInvokeMethod(nCahceType, "InClassAry", this, new object[] { cls }); }