internal override Type DefineUnloadable(string name) { #if !WINRT lock (this) { if (unloadables == null) { unloadables = new Dictionary <string, TypeBuilder>(); } TypeBuilder type; if (unloadables.TryGetValue(name, out type)) { return(type); } if (unloadableContainer == null) { unloadableContainer = moduleBuilder.DefineType(UnloadableTypeWrapper.ContainerTypeName, TypeAttributes.Interface | TypeAttributes.Abstract); AttributeHelper.HideFromJava(unloadableContainer); } type = unloadableContainer.DefineNestedType(TypeNameUtil.MangleNestedTypeName(name), TypeAttributes.NestedPrivate | TypeAttributes.Interface | TypeAttributes.Abstract); unloadables.Add(name, type); return(type); } #else throw new NotImplementedException(); #endif }
internal static string TypeNameMangleImpl(Dictionary <string, TypeWrapper> dict, string name, TypeWrapper tw) { // the CLR maximum type name length is 1023 characters, // but we need to leave some room for the suffix that we // may need to append to make the name unique const int MaxLength = 1000; if (name.Length > MaxLength) { name = name.Substring(0, MaxLength) + "/truncated"; } string mangledTypeName = TypeNameUtil.ReplaceIllegalCharacters(name); // FXBUG the CLR (both 1.1 and 2.0) doesn't like type names that end with a single period, // it loses the trailing period in the name that gets passed in the TypeResolve event. if (dict.ContainsKey(mangledTypeName) || mangledTypeName.EndsWith(".")) { #if STATIC_COMPILER Tracer.Warning(Tracer.Compiler, "Class name clash: {0}", mangledTypeName); #endif // Java class names cannot contain slashes (since they are converted into periods), // so we take advantage of that fact to create a unique name. string baseName = mangledTypeName; int instanceId = 0; do { mangledTypeName = baseName + "/" + (++instanceId); } while (dict.ContainsKey(mangledTypeName)); } dict.Add(mangledTypeName, tw); return(mangledTypeName); }
private static void CreateNoFail(CompilerClassLoader loader, TypeWrapper[] interfaces, List <ProxyMethod> methods) { bool ispublic = true; Type[] interfaceTypes = new Type[interfaces.Length]; for (int i = 0; i < interfaceTypes.Length; i++) { ispublic &= interfaces[i].IsPublic; interfaceTypes[i] = interfaces[i].TypeAsBaseType; } TypeAttributes attr = TypeAttributes.Class | TypeAttributes.Sealed; attr |= ispublic ? TypeAttributes.NestedPublic : TypeAttributes.NestedAssembly; DynamicClassLoader factory = (DynamicClassLoader)loader.GetTypeWrapperFactory(); TypeBuilder tb = factory.DefineProxy(TypeNameUtil.GetProxyNestedName(interfaces), attr, proxyClass.TypeAsBaseType, interfaceTypes); AttributeHelper.SetImplementsAttribute(tb, interfaces); // we apply an InnerClass attribute to avoid the CompiledTypeWrapper heuristics for figuring out the modifiers AttributeHelper.SetInnerClass(tb, null, ispublic ? Modifiers.Public | Modifiers.Final : Modifiers.Final); CreateConstructor(tb); for (int i = 0; i < methods.Count; i++) { methods[i].fb = tb.DefineField("m" + i, javaLangReflectMethod.TypeAsSignatureType, FieldAttributes.Private | FieldAttributes.Static); } foreach (ProxyMethod method in methods) { CreateMethod(loader, tb, method); } CreateStaticInitializer(tb, methods, loader); }
private static string GetProxyNestedName(TypeWrapper[] interfaces) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (TypeWrapper tw in interfaces) { sb.Append(tw.Name.Length).Append('|').Append(tw.Name); } return(TypeNameUtil.MangleNestedTypeName(sb.ToString())); }
internal void DefineProxyHelper(Type type) { if (proxyHelperContainer == null) { proxyHelperContainer = moduleBuilder.DefineType("__<Proxy>", TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract); AttributeHelper.HideFromJava(proxyHelperContainer); AttributeHelper.SetEditorBrowsableNever(proxyHelperContainer); proxyHelpers = new List <TypeBuilder>(); } proxyHelpers.Add(proxyHelperContainer.DefineNestedType(TypeNameUtil.MangleNestedTypeName(type.FullName), TypeAttributes.NestedPublic | TypeAttributes.Interface | TypeAttributes.Abstract, null, new Type[] { type })); }
internal TypeBuilder DefineProxy(TypeWrapper proxyClass, TypeWrapper[] interfaces) { if (proxiesContainer == null) { proxiesContainer = moduleBuilder.DefineType(TypeNameUtil.ProxiesContainer, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Abstract); AttributeHelper.HideFromJava(proxiesContainer); AttributeHelper.SetEditorBrowsableNever(proxiesContainer); proxies = new List <TypeBuilder>(); } Type[] ifaces = new Type[interfaces.Length]; for (int i = 0; i < ifaces.Length; i++) { ifaces[i] = interfaces[i].TypeAsBaseType; } TypeBuilder tb = proxiesContainer.DefineNestedType(TypeNameUtil.GetProxyNestedName(interfaces), TypeAttributes.NestedPublic | TypeAttributes.Class | TypeAttributes.Sealed, proxyClass.TypeAsBaseType, ifaces); proxies.Add(tb); return(tb); }
public static java.lang.Class getPrecompiledProxy(java.lang.ClassLoader classLoader, string proxyName, java.lang.Class[] interfaces) { AssemblyClassLoader acl = ClassLoaderWrapper.GetClassLoaderWrapper(classLoader) as AssemblyClassLoader; if (acl == null) { return(null); } TypeWrapper[] wrappers = new TypeWrapper[interfaces.Length]; for (int i = 0; i < wrappers.Length; i++) { wrappers[i] = TypeWrapper.FromClass(interfaces[i]); } // TODO support multi assembly class loaders Type type = acl.MainAssembly.GetType(TypeNameUtil.GetProxyName(wrappers)); if (type == null) { return(null); } TypeWrapper tw = CompiledTypeWrapper.newInstance(proxyName, type); TypeWrapper tw2 = acl.RegisterInitiatingLoader(tw); if (tw != tw2) { return(null); } // we need to explicitly register the type, because the type isn't visible by normal means tw.GetClassLoader().SetWrapperForType(type, tw); TypeWrapper[] wrappers2 = tw.Interfaces; if (wrappers.Length != wrappers.Length) { return(null); } for (int i = 0; i < wrappers.Length; i++) { if (wrappers[i] != wrappers2[i]) { return(null); } } return(tw.ClassObject); }
internal override Type DefineUnloadable(string name) { lock (this) { if (unloadables == null) { unloadables = new Dictionary <string, TypeBuilder>(); } TypeBuilder type; if (unloadables.TryGetValue(name, out type)) { return(type); } if (unloadableContainer == null) { unloadableContainer = moduleBuilder.DefineType("__<Unloadable>", TypeAttributes.Interface | TypeAttributes.Abstract); AttributeHelper.HideFromJava(unloadableContainer); } type = unloadableContainer.DefineNestedType(TypeNameUtil.MangleNestedTypeName(name), TypeAttributes.NestedPrivate | TypeAttributes.Interface | TypeAttributes.Abstract); unloadables.Add(name, type); return(type); } }
internal static string GetProxyHelperName(Type type) { return("__<Proxy>+" + TypeNameUtil.MangleNestedTypeName(type.FullName)); }