public static TypeReference MapDatatype(TypeReference t) { var m = t.MemberOf; var g = t.Container; t = t.Clone() as TypeReference; t.MemberOf = m; t.Container = g; TypeReference retVal = t.Clone() as TypeReference; // Create a type reference var type = s_heuristicData.Datatypes.Find(o => o.MifDatatype == t.Name + (t.Flavor != null ? "." + t.Flavor : "")); if (type == null && !String.IsNullOrEmpty(t.Flavor)) { type = s_heuristicData.Datatypes.Find(o => o.MifDatatype == t.Name); } if (t is TypeParameter) { return(t); } else if (t.Name == null) { retVal.Name = "java.lang.Object"; } else if (type != null) { retVal.Name = type.JavaType; //if (!String.IsNullOrEmpty(type.TemplateParameter)) // retVal.Name = String.Format("{0}.datatypes.generic.{1}", s_apiNs, retVal.Name); //else // retVal.Name = String.Format("{0}.datatypes.{1}", s_apiNs, retVal.Name); retVal.MemberOf = t.MemberOf; retVal.GenericSupplier = t.GenericSupplier; if (t.Name != retVal.Name) { retVal.Flavor = null; // Clear flavors if pointing to a new type } // Default binding information var tParm = type.DefaultBind; if ((t.GenericSupplier == null || t.GenericSupplier.Count == 0) && !String.IsNullOrEmpty(tParm)) { retVal.AddGenericSupplier("def", MapDatatype(new TypeReference() { Name = tParm })); } } // Default member? return(retVal); }
public static TypeReference MapDatatype(TypeReference t) { var m = t.MemberOf; var g = t.Container; TypeReference retVal = t.Clone() as TypeReference; retVal.MemberOf = m; retVal.Container = g; if (t is TypeParameter) { return(t); } else if (t.Name == null) { retVal.Name = "System.Object"; } else if (flavMaps.ContainsKey(t.Name + "." + t.Flavor)) { // Create a type reference Type type = flavMaps[t.Name + "." + t.Flavor]; retVal.Name = type.Name; if (type.IsInterface) { retVal.Name = type.FullName; } if (retVal.Name.Contains("`")) { retVal.Name = retVal.Name.Substring(0, retVal.Name.IndexOf("`")); } retVal.MemberOf = t.MemberOf; retVal.GenericSupplier = t.GenericSupplier; if (t.Name != retVal.Name) { retVal.Flavor = null; // Clear flavors if pointing to a new type } } else if (typeMaps.ContainsKey(String.Format("{0}#{1}", t.Name, t.GenericSupplier != null && t.GenericSupplier.Count > 0 ? t.GenericSupplier[0].Name : null))) // Maps types { Type type = typeMaps[String.Format("{0}#{1}", t.Name, t.GenericSupplier != null && t.GenericSupplier.Count > 0 ? t.GenericSupplier[0].Name : null)]; retVal.Name = type.Name; if (type.IsInterface) { retVal.Name = type.FullName; } if (retVal.Name.Contains("`")) { retVal.Name = retVal.Name.Substring(0, retVal.Name.IndexOf("`")); } retVal.MemberOf = t.MemberOf; if (type.IsGenericTypeDefinition) { retVal.GenericSupplier = t.GenericSupplier; } else { retVal.GenericSupplier = null; } } else if (typeMaps.ContainsKey(String.Format("{0}#", t.Name))) // Maps types { Type type = typeMaps[String.Format("{0}#", t.Name)]; retVal.Name = type.Name; if (type.IsInterface) { retVal.Name = type.FullName; } if (retVal.Name.Contains("`")) { retVal.Name = retVal.Name.Substring(0, retVal.Name.IndexOf("`")); } retVal.MemberOf = t.MemberOf; retVal.GenericSupplier = t.GenericSupplier; } // Type parm info var tParm = defaultTypeParms.Find(o => o.StructureAttribute.Name.Equals(t.Name)); if (tParm != null && (t.GenericSupplier == null || t.GenericSupplier.Count == 0) && tParm.DefaultTypeParameter != null) { // Create the type parm var staParm = tParm.DefaultTypeParameter.GetCustomAttributes(typeof(StructureAttribute), false); for (int i = 0; i < tParm.Type.GetGenericArguments().Length; i++) { if (staParm.Length > 0) { retVal.AddGenericSupplier(i.ToString(), MapDatatype(new TypeReference() { Name = (staParm[0] as StructureAttribute).Name })); } else { retVal.AddGenericSupplier(i.ToString(), new TypeReference() { Name = tParm.DefaultTypeParameter.FullName }); } } } // Default member? return(retVal); }
private void ProcessTypeParameters(List <ParameterModel> parms, TypeReference baseRef, MohawkCollege.EHR.gpmr.COR.Interaction ownerInteraction) { if (parms != null && baseRef.Class != null && baseRef.Class.TypeParameters != null && parms.Count != baseRef.Class.TypeParameters.Count) { Trace.WriteLine( string.Format("The argument message '{0}.{1}' requires {2} parameter messages however interaction '{3}' only specifies {4}", baseRef.Class.ContainerName, baseRef.Class.Name, baseRef.Class.TypeParameters.Count, ownerInteraction.Name, parms.Count) , "warn"); } else if (parms == null || parms.Count == 0) { return; // Check for null } // Setup the parameters foreach (ParameterModel p in parms) { // Check if the parameter model exists if (!ClassRepository.ContainsKey(p.ToString(MifCompiler.NAME_FORMAT))) { PackageParser.Parse(p.ToString(MifCompiler.NAME_FORMAT), repository, ClassRepository); // Process the package if it doesn't } // Check again, if this fails all hell breaks loose var model = (ClassRepository[p.ToString(MifCompiler.NAME_FORMAT)] as MohawkCollege.EHR.gpmr.COR.SubSystem); if (model == null) { System.Diagnostics.Trace.WriteLine(string.Format("Could not find the parameter model '{0}'", p.ToString(MifCompiler.NAME_FORMAT)), "error"); return; } else if (model.EntryPoint.Count == 0) { System.Diagnostics.Trace.WriteLine(string.Format("Parameter model '{0}' must have an entry point", p.ToString(MifCompiler.NAME_FORMAT)), "error"); return; } else if (model.EntryPoint.Count != 1) { System.Diagnostics.Trace.WriteLine(string.Format("Ambiguous entry point for parameter model '{0}'", p.ToString(MifCompiler.NAME_FORMAT)), "error"); return; } // Entry class for p TypeReference parmRef = model.EntryPoint[0].CreateTypeReference(); // Find any reference and set an alternate traversal name for that property if (p.Specialization.Count == 0) { AppendTraversalName(baseRef, p.ParameterName, p.TraversalName, parmRef, ownerInteraction, new Stack <string>()); } else { ProcessSpecializations(p, p.Specialization, baseRef, ownerInteraction, null); } // Process Children ProcessTypeParameters(p.ParameterModel, parmRef, ownerInteraction); // Assign for tr as a parameter reference try { baseRef.AddGenericSupplier(p.ParameterName, parmRef); } catch (ArgumentException e) // This is thrown when there are more than one supplier binding { // Was more than one specified if (baseRef.GenericSupplier.Exists(o => (o as TypeParameter).ParameterName == p.ParameterName)) { //baseRef.GenericSupplier.RemoveAll(o => (o as TypeParameter).ParameterName == p.ParameterName); // remove the existing type reference // Add the generic supplier manually for the new type baseRef.AddGenericSupplier(p.ParameterName, parmRef, false); Trace.WriteLine(String.Format("Generic supplier {0} has been specified more than once, will use base object in it's place", p.ParameterName), "warn"); } } catch (Exception e) { // JF - Some UV models attempt to bind to classes that don't support binding if (baseRef.Class.TypeParameters == null) { System.Diagnostics.Trace.WriteLine(String.Format("{0} can't force bind because the target class has not template parameters", e.Message), "error"); if (MifCompiler.hostContext.Mode == Pipeline.OperationModeType.Quirks) { System.Diagnostics.Trace.WriteLine(String.Format("{0} will ignore this binding in order to continue. This interaction will effectively be useless", ownerInteraction.Name)); } else { throw new InvalidOperationException(String.Format("Cannot bind parameter '{0}' to class '{1}' because '{1}' does not support templates", parmRef.Name, baseRef.Name)); } } else { System.Diagnostics.Trace.WriteLine(String.Format("{0} will try force binding", e.Message), "error"); foreach (var t in baseRef.Class.TypeParameters) { if (baseRef.GenericSupplier.Find(o => o.Name.Equals(t.ParameterName)) == null) { baseRef.AddGenericSupplier(t.ParameterName, parmRef); System.Diagnostics.Trace.WriteLine(String.Format("Bound {0} to {1} in {2}", parmRef, t.ParameterName, baseRef), "warn"); break; } } } } } }