예제 #1
0
        private void AppendOnNamespace(ICollection <Ui5Complex> content, Ui5Complex entry, string[] address = null)
        {
            // Create the namespace elements, if no array is handed (for recursion)
            if (address == null)
            {
                address = [email protected]('.');
            }

            // check address length (for stability)
            if (address.Length > 0)
            {
                // try to find the parent
                Ui5Namespace parent = content.OfType <Ui5Namespace>().FirstOrDefault(x => x.name == address[0]);
                if (parent == null)
                {
                    Ui5Namespace ns = new Ui5Namespace
                    {
                        name = [email protected]('.').TakeWhile(x => x != address[0]).Aggregate((a, b) => a + "." + b) + "." + address[0]
                    };
                    content.Add(ns);
                    AppendOnNamespace(ns.Content, entry, address.Skip(1).ToArray());
                }
                else
                {
                    AppendOnNamespace(parent.Content, entry, address.Skip(1).ToArray());
                }
            }
            else
            {
                content.Add(entry);
            }
        }
예제 #2
0
        private void AppendCustomTypeDefinitions(List <Ui5Complex> results)
        {
            foreach (var entry in globalValues.Typedefinitions.Where(x => x.Value != nameof(Ui5Enum)))
            {
                Ui5Complex toreplace = GetElementByPath(results, entry.Key);

                if (toreplace == null)
                {
                    // if not found try to get the namespace
                    string[]     arr        = entry.Key.Split('.');
                    Ui5Namespace @namespace = GetElementByPath(results, arr.Take(arr.Length - 1).Aggregate((a, b) => a + "." + b)) as Ui5Namespace;
                    if (toreplace == null)
                    {
                        Log("Could not find element to replace with Type '" + entry.Key + "'");
                        continue;
                    }
                    // Create a dummy (to reuse code below)
                    toreplace = new Ui5Class {
                        parentNamespace = @namespace
                    };
                }

                if (!entry.Value.StartsWith("{"))
                {
                    StringBuilder sb = new StringBuilder();
                    if (toreplace.description != null)
                    {
                        sb.AppendComment(toreplace.description);
                    }
                    sb.AppendLine($"type {toreplace.name} = {entry.Value};");
                    toreplace.parentNamespace?.AppendAdditionalTypedef(sb.ToString());
                    toreplace.parentNamespace?.Content.Remove(toreplace);
                }
            }
        }
예제 #3
0
 private void SetParents(Ui5Namespace result)
 {
     foreach (Ui5Complex entry in result.Content)
     {
         entry.parentNamespace = result;
     }
     foreach (Ui5Namespace @namespace in result.Content.OfType <Ui5Namespace>())
     {
         SetParents(@namespace);
     }
 }
        private static string CheckAndCreateImport(Ui5Complex owner, string type)
        {
            // Check if type is a base type and return if so
            if (globalValues.IsBaseType(type))
            {
                return(null);
            }
            // Convert the type, if the user wanted to replace it
            if (globalValues.TranslationDictionary.ContainsKey(type))
            {
                type = globalValues.ConvertToValidTypeIfKnown(type);
            }
            // check for any equal parts
            string equals = getequalpart(type, owner.@namespace);

            if (equals != null)
            {
                return(type);
            }

            // Now we know definetly it is an absolute path, which may collide with a relative path
            // so lets check this:

            string startofpath = [email protected]('.')[0];

            // check the parent namespaces for any relative starts
            List <Ui5Namespace> namespacesinpath = new List <Ui5Namespace>();

            if (owner is Ui5Namespace)
            {
                namespacesinpath.Add(owner as Ui5Namespace);
            }
            Ui5Namespace curns = owner.parentNamespace;

            while (curns != null)
            {
                namespacesinpath.Add(curns);
                curns = curns.parentNamespace;
            }

            // Check if any namespace on the list has the name of the start of the type
            // if nothing is found an import is not needed
            if (namespacesinpath.FirstOrDefault(x => x.name == startofpath) == null)
            {
                return(null);
            }

            // we found a relative namespace which has the same name as the absolute start of the namespace

            Ui5Namespace ns = FindBaseNamespace(owner);

            ns.Imports[startofpath] = startofpath + "import";
            return(Regex.Replace(type, "^" + startofpath + @"\.?", ns.Imports[startofpath]));
        }
 private static string AddImports(string equals, Ui5Namespace ns, string replacement)
 {
     foreach (string key in ns.Imports.Keys)
     {
         string commonbasenamespace = getequalpart(equals, key);
         if (commonbasenamespace != null)
         {
             return(ns.Imports[key] + equals.Replace(commonbasenamespace, ""));
         }
     }
     ns.Imports[equals] = replacement;
     return(replacement);
 }