TSTypeFile EnsureInitialized(IActivityMonitor monitor, TSTypeFile f, ref HashSet <Type>?cycleDetector) { if (!f.IsInitialized) { TypeScriptAttribute attr = f.Attribute; var generators = f.Generators; var t = f.Type; ITSCodeGenerator?globalControl = null; foreach (var g in _globals) { _success &= g.ConfigureTypeScriptAttribute(monitor, this, t, attr, generators, ref globalControl); } if (globalControl == null) { if (generators.Count > 0) { foreach (var g in generators) { _success &= g.ConfigureTypeScriptAttribute(monitor, attr, generators); } } } NormalizedPath folder; string? fileName = null; Type? refTarget = attr.SameFileAs ?? attr.SameFolderAs; if (refTarget != null) { if (cycleDetector == null) { cycleDetector = new HashSet <Type>(); } if (!cycleDetector.Add(t)) { throw new InvalidOperationException($"TypeScript.SameFoldeAs cycle detected: {cycleDetector.Select( c => c.Name ).Concatenate( " => " )}."); } var target = DoGetTSTypeFile(monitor, refTarget, ref cycleDetector); folder = target.Folder; if (attr.SameFileAs != null) { fileName = target.FileName; } } else { folder = attr.Folder ?? t.Namespace !.Replace('.', '/'); } var defName = t.GetExternalName() ?? t.Name; fileName ??= attr.FileName ?? (defName + ".ts"); string typeName = attr.TypeName ?? defName; f.Initialize(folder, fileName, typeName, globalControl); } return(f); }
public TypeScriptImpl(TypeScriptAttribute a, Type type) { Attribute = a; _type = type; }
public bool ConfigureTypeScriptAttribute(IActivityMonitor monitor, TypeScriptGenerator generator, Type type, TypeScriptAttribute attr, IReadOnlyList <ITSCodeGeneratorType> generatorTypes, ref ITSCodeGenerator currentHandler) { if (typeof(ICommand).IsAssignableFrom(type)) { if (attr.SameFolderAs == null) { attr.Folder ??= type.Namespace !.Replace('.', '/'); const string autoMapping = "CK/StObj/"; if (attr.Folder.StartsWith(autoMapping)) { attr.Folder = "Cris/Commands/" + attr.Folder.Substring(autoMapping.Length); } } if (attr.FileName == null && attr.SameFileAs == null) { attr.FileName = type.Name.Substring(1) + ".ts"; } // Takes control of all ICommand interfaces: currentHandler = this; } return(true); }