private static void RegisterJVMFields(GType type, bool register) { Class clazz = type.JVMType; foreach (Field field in clazz.getFields()) { RegisterJVMField(type, field, register); } }
/// <summary> /// Load and register methods /// </summary> private static void LoadMethods(GType type) { if (type.IsMethodsLoaded) { return; } type.IsMethodsLoaded = true; if (type.Base != null) { LoadMethods(type.Base); if (!type.IsRootType && !type.IsInterface) { foreach (var pair in type.Base.AllMethods) { if (!type.AllMethods.ContainsKey(pair.Key)) { type.AllMethods.Add(pair.Key, pair.Value); } } } } if (!type.IsInterface) { foreach (GType ifc in type.Interfaces) { LoadMethods(ifc); foreach (var pair in ifc.AllMethods) { if (!type.AllMethods.ContainsKey(pair.Key) || pair.Value.UseExplicitInterface || type.AllMethods[pair.Key].UseExplicitInterface) { type.AllMethods.Add(pair.Key, pair.Value); type.MethodsWithInterfaces.Add(pair.Value); } } } } bool loadCLR = (type.IsCLRGenerate || type.IsLoadJVMMethods) && type.IsJVMType; bool loadJVM = (type.IsJVMGenerate || type.IsLoadCLRMethods) && type.IsCLRType; if ((loadCLR || (loadJVM && type.IsInterface)) && type.IsJVMType) { RegisterJVMConstructors(type, true); RegisterJVMMethods(type, true); RegisterJVMFields(type, true); } if ((loadJVM || (loadCLR && type.IsInterface)) && type.IsCLRType) { RegisterCLRMethods(type, true); RegisterCLRConstructors(type, true); } }
private static void RegisterJVMMethod(GType type, Method method, bool register) { var modifiers = (ModifierFlags)method.getModifiers(); Annotation annotation = HasAnnotation(method, "net.sf.jni4net.attributes.ClrMethod"); if (annotation != null || (modifiers & (ModifierFlags.Private | ModifierFlags.Synthetic)) != ModifierFlags.None) { if (annotation == null) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method); } } return; } var res = new GMethod(); res.Type = type; res.Name = method.getName(); res.JVMName = res.Name; res.CLRName = res.JVMName; res.IsJVMMethod = true; var parameterTypes = method.getParameterTypes(); var parameterNames = GetParameterNames(method, parameterTypes.Length); for (int i = 0; i < parameterTypes.Length; i++) { var paramType = parameterTypes[i]; var paramName = parameterNames[i]; res.ParameterNames.Add(paramName); //+ paramType.ShortName res.Parameters.Add(RegisterClass(paramType)); } ConvertJVMAttributes(type, res, method); res.LowerName = res.Name + res.GetSignatureLowerNoRet(); res.ReturnType = RegisterClass(method.getReturnType()); if (register) { bool force = false; if (UseMethodModifier(type, res, res.Name, res.GetJVMSignature(), ref force)) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method); } return; } FinishRegistration(method.getName(), type, res, force, res.Name + res.GetCLRSignatureNoRet(), skipCLR); } }
private static void RegisterJVMConstructors(GType type, bool register) { if (type.IsAbstract) { return; } Class clazz = type.JVMType; foreach (Constructor ctor in clazz.getConstructors()) { RegisterJVMConstructor(type, ctor, register); } }
private static void RegisterClass(string clazzName) { Class clazz = loadClass(clazzName, false); if (clazz != null && ((ModifierFlags)clazz.getModifiers() & ModifierFlags.Public) != 0) { TypeRegistration registration = new TypeRegistration(); registration.TypeName = clazzName; GType reg = RegisterClass(clazz, registration); reg.IsCLRGenerate = true; reg.IsSkipJVMInterface = !registration.SyncInterface; reg.MergeJavaSource = registration.MergeJavaSource; } }
private static void RegisterClasses() { foreach (TypeRegistration registration in config.JavaClass) { string name = registration.TypeName.Replace(".", "/"); Class clazz = loadClass(name, true); if (clazz != null) { GType reg = RegisterClass(clazz, registration); reg.IsCLRGenerate = registration.Generate; reg.IsSkipJVMInterface = !registration.SyncInterface; reg.MergeJavaSource = registration.MergeJavaSource; } } }
/// <summary> /// Prefetch types of parameters /// </summary> private static void PreLoadMethods(GType type) { if (type.IsMethodsPreLoaded) { return; } type.IsMethodsPreLoaded = true; if (type.Registration != null && type.Registration.IgnoreInterface != null) { foreach (TypeReference ifcName in type.Registration.IgnoreInterface) { foreach (GType ifc in type.Interfaces) { if (ifc.LowerName == ifcName.TypeName.ToLowerInvariant()) { type.Interfaces.Remove(ifc); break; } } } } if (type.IsLoadCLRMethods || type.IsLoadJVMMethods) { foreach (GType ifc in type.Interfaces) { PreLoadMethods(ifc); } if (type.Base != null) { PreLoadMethods(type.Base); } if (type.IsLoadJVMMethods) { //dry registration RegisterJVMConstructors(type, false); RegisterJVMMethods(type, false); RegisterJVMFields(type, false); } if (type.IsLoadCLRMethods) { //dry registration RegisterCLRMethods(type, false); RegisterCLRConstructors(type, false); } } }
public GType MakeArray() { if (IsCLRType) { GType array = Repository.RegisterType(CLRType.MakeArrayType()); array.ArrayElement = this; return(array); } else { Class arrClass = JNIEnv.ThreadEnv.NewObjectArray(0, JVMType, null).getClass(); GType array = Repository.RegisterClass(arrClass); array.ArrayElement = this; return(array); } }
private static void BindKnownTypesPost() { voidType = RegisterClass(Class.getPrimitiveClass("void")); systemObject = RegisterType(typeof (object)); systemString = RegisterType(typeof (string)); systemType = RegisterType(typeof (Type)); systemException = RegisterType(typeof (Exception)); javaLangObject = RegisterClass(Object._class); javaLangString = RegisterClass(String._class); javaLangClass = RegisterClass(Class._class); javaLangThrowable = RegisterClass(Throwable._class); systemString.JVMSubst = javaLangString; javaLangIObject = RegisterType(javalangIObjectType); javaLangIObject.JVMSubst = javaLangObject; jvmProxy = RegisterType(jvmProxyType); jvmProxy.JVMSubst = javaLangObject; clrProxy.CLRSubst = systemObject; }
private static void BindKnownTypesPost() { voidType = RegisterClass(Class.getPrimitiveClass("void")); systemObject = RegisterType(typeof(object)); systemString = RegisterType(typeof(string)); systemType = RegisterType(typeof(Type)); systemException = RegisterType(typeof(Exception)); javaLangObject = RegisterClass(Object._class); javaLangString = RegisterClass(String._class); javaLangClass = RegisterClass(Class._class); javaLangThrowable = RegisterClass(Throwable._class); systemString.JVMSubst = javaLangString; javaLangIObject = RegisterType(javalangIObjectType); javaLangIObject.JVMSubst = javaLangObject; jvmProxy = RegisterType(jvmProxyType); jvmProxy.JVMSubst = javaLangObject; clrProxy.CLRSubst = systemObject; }
private static bool testVirtual(GType type, Class clazz, Method method, bool create, bool isBaseClassPublic) { var modifiers = (ModifierFlags)method.getModifiers(); bool isStatic = (modifiers & ModifierFlags.Static) != ModifierFlags.None; bool isVirtual = (modifiers & ModifierFlags.Final) == ModifierFlags.None; if (!clazz.isInterface()) { if (create && !isStatic && isVirtual && !type.IsRootType) { Method smethod = clazz.getSuperclass().GetMethodNoThrow(method.getName(), method.GetSignature(), false); if (smethod != null && isBaseClassPublic) { create = false; } } } return(create); }
private static void RegisterJVMConstructor(GType type, Constructor ctor, bool register) { var modifiers = (ModifierFlags)ctor.getModifiers(); if ((modifiers & (ModifierFlags.Private | ModifierFlags.Synthetic)) != ModifierFlags.None) { return; } var res = new GMethod(); res.Type = type; res.Name = "<init>"; res.JVMName = res.Name; res.CLRName = "_ctor" + type.JVMType.getSimpleName(); res.ReturnType = voidType; res.IsJVMMethod = true; res.IsConstructor = true; var parameterTypes = ctor.getParameterTypes(); var parameterNames = GetParameterNames(ctor, parameterTypes.Length); for (int i = 0; i < parameterTypes.Length; i++) { var paramType = parameterTypes[i]; var paramName = parameterNames[i]; res.ParameterNames.Add(paramName); //+ paramType.ShortName res.Parameters.Add(RegisterClass(paramType)); } ConvertJVMAttributes(type, res, ctor); res.LowerName = (res.Name + res.GetSignatureLowerNoRet()); if (register) { bool force = false; if (UseMethodModifier(type, res, res.Name, res.GetJVMSignature(), ref force)) { return; } type.Constructors.Add(res); } }
private static bool UseMethodModifier(GType type, GMethod res, string name, string signature, ref bool force) { bool fskip = false; if (type.Registration != null) { MethodModifier modifier; if (type.Registration.GetModifier(name, signature, out modifier)) { if (modifier.Return != null) { res.ReturnType = knownNames[modifier.Return.ToLowerInvariant()]; } if (modifier.Interface != null) { res.UseExplicitInterface = true; res.DeclaringType = knownNames[modifier.Interface.ToLowerInvariant()]; } if (modifier.RenameJVM != null) { res.JVMName = modifier.RenameJVM; } if (modifier.RenameCLR != null) { res.JVMName = modifier.RenameCLR; } if (modifier.Hide) { res.Attributes = (res.Attributes & (MemberAttributes.VTableMask | MemberAttributes.ScopeMask)) | MemberAttributes.Private; } if (modifier.Skip) { type.SkippedMethods.Add(res); fskip = true; } force = type.Registration.TestForceMethod(name, signature); } } return(fskip); }
private static void FinishRegistration(string method, GType type, GMethod res, bool force, string sig, RegSkip skipSignatureBuilder) { if (!res.UseExplicitInterface && !force) { if (type.AllMethods.ContainsKey(sig)) { type.SkippedMethods.Add(res); if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method + "<-" + type.AllMethods[sig].Type); } return; } type.AllMethods.Add(sig, res); } if (res.UseExplicitInterface) { if (type.AllMethods.ContainsKey(sig)) { GMethod rem = type.AllMethods[sig]; type.AllMethods.Remove(sig); type.MethodsWithInterfaces.Remove(rem); } foreach (GMethod skip in type.SkippedMethods) { string skipSig = skipSignatureBuilder(skip); if (skipSig == sig) { type.Methods.Add(skip); type.MethodsWithInterfaces.Add(skip); type.AllMethods.Add(sig, skip); type.SkippedMethods.Remove(skip); break; } } type.AllMethods.Add(res.DeclaringType.Name + "." + sig, res); } type.MethodsWithInterfaces.Add(res); type.Methods.Add(res); }
private static void RegisterCLRMethods(GType type, bool register) { Type clrType = type.CLRType; foreach (MethodInfo method in clrType.GetMethods()) { if (method.DeclaringType == type.CLRType || type.CLRType == typeof(Exception)) { RegisterCLRMethod(type, method, register); } } foreach (GType ifc in type.Interfaces) { if (ifc.IsCLRType) { foreach (MethodInfo method in ifc.CLRType.GetMethods()) { RegisterCLRMethod(type, method, register); } } } }
private static void ConvertJVMAttributes(GType type, GMethod res, Member member) { var modifiers = (ModifierFlags)member.getModifiers(); res.Attributes = 0; if ((modifiers & (ModifierFlags.Public)) != ModifierFlags.None || type.IsInterface) { res.Attributes |= MemberAttributes.Public; } if ((modifiers & (ModifierFlags.Static)) != ModifierFlags.None) { res.Attributes |= MemberAttributes.Static; res.IsStatic = true; } /*if ((modifiers & (ModifierFlags.Abstract)) != ModifierFlags.None && !type.IsInterface) * { * res.Attributes |= MemberAttributes.Abstract; * }*/ if ((modifiers & (ModifierFlags.Final)) != ModifierFlags.None && !type.IsInterface) { res.Attributes |= MemberAttributes.Final; } }
private static void RegisterCLRMethod(GType type, MethodInfo method, bool register) { object attr = HasAttribute(method, javaMethodAttribute); if (method.IsGenericMethod || !method.IsPublic || attr != null) { if (attr == null && config.Verbose) { Console.WriteLine("Skip " + type + "." + method); } return; } if (method.IsSpecialName) { string name = method.Name; if (name.StartsWith("op_")) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method); } return; } } GMethod res = RegisterCLRCall(type, method); if (res == null || TestCLRType(method.ReturnType)) { // skip if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method); } return; } if (method.IsSpecialName) { res.CLRProperty = GetProperty(type, method); if (res.CLRProperty == null) { res.CLREvent = GetEvent(type, method); res.IsEvent = true; if (method.Name.StartsWith("add_")) { res.IsCLRPropertyAdd = true; res.CLRPropertyAdd = res; foreach (GMethod m in type.Methods) { if (m.CLRProperty == res.CLRProperty) { m.CLRPropertyAdd = res; } } } if (method.Name.StartsWith("remove_")) { res.IsCLRPropertyRemove = true; res.CLRPropertyRemove = res; foreach (GMethod m in type.Methods) { if (m.CLRProperty == res.CLRProperty) { m.CLRPropertyRemove = res; } } } res.CLRName = res.CLREvent.Name; res.JVMName = method.Name.Replace("_", ""); } else { res.IsProperty = true; if (res.CLRProperty.CanRead && method.Name.StartsWith("get_")) { res.IsCLRPropertyGetter = true; res.CLRPropertyGetter = res; foreach (GMethod m in type.Methods) { if (m.CLRProperty == res.CLRProperty) { m.CLRPropertyGetter = res; } } } if (res.CLRProperty.CanWrite && method.Name.StartsWith("set_")) { res.IsCLRPropertySetter = true; res.CLRPropertySetter = res; foreach (GMethod m in type.Methods) { if (m.CLRProperty == res.CLRProperty) { m.CLRPropertySetter = res; } } } res.CLRName = res.CLRProperty.Name; res.JVMName = method.Name.Replace("_", ""); if (res.CLRProperty.PropertyType == typeof(bool) && res.JVMName.StartsWith("getIs")) { res.JVMName = "is" + res.JVMName.Substring(5); } } res.Name = method.Name; } if (method.DeclaringType != type.CLRType) { res.DeclaringType = RegisterType(method.DeclaringType); } res.ReturnType = RegisterType(method.ReturnType); if (register) { bool force = false; if (UseMethodModifier(type, res, res.Name, res.GetCLRSignature(), ref force)) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method); } return; } FinishRegistration(method.Name, type, res, force, res.Name + res.GetJVMSignatureNoRet(), skipJVM); } }
private static void RegisterCLRConstructor(GType type, ConstructorInfo method, bool register) { GMethod res = RegisterCLRCall(type, method); if (res == null) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method); } // skip return; } res.IsConstructor = true; if (register) { string sig = type.Name + res.GetJVMSignatureNoRet(); if (type.AllMethods.ContainsKey(sig)) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method); } return; } type.AllMethods.Add(sig, res); type.Constructors.Add(res); } }
private static PropertyInfo GetProperty( GType type, MethodInfo method ) { BindingFlags f = GetPropFlags( method ); string pname = method.Name.Substring( method.Name.IndexOf( '_' ) + 1 ); bool isIndexerProperty = method.IsSpecialName && pname == "Item"; if (isIndexerProperty) { var pts=new List<Type>(); int length = method.GetParameters().Length; if (method.Name.StartsWith("set_")) { // setter value length--; } for (int index = 0; index < length; index++) { var parameter = method.GetParameters()[index]; pts.Add(parameter.ParameterType); } return FindIndexerProperty(f, type.CLRType, method.ReturnType, pts.ToArray()); } return FindProperty( f, type.CLRType, pname ); }
private static void ConvertCLRAttributes(GType type, GMethod res, MethodBase method) { res.Attributes = 0; if (method.IsPublic || type.IsInterface) { res.Attributes |= MemberAttributes.Public; } else if (method.IsFamily && !type.IsInterface) { res.Attributes |= MemberAttributes.Family; } else if (method.IsFamilyOrAssembly && !type.IsInterface) { res.Attributes |= MemberAttributes.FamilyOrAssembly; } else if (method.IsFamilyAndAssembly && !type.IsInterface) { res.Attributes |= MemberAttributes.FamilyAndAssembly; } if (method.IsAbstract && !type.IsInterface) { res.Attributes |= MemberAttributes.Abstract; } else if (method.IsStatic && !type.IsInterface) { res.IsStatic = method.IsStatic; res.Attributes |= MemberAttributes.Static; } else if (!method.IsVirtual && !method.IsAbstract && !type.IsInterface) { //TODO res.Attributes |= MemberAttributes.Final; } }
private static void RegisterJVMMethod(GType type, Method method, bool register) { var modifiers = (ModifierFlags)method.getModifiers(); Annotation annotation = HasAnnotation(method, "net.sf.jni4net.attributes.ClrMethod"); if (annotation != null || (modifiers & (ModifierFlags.Private | ModifierFlags.Synthetic)) != ModifierFlags.None) { if (annotation == null) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method); } } return; } var res = new GMethod(); res.Type = type; res.Name = method.getName(); res.JVMName = res.Name; res.CLRName = res.JVMName; res.IsJVMMethod = true; Class[] parameterTypes = method.getParameterTypes(); for (int i = 0; i < parameterTypes.Length; i++) { Class paramType = parameterTypes[i]; res.ParameterNames.Add("par" + i); //+ paramType.ShortName res.Parameters.Add(RegisterClass(paramType)); } ConvertJVMAttributes(type, res, method); res.LowerName = res.Name + res.GetSignatureLowerNoRet(); res.ReturnType = RegisterClass(method.getReturnType()); if (register) { bool force = false; if (UseMethodModifier(type, res, res.Name, res.GetJVMSignature(), ref force)) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method); } return; } FinishRegistration(method.getName(), type, res, force, res.Name + res.GetCLRSignatureNoRet(), skipCLR); } }
public CLRWrapperGenerator(GType type) : base(type) { }
private static bool testVirtual(GType type, Class clazz, Method method, bool create, bool isBaseClassPublic) { var modifiers = (ModifierFlags) method.getModifiers(); bool isStatic = (modifiers & ModifierFlags.Static) != ModifierFlags.None; bool isVirtual = (modifiers & ModifierFlags.Final) == ModifierFlags.None; if (!clazz.isInterface()) { if (create && !isStatic && isVirtual && !type.IsRootType) { Method smethod = clazz.getSuperclass().GetMethodNoThrow(method.getName(), method.GetSignature(), false); if (smethod != null && isBaseClassPublic) { create = false; } } } return create; }
internal static GType RegisterClass(Class clazz, TypeRegistration registration) { if (knownClasses.ContainsKey(clazz)) { GType known = knownClasses[clazz]; if (registration != null) { known.Registration = registration; } return known; } var res = new GType(); if (clazz.isArray()) { res.ArrayElement = RegisterClass(clazz.getComponentType(), null); res.IsArray = true; string array = "[]"; Class comp = clazz.getComponentType(); while (comp.isArray()) { array += "[]"; comp = comp.getComponentType(); } res.LowerName = ((string) comp.getName()).ToLowerInvariant() + array; } else { res.LowerName = ((string) clazz.getName()).ToLowerInvariant(); } res.Attributes = 0; var classModifiers = (ModifierFlags) clazz.getModifiers(); if ((classModifiers & ModifierFlags.Abstract) != 0) { res.IsAbstract = true; res.Attributes |= TypeAttributes.Abstract; } if ((classModifiers & ModifierFlags.Final) != 0) { res.IsFinal = true; } if ((classModifiers & ModifierFlags.Public) != 0) { res.Attributes |= TypeAttributes.Public; } else if ((classModifiers & ModifierFlags.Private) != 0) { res.Attributes |= TypeAttributes.NotPublic; } //TODO internal ? if (knownNames.ContainsKey(res.LowerName)) { res = knownNames[res.LowerName]; } if (res.Registration == null && registration != null) { res.Registration = registration; } res.JVMType = clazz; res.JVMFullName = clazz.getName(); if (res.IsArray) { string array = "[]"; Class comp = clazz.getComponentType(); while (comp.isArray()) { array += "[]"; comp = comp.getComponentType(); } res.JVMFullName = comp.getName() + array; } else { res.JVMFullName = clazz.getName(); } res.IsJVMType = true; res.IsPrimitive = clazz.isPrimitive(); res.IsException = Throwable._class.isAssignableFrom(clazz); res.IsInterface = clazz.isInterface(); res.IsCLRProxy = clrProxyClass != null && clrProxyClass.isAssignableFrom(clazz); if (!res.IsCLRProxy) { res.IsJVMRealType = true; } Class superclass = clazz.getSuperclass(); var isBaseClassPublic = superclass == null || ((ModifierFlags)superclass.getModifiers() & ModifierFlags.Public) != 0; if (superclass != null && res.Base == null && clazz != Object._class && clazz != Throwable._class && res.JVMFullName != "system.Object" && res.JVMFullName != "system.Exception" && isBaseClassPublic) { res.Base = RegisterClass(superclass); } List<Class> interfaces = new List<Class>(clazz.getInterfaces()); if (!isBaseClassPublic) { interfaces.AddRange(superclass.getInterfaces()); res.Base = RegisterClass(superclass.getSuperclass()); } foreach (Class ifc in interfaces) { GType gifc = RegisterClass(ifc); if (!res.Interfaces.Contains(gifc)) { if (res.IsInterface && res.Base == null) { res.Base = gifc; } res.Interfaces.Add(gifc); res.AllInterfaces.Add(gifc); } } Register(res); return res; }
public CLRClassGenerator(GType type) : base(type) { }
internal static GType RegisterType(Type type, TypeRegistration registration) { Type original = type; if (knownTypes.ContainsKey(type)) { GType known = knownTypes[type]; if (registration != null) { known.Registration = registration; } return(known); } var res = new GType(); if (typeof(Delegate).IsAssignableFrom(type)) { int i = 0; } if (type.IsPointer) { //it's out really res.IsOut = true; type = type.GetElementType(); } if (type.IsByRef) { //it's ref really res.IsRef = true; type = type.GetElementType(); } if (type.IsArray) { res.ArrayElement = RegisterType(type.GetElementType()); res.IsArray = true; } res.LowerName = original.FullName.ToLowerInvariant(); if (res.IsOut) { res.LowerName += "!"; } if (knownNames.ContainsKey(res.LowerName)) { res = knownNames[res.LowerName]; } if (type.IsAbstract) { res.IsAbstract = true; } if (type.IsSealed) { res.IsFinal = true; } if (typeof(Delegate).IsAssignableFrom(type) && typeof(Delegate) != type && typeof(MulticastDelegate) != type) { res.IsDelegate = true; } if (res.Registration == null && registration != null) { res.Registration = registration; } res.IsPrimitive = type.IsPrimitive; res.IsException = typeof(Exception).IsAssignableFrom(type); res.CLRType = original; if (res.IsArray) { res.CLRFullName = type.GetElementType().FullName + "[]"; } else { res.CLRFullName = type.FullName; } res.Attributes = type.Attributes; res.IsCLRType = true; res.IsInterface = type.IsInterface; res.IsJVMProxy = jvmProxyType.IsAssignableFrom(type); if (!res.IsJVMProxy) { res.IsCLRRealType = true; } if (type.BaseType != null && res.Base == null && type != typeof(object) && type != typeof(Exception) && type.FullName != "java.lang.Throwable" && type.FullName != "java.lang.Object" ) { res.Base = RegisterType(type.BaseType); } foreach (Type ifc in type.GetInterfaces()) { if (!ifc.IsAssignableFrom(type.BaseType)) { if (!TestCLRTypeStrong(ifc)) { GType gifc = RegisterType(ifc); if (!res.Interfaces.Contains(gifc)) { if (res.IsInterface && res.Base == null) { res.Base = gifc; } res.Interfaces.Add(gifc); res.AllInterfaces.Add(gifc); } } } } Register(res); if (type.IsGenericType) { Type sub; Type supGeneric = type.GetGenericTypeDefinition(); if (typeof(IComparable <>).IsAssignableFrom(supGeneric)) { sub = typeof(IComparable); res.LowerName = ("System.IComparable<" + type.GetGenericArguments()[0].Name + ">").ToLowerInvariant(); } else if (typeof(IEnumerable <>).IsAssignableFrom(supGeneric)) { sub = typeof(IEnumerable); res.LowerName = ("System.Collections.Generic.IEnumerable<" + type.GetGenericArguments()[0].Name + ">"). ToLowerInvariant(); } else if (typeof(IEnumerator <>).IsAssignableFrom(supGeneric)) { sub = typeof(IEnumerator); res.LowerName = ("System.Collections.Generic.IEnumerator<" + type.GetGenericArguments()[0].Name + ">"). ToLowerInvariant(); } else if (typeof(IEquatable <>).IsAssignableFrom(supGeneric)) { sub = typeof(object); res.LowerName = ("System.Collections.Generic.IEquatable<" + type.GetGenericArguments()[0].Name + ">"). ToLowerInvariant(); } else if (typeof(ICollection <>).IsAssignableFrom(supGeneric)) { sub = typeof(ICollection); res.LowerName = ("System.Collections.Generic.ICollection<" + type.GetGenericArguments()[0].Name + ">"). ToLowerInvariant(); } else if (typeof(IList <>).IsAssignableFrom(supGeneric)) { sub = typeof(IList); res.LowerName = ("System.Collections.Generic.IList<" + type.GetGenericArguments()[0].Name + ">"). ToLowerInvariant(); } else { sub = type.BaseType; if (sub == null) { sub = typeof(object); } } res.JVMSubst = RegisterType(sub); } if (res.IsOut) { Type sub; if (type.IsArray) { sub = typeof(Out <>).MakeGenericType(typeof(object)); } else { sub = typeof(Out <>).MakeGenericType(type); } res.JVMSubst = RegisterType(sub); res.CLRSubst = res; } if (res.IsRef) { Type sub; if (type.IsArray) { sub = typeof(Ref <>).MakeGenericType(typeof(object)); } else { sub = typeof(Ref <>).MakeGenericType(type); } res.JVMSubst = RegisterType(sub); res.CLRSubst = res; } return(res); }
private static void RegisterJVMMethods(GType type, bool register) { Class clazz = type.JVMType; Method[] methods; try { methods = clazz.getMethods(); } catch (Throwable th) { if (config.Verbose) { Console.WriteLine("Skip methods" + type + " error: " + th.Message); } type.IsCLRGenerate = false; type.IsJVMGenerate = false; return; } var superclass = clazz.getSuperclass(); var isBaseClassPublic = superclass == null || ((ModifierFlags)superclass.getModifiers() & ModifierFlags.Public) != 0; foreach (Method method in methods) { var declaringClass = method.getDeclaringClass(); bool create = declaringClass == clazz; create = testVirtual(type, clazz, method, create, isBaseClassPublic); if (create || type == javaLangThrowable) { try { RegisterJVMMethod(type, method, register); } catch (Throwable th) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method + " error: " + th.Message); } } } else if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method); } } foreach (GType ifc in type.Interfaces) { if (ifc.IsJVMType) { foreach (Method method in ifc.JVMType.getMethods()) { bool create = testVirtual(type, clazz, method, true, isBaseClassPublic); if (create) { try { RegisterJVMMethod(type, method, register); } catch (Throwable th) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method + " error: " + th.Message); } } } } } } }
private static void RegisterJVMField(GType type, Field field, bool register) { var modifiers = (ModifierFlags) field.getModifiers(); if ((modifiers & (ModifierFlags.Private | ModifierFlags.Synthetic)) != ModifierFlags.None) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + field); } return; } var res = new GMethod(); res.Type = type; res.IsField = true; res.Name = field.getName(); res.JVMName = field.getName(); res.CLRName = res.JVMName; res.IsJVMMethod = true; ConvertJVMAttributes(type, res, field); res.ReturnType = RegisterClass(field.getType()); res.LowerName = (field.getName()); if (register) { type.Methods.Add(res); type.MethodsWithInterfaces.Add(res); } }
private static void BindKnownTypesPre() { foreach (Assembly assembly in knownAssemblies) { if (jvmProxyType == null) { jvmProxyType = assembly.GetType("net.sf.jni4net.jni.IJvmProxy"); } if (javaClassAttr == null) { javaClassAttr = assembly.GetType("net.sf.jni4net.attributes.JavaClassAttribute"); } if (javaInterfaceAttr == null) { javaInterfaceAttr = assembly.GetType("net.sf.jni4net.attributes.JavaInterfaceAttribute"); } if (clrWrapperAttr == null) { clrWrapperAttr = assembly.GetType("net.sf.jni4net.attributes.ClrWrapperAttribute"); } if (javaMethodAttribute == null) { javaMethodAttribute = assembly.GetType("net.sf.jni4net.attributes.JavaMethodAttribute"); } if (javalangIObjectType == null) { javalangIObjectType = assembly.GetType("java_.lang.IObject"); } } if (javaMethodAttribute == null) { Console.Error.WriteLine("Wrong DLLs ?"); } clrProxyClass = JNIEnv.ThreadEnv.FindClassNoThrow("net/sf/jni4net/inj/IClrProxy"); clrProxy = RegisterClass(clrProxyClass); systemIObject = RegisterClass(JNIEnv.ThreadEnv.FindClassNoThrow("system/IObject")); knownNames.Add("int", RegisterType(typeof(int))); knownNames.Add("long", RegisterType(typeof(long))); knownNames.Add("short", RegisterType(typeof(short))); knownNames.Add("char", RegisterType(typeof(char))); knownNames.Add("double", RegisterType(typeof(double))); knownNames.Add("float", RegisterType(typeof(float))); knownNames.Add("byte", RegisterType(typeof(byte))); knownNames.Add("bool", RegisterType(typeof(bool))); knownNames.Add("boolean", RegisterType(typeof(bool))); knownNames.Add("void", RegisterType(typeof(void))); GType glong = RegisterClass(Class.getPrimitiveClass("long")); GType gint = RegisterClass(Class.getPrimitiveClass("int")); GType gshort = RegisterClass(Class.getPrimitiveClass("short")); GType gbyte = RegisterClass(Class.getPrimitiveClass("byte")); GType gchar = RegisterClass(Class.getPrimitiveClass("char")); GType gdouble = RegisterClass(Class.getPrimitiveClass("double")); GType gfloat = RegisterClass(Class.getPrimitiveClass("float")); GType gbool = RegisterClass(Class.getPrimitiveClass("boolean")); RegisterType(typeof(ulong)).JVMSubst = glong; RegisterType(typeof(uint)).JVMSubst = gint; RegisterType(typeof(ushort)).JVMSubst = gshort; RegisterType(typeof(sbyte)).JVMSubst = gbyte; RegisterType(typeof(long)).JVMSubst = glong; RegisterType(typeof(int)).JVMSubst = gint; RegisterType(typeof(short)).JVMSubst = gshort; RegisterType(typeof(byte)).JVMSubst = gbyte; RegisterType(typeof(char)).JVMSubst = gchar; RegisterType(typeof(double)).JVMSubst = gdouble; RegisterType(typeof(float)).JVMSubst = gfloat; RegisterType(typeof(bool)).JVMSubst = gbool; RegisterType(typeof(IntPtr)).JVMSubst = glong; jvmPrimitives.Add(typeof(long), Class.forName("java.lang.Long")); jvmPrimitives.Add(typeof(int), Class.forName("java.lang.Integer")); jvmPrimitives.Add(typeof(short), Class.forName("java.lang.Short")); jvmPrimitives.Add(typeof(byte), Class.forName("java.lang.Byte")); jvmPrimitives.Add(typeof(char), Class.forName("java.lang.Character")); jvmPrimitives.Add(typeof(double), Class.forName("java.lang.Double")); jvmPrimitives.Add(typeof(float), Class.forName("java.lang.Float")); jvmPrimitives.Add(typeof(bool), Class.forName("java.lang.Boolean")); jvmPrimitives.Add(typeof(ulong), Class.forName("java.lang.Long")); jvmPrimitives.Add(typeof(uint), Class.forName("java.lang.Integer")); jvmPrimitives.Add(typeof(ushort), Class.forName("java.lang.Short")); jvmPrimitives.Add(typeof(sbyte), Class.forName("java.lang.Byte")); }
public void UpdateNames() { foreach (GType ifc in Interfaces) { foreach (GType inIfc in ifc.AllInterfaces) { if (!AllInterfaces.Contains(inIfc)) { AllInterfaces.Add(inIfc); } } } if (IsCLRType) { CLRNamespace = CLRType.Namespace; Name = CLRType.Name; if (!IsJVMType && JVMFullName == null) { JVMNamespace = CLRNamespace.ToLowerInvariant(); if (CLRType.IsGenericType) { bool rref = typeof(Ref <>).IsAssignableFrom(CLRType.GetGenericTypeDefinition()); bool oout = typeof(Out <>).IsAssignableFrom(CLRType.GetGenericTypeDefinition()); if (rref || oout) { JVMFullName = JVMNamespace + (rref ? ".Ref<" : ".Out<"); Type[] genericArguments = CLRType.GetGenericArguments(); for (int i = 0; i < genericArguments.Length; i++) { Type argument = genericArguments[i]; if (argument.IsPrimitive) { String objName = Repository.jvmPrimitives[argument].getName(); JVMFullName += objName; } else { GType real = Repository.RegisterType(argument); real.UpdateNames(); JVMFullName += real.JVMResolved; } if (i + 1 < genericArguments.Length) { JVMFullName += ","; } } JVMFullName += ">"; } } else { JVMFullName = JVMNamespace + "." + CLRType.Name; } } } if (IsJVMType) { JVMNamespace = JVMType.PackageName; Name = JVMType.ShortName; if (!IsCLRType) { CLRNamespace = JVMNamespace; if (IsArray) { CLRFullName = JVMType.getComponentType().getName() + "[]"; } else { CLRFullName = JVMType.FullName; } } } JVMNamespaceExt = JVMNamespace; CLRNamespaceExt = CLRNamespace; if (JVMNamespace.StartsWith("java.")) { JVMNamespaceExt = "java_." + JVMNamespace.Substring(5); } /* TODO * if (IsJVMGenerate) * { * if (Base!=null && !Base.IsJVMType && !Base.IsJVMGenerate) * { * Console.WriteLine("you should add " + Base.Name); * } * foreach (GType ifc in Interfaces) * { * if (!ifc.IsJVMType && !ifc.IsJVMGenerate) * { * Console.WriteLine("you should add " + ifc.Name); * } * } * } * * if (IsCLRGenerate && CLRType!=typeof(IClrProxy)) * { * if (Base != null && !Base.IsCLRType && !Base.IsCLRGenerate) * { * Console.WriteLine("you should add " + Base.Name); * } * foreach (GType ifc in Interfaces) * { * if (!ifc.IsCLRType && !ifc.IsCLRGenerate) * { * Console.WriteLine("you should add " + ifc.Name); * } * } * }*/ }
public static void Register() { if (config.Verbose) { Console.WriteLine("clr.version :" + RuntimeEnvironment.GetSystemVersion()); Console.WriteLine("clr.arch :" + ((IntPtr.Size == 8) ? "64bit" : "32bit")); } LoadClasspath(); if (config.Verbose) { Console.WriteLine("java.home :" + Bridge.Setup.JavaHome); Console.WriteLine("java.version :" + java.lang.System.getProperty("java.version")); Console.WriteLine("sun.arch.data.model :" + java.lang.System.getProperty("sun.arch.data.model")); Console.WriteLine(""); } LoadAssemblies(); RegisterAssemblies(); if (config.JavaClass != null) { RegisterClasses(); } if (config.ClrType != null) { RegisterTypes(); } foreach (Assembly assembly in generateAssemblies) { foreach (Type type in assembly.GetTypes()) { if (type.IsPublic) { TypeRegistration registration = new TypeRegistration(); registration.TypeName = type.FullName; GType reg = RegisterType(type, registration); reg.IsJVMGenerate = true; reg.IsSkipCLRInterface = !registration.SyncInterface; reg.MergeJavaSource = registration.MergeJavaSource; } } } foreach (string classPath in generateCp) { if (Directory.Exists(classPath)) { string path = Path.GetFullPath(classPath); foreach (string classFile in Directory.GetFiles(path, "*.class", SearchOption.AllDirectories)) { if (!classFile.Contains("$")) { string name = classFile.Substring(path.Length + 1); string clazzName = name.Substring(0, name.Length - (".class".Length)).Replace('\\', '/'); RegisterClass(clazzName); } } } else if (File.Exists(classPath) && Path.GetExtension(classPath) == ".jar") { using (var fis = Adapt.Disposable(new FileInputStream(classPath))) { using (var zis = Adapt.Disposable(new ZipInputStream(fis.Real))) { ZipEntry entry = zis.Real.getNextEntry(); while (entry != null) { string name = entry.getName(); if (!entry.isDirectory() && name.EndsWith(".class") && !name.Contains("$")) { string clazzName = name.Substring(0, name.Length - (".class".Length)); RegisterClass(clazzName); } entry = zis.Real.getNextEntry(); } } } } } }
protected JVMGenerator(GType type) : base(type) { }
private static void RegisterJVMMethods(GType type, bool register) { Class clazz = type.JVMType; Method[] methods; try { methods = clazz.getMethods(); } catch(Throwable th) { if (config.Verbose) { Console.WriteLine("Skip methods" + type + " error: " + th.Message); } type.IsCLRGenerate = false; type.IsJVMGenerate = false; return; } var superclass = clazz.getSuperclass(); var isBaseClassPublic = superclass==null || ((ModifierFlags)superclass.getModifiers() & ModifierFlags.Public) != 0; foreach (Method method in methods) { var declaringClass = method.getDeclaringClass(); bool create = declaringClass == clazz; create = testVirtual(type, clazz, method, create, isBaseClassPublic); if (create || type == javaLangThrowable) { try { RegisterJVMMethod(type, method, register); } catch(Throwable th) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method + " error: " + th.Message); } } } else if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method); } } foreach (GType ifc in type.Interfaces) { if (ifc.IsJVMType) { foreach (Method method in ifc.JVMType.getMethods()) { bool create = testVirtual(type, clazz, method, true, isBaseClassPublic); if (create) { try { RegisterJVMMethod(type, method, register); } catch (Throwable th) { if (config.Verbose) { Console.WriteLine("Skip " + type + "." + method + " error: " + th.Message); } } } } } } }
private static EventInfo GetEvent(GType type, MethodInfo method) { BindingFlags f = GetPropFlags(method); string pname = method.Name.Substring(method.Name.IndexOf('_') + 1); return FindEvent(f, type.CLRType, pname); }
private static void Register(GType type) { bool known = false; if (type.CLRType != null) { if (!knownTypes.ContainsKey(type.CLRType)) { knownTypes.Add(type.CLRType, type); } else { known = true; } } if (type.JVMType != null) { if (!knownClasses.ContainsKey(type.JVMType)) { knownClasses.Add(type.JVMType, type); } else { known = true; } } if (!knownNames.ContainsKey(type.LowerName)) { knownNames.Add(type.LowerName, type); } if (!known) { all.Add(type); } }
private static GMethod RegisterCLRCall(GType type, MethodBase method) { var res = new GMethod(); res.Type = type; res.Name = method.Name; res.CLRName = method.Name; res.JVMName = method.Name; res.IsCLRMethod = true; foreach (ParameterInfo info in method.GetParameters()) { Type parameterType = info.ParameterType; if (TestCLRType(parameterType)) { return null; } // we ignore IsOut when IsIn is set as well, because they are probably just attributes // see System.IO.TextReader.Read([In, Out] char[] buffer, int index, int count) if (info.IsOut && !info.IsIn) { //this is trick how to store out as type parameterType = parameterType.GetElementType().MakePointerType(); } res.ParameterNames.Add(info.Name); res.Parameters.Add(RegisterType(parameterType)); } res.ReturnType = RegisterType(typeof (void)); ConvertCLRAttributes(type, res, method); res.LowerName = (res.JVMName + res.GetSignatureLowerNoRet()); return res; }
private static void RegisterCLRConstructors(GType type, bool register) { if (type.IsAbstract) { return; } Type clrType = type.CLRType; if (typeof(Delegate).IsAssignableFrom(clrType)) { if (config.Verbose) { Console.WriteLine("Skip " + type + " constructors"); } return; } foreach (ConstructorInfo constructor in clrType.GetConstructors()) { MethodAttributes modifiers = constructor.Attributes; if ((modifiers & (MethodAttributes.Private)) != 0) { continue; } RegisterCLRConstructor(type, constructor, register); } }
private static void RegisterCLRMethods(GType type, bool register) { Type clrType = type.CLRType; foreach (MethodInfo method in clrType.GetMethods()) { if (method.DeclaringType == type.CLRType || type.CLRType == typeof (Exception)) { RegisterCLRMethod(type, method, register); } } foreach (GType ifc in type.Interfaces) { if (ifc.IsCLRType) { foreach (MethodInfo method in ifc.CLRType.GetMethods()) { RegisterCLRMethod(type, method, register); } } } }
internal static GType RegisterType(Type type, TypeRegistration registration) { Type original = type; if (knownTypes.ContainsKey(type)) { GType known = knownTypes[type]; if (registration != null) { known.Registration = registration; } return known; } var res = new GType(); if(typeof(Delegate).IsAssignableFrom(type)) { int i = 0; } if (type.IsPointer) { //it's out really res.IsOut = true; type = type.GetElementType(); } if (type.IsByRef) { //it's ref really res.IsRef = true; type = type.GetElementType(); } if (type.IsArray) { res.ArrayElement = RegisterType(type.GetElementType()); res.IsArray = true; } res.LowerName = original.FullName.ToLowerInvariant(); if (res.IsOut) { res.LowerName += "!"; } if (knownNames.ContainsKey(res.LowerName)) { res = knownNames[res.LowerName]; } if (type.IsAbstract) { res.IsAbstract = true; } if (type.IsSealed) { res.IsFinal = true; } if (typeof(Delegate).IsAssignableFrom(type) && typeof(Delegate) != type && typeof(MulticastDelegate) != type) { res.IsDelegate = true; } if (res.Registration == null && registration != null) { res.Registration = registration; } res.IsPrimitive = type.IsPrimitive; res.IsException = typeof(Exception).IsAssignableFrom(type); res.CLRType = original; if (res.IsArray) { res.CLRFullName = type.GetElementType().FullName + "[]"; } else { res.CLRFullName = type.FullName; } res.Attributes = type.Attributes; res.IsCLRType = true; res.IsInterface = type.IsInterface; res.IsJVMProxy = jvmProxyType.IsAssignableFrom(type); if (!res.IsJVMProxy) { res.IsCLRRealType = true; } if (type.BaseType != null && res.Base == null && type != typeof (object) && type != typeof (Exception) && type.FullName != "java.lang.Throwable" && type.FullName != "java.lang.Object" ) { res.Base = RegisterType(type.BaseType); } foreach (Type ifc in type.GetInterfaces()) { if (!ifc.IsAssignableFrom(type.BaseType)) { if (!TestCLRTypeStrong(ifc)) { GType gifc = RegisterType(ifc); if (!res.Interfaces.Contains(gifc)) { if (res.IsInterface && res.Base == null) { res.Base = gifc; } res.Interfaces.Add(gifc); res.AllInterfaces.Add(gifc); } } } } Register(res); if (type.IsGenericType) { Type sub; Type supGeneric = type.GetGenericTypeDefinition(); if (typeof (IComparable<>).IsAssignableFrom(supGeneric)) { sub = typeof (IComparable); res.LowerName = ("System.IComparable<" + type.GetGenericArguments()[0].Name + ">").ToLowerInvariant(); } else if (typeof (IEnumerable<>).IsAssignableFrom(supGeneric)) { sub = typeof (IEnumerable); res.LowerName = ("System.Collections.Generic.IEnumerable<" + type.GetGenericArguments()[0].Name + ">"). ToLowerInvariant(); } else if (typeof (IEnumerator<>).IsAssignableFrom(supGeneric)) { sub = typeof (IEnumerator); res.LowerName = ("System.Collections.Generic.IEnumerator<" + type.GetGenericArguments()[0].Name + ">"). ToLowerInvariant(); } else if (typeof (IEquatable<>).IsAssignableFrom(supGeneric)) { sub = typeof (object); res.LowerName = ("System.Collections.Generic.IEquatable<" + type.GetGenericArguments()[0].Name + ">"). ToLowerInvariant(); } else if (typeof (ICollection<>).IsAssignableFrom(supGeneric)) { sub = typeof (ICollection); res.LowerName = ("System.Collections.Generic.ICollection<" + type.GetGenericArguments()[0].Name + ">"). ToLowerInvariant(); } else if (typeof (IList<>).IsAssignableFrom(supGeneric)) { sub = typeof (IList); res.LowerName = ("System.Collections.Generic.IList<" + type.GetGenericArguments()[0].Name + ">"). ToLowerInvariant(); } else { sub = type.BaseType; if (sub == null) { sub = typeof (object); } } res.JVMSubst = RegisterType(sub); } if (res.IsOut) { Type sub; if (type.IsArray) { sub = typeof(Out<>).MakeGenericType(typeof(object)); } else { sub = typeof(Out<>).MakeGenericType(type); } res.JVMSubst = RegisterType(sub); res.CLRSubst = res; } if (res.IsRef) { Type sub; if (type.IsArray) { sub = typeof(Ref<>).MakeGenericType(typeof(object)); } else { sub = typeof(Ref<>).MakeGenericType(type); } res.JVMSubst = RegisterType(sub); res.CLRSubst = res; } return res; }
public JVMStaticGenerator(GType type) : base(type) { }
protected Generator(GType type) { this.type = type; SetCurrentType(type.CLRNamespace + "." + type.Name); }
private CodeMethodInvokeExpression CreateConversionExpressionC2JParam(GType paramType, CodeExpression invokeExpression) { return CEEC2J("Par", paramType, invokeExpression); }
private CodeMethodInvokeExpression CreateConversionExpressionJ2CParam(GType paramType, CodeExpression invokeExpression) { return CEEJ2C(paramType, invokeExpression, true); }
public GType Resolve() { if (IsJVMGenerate || IsCLRGenerate) { return(this); } if (IsCLRType && IsJVMType) { return(this); } if (IsCLRType && JVMSubst != null) { return(JVMSubst); } if (IsJVMType && CLRSubst != null) { return(CLRSubst); } if (IsArray) { if (ArrayElement.CLRType == typeof(string)) { JVMSubst = Repository.RegisterClass(String._class).MakeArray(); return(JVMSubst); } GType subst = ArrayElement.Resolve().MakeArray(); if (IsCLRType) { JVMSubst = subst; } else { CLRSubst = subst; } return(subst); } if (IsRootType) { return(this); } if (Base != null) { GType subst = Base.Resolve(); if (!subst.IsRootType) { if (IsCLRType) { JVMSubst = subst; } else { CLRSubst = subst; } return(subst); } } /* * foreach (GType ifc in Interfaces) * { * GType subst = ifc.Resolve(); * if (IsCLRType && ifc.IsJVMType) * { * JVMSubst = subst; * return subst; * } * if (IsJVMType && ifc.IsCLRType) * { * CLRSubst = subst; * return subst; * } * }*/ if (IsCLRType) { JVMSubst = Repository.systemObject; return(Repository.systemObject); } else { CLRSubst = Repository.javaLangObject; return(Repository.javaLangObject); } }
private CodeMethodInvokeExpression CEEC2J(string prefix, GType paramType, CodeExpression invokeExpression) { CodeTypeReference[] par; if (paramType.IsArray) { GType element = paramType.ArrayElement; if (element.IsPrimitive) { par = new CodeTypeReference[] {}; return CCE(prefix + "ArrayPrimC2J", par, invokeExpression, true); } if (element == Repository.systemString) { par = new CodeTypeReference[] {}; return CCE(prefix + "ArrayStrongC2JString", par, invokeExpression, true); } if (!element.IsInterface && !element.IsCLRRootType && element.IsCLRRealType) { par = new[] {paramType.CLRReference, paramType.ArrayElement.CLRReference}; return CCE(prefix + "ArrayStrongC2Jp", par, invokeExpression, true); } if (!element.IsInterface && !element.IsJVMRootType && element.IsJVMRealType) { par = new CodeTypeReference[] {}; return CCE(prefix + "ArrayStrongCp2J", par, invokeExpression, true); } par = new[] {paramType.CLRReference, paramType.ArrayElement.CLRReference}; return CCE(prefix + "ArrayFullC2J", par, invokeExpression, true); } if (paramType.IsPrimitive) { par = new CodeTypeReference[] {}; return CCE(prefix + "PrimC2J", par, invokeExpression, false); } if (paramType == Repository.javaLangString || paramType == Repository.javaLangClass) { par = new CodeTypeReference[] {}; return CCE(prefix + "StrongCp2J", par, invokeExpression, false); } if (paramType == Repository.systemString) { par = new CodeTypeReference[] {}; return CCE(prefix + "StrongC2JString", par, invokeExpression, true); } if (paramType.IsDelegate) { par = new CodeTypeReference[] { }; return CCE(prefix + "StrongC2JDelegate", par, invokeExpression, true); } if (!paramType.IsInterface && !paramType.IsCLRRootType && paramType.IsCLRRealType) { par = new[] {paramType.CLRReference}; return CCE(prefix + "StrongC2Jp", par, invokeExpression, true); } if (!paramType.IsInterface && !paramType.IsJVMRootType && paramType.IsJVMRealType) { par = new CodeTypeReference[] {}; return CCE(prefix + "StrongCp2J", par, invokeExpression, false); } par = new[] {paramType.CLRReference}; return CCE(prefix + "FullC2J", par, invokeExpression, true); }
public JVMClassGenerator(GType type) : base(type) { }
internal static GType RegisterClass(Class clazz, TypeRegistration registration) { if (knownClasses.ContainsKey(clazz)) { GType known = knownClasses[clazz]; if (registration != null) { known.Registration = registration; } return(known); } var res = new GType(); if (clazz.isArray()) { res.ArrayElement = RegisterClass(clazz.getComponentType(), null); res.IsArray = true; string array = "[]"; Class comp = clazz.getComponentType(); while (comp.isArray()) { array += "[]"; comp = comp.getComponentType(); } res.LowerName = ((string)comp.getName()).ToLowerInvariant() + array; } else { res.LowerName = ((string)clazz.getName()).ToLowerInvariant(); } res.Attributes = 0; var classModifiers = (ModifierFlags)clazz.getModifiers(); if ((classModifiers & ModifierFlags.Abstract) != 0) { res.IsAbstract = true; res.Attributes |= TypeAttributes.Abstract; } if ((classModifiers & ModifierFlags.Final) != 0) { res.IsFinal = true; } if ((classModifiers & ModifierFlags.Public) != 0) { res.Attributes |= TypeAttributes.Public; } else if ((classModifiers & ModifierFlags.Private) != 0) { res.Attributes |= TypeAttributes.NotPublic; } //TODO internal ? if (knownNames.ContainsKey(res.LowerName)) { res = knownNames[res.LowerName]; } if (res.Registration == null && registration != null) { res.Registration = registration; } res.JVMType = clazz; res.JVMFullName = clazz.getName(); if (res.IsArray) { string array = "[]"; Class comp = clazz.getComponentType(); while (comp.isArray()) { array += "[]"; comp = comp.getComponentType(); } res.JVMFullName = comp.getName() + array; } else { res.JVMFullName = clazz.getName(); } res.IsJVMType = true; res.IsPrimitive = clazz.isPrimitive(); res.IsException = Throwable._class.isAssignableFrom(clazz); res.IsInterface = clazz.isInterface(); res.IsCLRProxy = clrProxyClass != null && clrProxyClass.isAssignableFrom(clazz); if (!res.IsCLRProxy) { res.IsJVMRealType = true; } Class superclass = clazz.getSuperclass(); var isBaseClassPublic = superclass == null || ((ModifierFlags)superclass.getModifiers() & ModifierFlags.Public) != 0; if (superclass != null && res.Base == null && clazz != Object._class && clazz != Throwable._class && res.JVMFullName != "system.Object" && res.JVMFullName != "system.Exception" && isBaseClassPublic) { res.Base = RegisterClass(superclass); } List <Class> interfaces = new List <Class>(clazz.getInterfaces()); if (!isBaseClassPublic) { interfaces.AddRange(superclass.getInterfaces()); res.Base = RegisterClass(superclass.getSuperclass()); } foreach (Class ifc in interfaces) { GType gifc = RegisterClass(ifc); if (!res.Interfaces.Contains(gifc)) { if (res.IsInterface && res.Base == null) { res.Base = gifc; } res.Interfaces.Add(gifc); res.AllInterfaces.Add(gifc); } } Register(res); return(res); }
private CodeMethodInvokeExpression CEEJ2C(GType paramType, CodeExpression invokeExpression, bool param) { CodeTypeReference[] par; if (paramType.IsArray) { GType element = paramType.ArrayElement; if (element.IsPrimitive) { par = new CodeTypeReference[] {}; return CCE("ArrayPrimJ2C" + element.Name, par, invokeExpression, true); } if (element == Repository.javaLangString) { par = new CodeTypeReference[] {}; return CCE("ArrayStrongJ2CpString", par, invokeExpression, true); } if (element == Repository.systemString) { par = new CodeTypeReference[] { }; return CCE("ArrayStrongJ2CString", par, invokeExpression, true); } if (element == Repository.javaLangClass) { par = new CodeTypeReference[] {}; return CCE("ArrayStrongJ2CpClass", par, invokeExpression, true); } if (!element.IsInterface && !element.IsCLRRootType && element.IsCLRRealType) { par = new[] {paramType.CLRReference, paramType.ArrayElement.CLRReference}; return CCE("ArrayStrongJp2C", par, invokeExpression, true); } if (!element.IsInterface && !element.IsJVMRootType && element.IsJVMRealType) { par = new[] {paramType.CLRReference, paramType.ArrayElement.CLRReference}; return CCE("ArrayStrongJ2Cp", par, invokeExpression, true); } par = new[] {paramType.CLRReference, paramType.ArrayElement.CLRReference}; return CCE("ArrayFullJ2C", par, invokeExpression, true); } if (paramType.IsPrimitive) { par = new CodeTypeReference[] {}; return CCE("PrimJ2C" + paramType.Name, par, invokeExpression, false); } if (paramType == Repository.javaLangString) { par = new CodeTypeReference[] {}; return CCE("StrongJ2CpString", par, invokeExpression, true); } if (paramType == Repository.systemString) { par = new CodeTypeReference[] { }; return CCE("StrongJ2CString", par, invokeExpression, true); } if (paramType == Repository.javaLangClass) { par = new CodeTypeReference[] {}; return CCE("StrongJ2CpClass", par, invokeExpression, true); } if(paramType.IsDelegate) { par = new [] { paramType.CLRReference }; return CCE("StrongJ2CpDelegate", par, invokeExpression, true); } if (!paramType.IsInterface && !paramType.IsCLRRootType && paramType.IsCLRRealType) { par = new[] {paramType.CLRReference}; return CCE("StrongJp2C", par, invokeExpression, true); } if (!paramType.IsInterface && !paramType.IsJVMRootType && paramType.IsJVMRealType) { par = new[] {paramType.CLRReference}; return CCE("StrongJ2Cp", par, invokeExpression, true); } par = new[] {paramType.CLRReference}; return CCE("FullJ2C", par, invokeExpression, true); }
public JVMInterfaceGenerator(GType type) : base(type) { }
protected CLRGenerator(GType type) : base(type) { }