コード例 #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 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]));
        }
コード例 #4
0
 private static Ui5Namespace FindBaseNamespace(Ui5Complex owner)
 {
     if (owner.parentNamespace != null)
     {
         return(FindBaseNamespace(owner.parentNamespace));
     }
     else
     {
         return(owner as Ui5Namespace);
     }
 }
コード例 #5
0
 public Ui5Method(Ui5Method x, Ui5Complex newowner)
 {
     deprecated  = x.deprecated;
     description = x.description;
     name        = x.name;
     owner       = newowner;
     parameters  = x.parameters.Select(y => y.Clone() as Ui5Parameter).ToList();
     returnValue = x.returnValue != null ? new Ui5Value(x.returnValue) : null;
     since       = x.since;
     @static     = x.@static;
     visibility  = x.visibility;
 }
コード例 #6
0
 public Ui5Enum(Ui5Complex source)
 {
     basename        = source.basename;
     deprecated      = source.deprecated;
     description     = source.description;
     extends         = source.extends;
     methods         = source.methods;
     module          = source.module;
     name            = source.fullname;
     parentNamespace = source.parentNamespace;
     properties      = source.properties;
     resource        = source.resource;
     since           = source.since;
     @static         = source.@static;
     visibility      = source.visibility;
 }
コード例 #7
0
        public static string GetRelativeTypeDef(Ui5Complex owner, string type)
        {
            if (owner == null)
            {
                return(type);
            }
            string[]      values    = type.Split('|');
            List <string> retvalues = new List <string>(type.Length);

            foreach (string value in values)
            {
                retvalues.Add(_CheckRelativeTypeDef(owner, value));
            }
            // Split to remove empty entries (if type should not be used in typedef
            try
            {
                return(retvalues.Distinct().Aggregate((a, b) => a + "|" + b).Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Aggregate((a, b) => a + "|" + b));
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #8
0
 private static string _CheckRelativeTypeDef(Ui5Complex owner, string type)
 {
     if (!string.IsNullOrWhiteSpace(owner.@namespace))
     {
         // Check, if the path starts with the namespace the owning class, namespace, enum, etc. is in.
         if (type.StartsWith(owner.@namespace))
         {
             return(type.Replace(owner.@namespace + ".", ""));
         }
         else
         {
             string relpath = CheckAndCreateImport(owner, type);
             if (relpath != null)
             {
                 return(relpath);
             }
             else
             {
                 return(type);
             }
         }
     }
     return(type);
 }
コード例 #9
0
 public string GetRelativeTypeDef(Ui5Complex owner)
 {
     return(GetRelativeTypeDef(owner, type));
 }
コード例 #10
0
        /// <summary>
        /// Will check base class for any methods that are overridden and not type matching. The class will create overloads for those and add it to its method list.
        /// </summary>
        /// <param name="allcontent"></param>
        public void CheckOverloads(IEnumerable <Ui5Complex> allcontent, Ui5Complex requestor = null, Ui5Complex basetype = null)
        {
            if (requestor == null)
            {
                requestor = this;
            }

            if (basetype == null)
            {
                basetype = this;
            }

            Ui5Complex extender = allcontent.FirstOrDefault(x => x.fullname == basetype.extends);

            if (extender == null)
            {
                return;
            }

            if (!extender.Overloaded)
            {
                extender.CheckOverloads(allcontent);
            }

            if (extender.extends != null)
            {
                extender.CheckOverloads(allcontent, requestor, extender);
            }

            List <Ui5Method> appendmethods = new List <Ui5Method>();

            foreach (Ui5Method m in requestor.methods)
            {
                // bm = basemethod
                string[] mdefs = m.GetMethodDefinitions();
                if (mdefs == null)
                {
                    continue;
                }

                foreach (Ui5Method bm in extender.methods.Where(x => x.name == m.name))
                {
                    foreach (string defbase in bm.GetMethodDefinitions())
                    {
                        foreach (string mdef in mdefs)
                        {
                            if (!mdef.Equals(defbase))
                            {
                                appendmethods.Add(bm);
                            }
                        }
                    }
                }
            }

            requestor.methods.AddRange(appendmethods.Select(x =>
            {
                Ui5Method overload    = new Ui5Method(x, requestor);
                overload.description += Environment.NewLine + "@note Overload from base type " + x.owner.fullname;
                return(overload);
            }));
            requestor.methods    = requestor.methods.Distinct(new Ui5MethodEqualityComparer()).OrderBy(x => x.name).ToList();
            requestor.Overloaded = true;
        }