Пример #1
0
        protected FuncParamsSyntaxCollections readFunctionParams(ExtObjectMember extObjectMember, string currentClassName, bool eventCompleting, string eventOrMethodName, bool isStatic, bool eventsCompleting)
        {
            FuncParamsSyntaxCollections funcParamsSyntaxCollections = new FuncParamsSyntaxCollections()
            {
                SpreadParamsSyntax   = new List <Param>(),
                StandardParamsSyntax = new List <Param>(),
                SpreadParamFound     = false
            };
            ParsedTypes?lastParamTypes = null;
            MemberParam lastParam;
            int         lastParamIndex = 0;

            if (extObjectMember.Params.Count > 0)
            {
                lastParamIndex = extObjectMember.Params.Count - 1;
                lastParam      = extObjectMember.Params[lastParamIndex];
                lastParamTypes = this.typesParser.Parse(
                    eventCompleting
                                                ? TypeDefinitionPlace.EVENT_PARAM
                                                : TypeDefinitionPlace.METHOD_PARAM,
                    currentClassName + "." + extObjectMember.Name,
                    lastParam.Name,
                    lastParam.Type
                    );
            }
            int           paramIndex     = 0;
            List <string> readParamNames = new List <string>();

            foreach (MemberParam param in extObjectMember.Params)
            {
                // Somethimes there could be probles with duplicated params in JSDuck output,
                // for example methods in version 6.2.0: Ext.util.Filter.isEqual? (filter: Ext.util.Filter, filter: Ext.util.Filter): boolean; ...
                if (readParamNames.Contains(param.Name))
                {
                    continue;
                }
                readParamNames.Add(param.Name);
                this.readFunctionParam(
                    extObjectMember, param, ref funcParamsSyntaxCollections, ref lastParamTypes,
                    eventCompleting, currentClassName, eventOrMethodName, isStatic, eventsCompleting, lastParamIndex, paramIndex
                    );
                paramIndex += 1;
            }
            return(funcParamsSyntaxCollections);
        }
Пример #2
0
        protected void readAndAddMethodOrEvent(ref ExtClass extClass, ExtObjectMember extObjectMember, string currentClassName, bool eventCompleting)
        {
            string funcOrEventName = this.sanitizeName(extObjectMember.Name);
            bool   ownedByCurrent  = extObjectMember.Owner.Length == currentClassName.Length && extObjectMember.Owner == currentClassName;
            bool   isStatic        = (extObjectMember.Static.HasValue && extObjectMember.Static.Value == true);
            FuncParamsSyntaxCollections funcParamsSyntaxCollections = this.readFunctionParams(
                extObjectMember, currentClassName, eventCompleting, funcOrEventName, isStatic, eventCompleting
                );

            if (eventCompleting)
            {
                this.readAndAddEvent(
                    ref extClass, extObjectMember, ref funcParamsSyntaxCollections,
                    funcOrEventName, ownedByCurrent
                    );
            }
            else
            {
                this.readAndAddMethod(
                    ref extClass, extObjectMember, ref funcParamsSyntaxCollections,
                    currentClassName, funcOrEventName, ownedByCurrent, isStatic
                    );
            }
        }
Пример #3
0
        protected void readAndAddMethod(ref ExtClass extClass, ExtObjectMember extObjectMember, ref FuncParamsSyntaxCollections funcParamsSyntaxCollections, string currentClassName, string methodName, bool ownedByCurrent, bool isStatic)
        {
            string[] docs = this.readJsDocs(extObjectMember.Doc, JsDocsType.METHOD, currentClassName, methodName);
            Method   item = new Method(
                methodName, funcParamsSyntaxCollections.StandardParamsSyntax, docs, extObjectMember.Owner, ownedByCurrent
                );

            item.Deprecated = this.readJsDocsDeprecated(
                extObjectMember.Deprecated, currentClassName, methodName
                );
            item.AccessModJs     = this.readItemAccessModifier(extObjectMember);
            item.AccessModTs     = item.AccessModJs;
            item.ExistenceReason = ExistenceReasonType.NATURAL;
            item.IsStatic        = isStatic;
            item.IsChainable     = (extObjectMember.Chainable.HasValue && extObjectMember.Chainable.Value == true);
            item.IsTemplate      = (extObjectMember.Template.HasValue && extObjectMember.Template.Value == true);
            item.Renderable      = extClass.Extends == null || extObjectMember.Name == "statics";        // force render if it is class without any parent
            if (item.IsChainable)
            {
                item.Renderable = true;                 // always render chanable method with it's return type
                item.ReturnTypes.Add(extClass.Name.FullName);
            }
            else
            {
                if (extObjectMember.Return != null)
                {
                    item.ReturnTypes = this.readAndAddMethodReturn(
                        ref extClass, extObjectMember, currentClassName, isStatic
                        );
                }
                else
                {
                    item.ReturnTypes.Add("void");
                }
            }
            if (extObjectMember.Return != null && extObjectMember.Return.Doc != null)
            {
                item.ReturnDocs = this.readJsDocs(
                    extObjectMember.Return.Doc,
                    JsDocsType.METHOD_RETURN,
                    currentClassName,
                    "return"
                    );
            }
            extClass.AddMemberMethod(item);
            if (funcParamsSyntaxCollections.SpreadParamsSyntax.Count > 0)
            {
                // There is necessary to add second method form,
                // because there was last param with standard param
                // syntax mixed with spread param syntax:
                Method itemClone = item.Clone();
                itemClone.OwnedByCurrent = item.OwnedByCurrent;
                itemClone.Params         = funcParamsSyntaxCollections.SpreadParamsSyntax;
                extClass.AddMemberMethod(itemClone);
            }
        }
Пример #4
0
        protected void readFunctionParamAddToParamsList(MemberParam extObjectMemberParam, ref FuncParamsSyntaxCollections functionParamsSyntaxCollections, ref ParsedTypes paramTypes, string currentClassName, bool eventCompleting, bool lastParamDefinition)
        {
            bool optional = (
                (extObjectMemberParam.Optional.HasValue && extObjectMemberParam.Optional.Value == true) ||
                (extObjectMemberParam.Doc != null && extObjectMemberParam.Doc.ToLower().Contains("(optional)"))
                );

            string[] docs = this.readJsDocs(
                extObjectMemberParam.Doc,
                (eventCompleting
                                        ? JsDocsType.EVENT_PARAM
                                        : JsDocsType.METHOD_PARAM),
                currentClassName,
                extObjectMemberParam.Name
                );

            /*if (!lastParamDefinition) {
             *      functionParamsSyntaxCollections.StandardParamsSyntax.Add(new Param(
             *              this.sanitizeName(extObjectMemberParam.Name),
             *              docs,
             *              paramTypes.MethodOrEventParam,
             *              optional,
             *              false // not last param can NOT have spread syntax - so this could be fixed false
             *      ));
             * } else {*/
            // When last param types are parsed - it's necessary
            // to determinate single or multiple method forms by spread
            // and non-spread last param types

            if (
                !functionParamsSyntaxCollections.SpreadParamFound &&
                paramTypes.MethodOrEventParam.Count > 0 &&
                paramTypes.MethodOrEventSpreadParam.Count > 0
                )
            {
                // There will be two method forms:
                functionParamsSyntaxCollections.SpreadParamFound   = true;
                functionParamsSyntaxCollections.SpreadParamsSyntax = new List <Param>(
                    functionParamsSyntaxCollections.StandardParamsSyntax
                    );
                functionParamsSyntaxCollections.SpreadParamsSyntax.Add(new Param(
                                                                           this.sanitizeName(extObjectMemberParam.Name),
                                                                           docs,
                                                                           paramTypes.MethodOrEventSpreadParam,
                                                                           optional,
                                                                           true
                                                                           ));
                functionParamsSyntaxCollections.StandardParamsSyntax.Add(new Param(
                                                                             this.sanitizeName(extObjectMemberParam.Name),
                                                                             docs,
                                                                             paramTypes.MethodOrEventParam,
                                                                             optional,
                                                                             false
                                                                             ));
            }
            else if (paramTypes.MethodOrEventParam.Count > 0)
            {
                // There will be only standard params method form:
                functionParamsSyntaxCollections.StandardParamsSyntax.Add(new Param(
                                                                             this.sanitizeName(extObjectMemberParam.Name),
                                                                             docs,
                                                                             paramTypes.MethodOrEventParam,
                                                                             optional,
                                                                             false
                                                                             ));
            }
            else if (
                !functionParamsSyntaxCollections.SpreadParamFound &&
                paramTypes.MethodOrEventSpreadParam.Count > 0
                )
            {
                if (functionParamsSyntaxCollections.StandardParamsSyntax.Count > 0)
                {
                    // There is something in standard param(s) from previous param - duplicate everything into spread params collection first:
                    functionParamsSyntaxCollections.SpreadParamFound   = true;
                    functionParamsSyntaxCollections.SpreadParamsSyntax = new List <Param>(
                        functionParamsSyntaxCollections.StandardParamsSyntax
                        );
                    functionParamsSyntaxCollections.SpreadParamsSyntax.Add(new Param(
                                                                               this.sanitizeName(extObjectMemberParam.Name),
                                                                               docs,
                                                                               paramTypes.MethodOrEventSpreadParam,
                                                                               optional,
                                                                               true
                                                                               ));
                }
                else
                {
                    // Add into spread params collection:
                    functionParamsSyntaxCollections.SpreadParamFound = true;
                    functionParamsSyntaxCollections.SpreadParamsSyntax.Add(new Param(
                                                                               this.sanitizeName(extObjectMemberParam.Name),
                                                                               docs,
                                                                               paramTypes.MethodOrEventSpreadParam,
                                                                               optional,
                                                                               true
                                                                               ));
                }
            }
            //}
        }
Пример #5
0
        protected void readAndAddEvent(ref ExtClass extClass, ExtObjectMember extObjectMember, ref FuncParamsSyntaxCollections funcParamsSyntaxCollections, string eventName, bool ownedByCurrent)
        {
            string[] docs         = this.readJsDocs(extObjectMember.Doc, JsDocsType.EVENT, extClass.Name.FullName, eventName);
            Event    newEventItem = new Event(
                eventName, funcParamsSyntaxCollections.StandardParamsSyntax, docs, extObjectMember.Owner, ownedByCurrent
                );

            newEventItem.Deprecated = this.readJsDocsDeprecated(
                extObjectMember.Deprecated, extClass.Name.FullName, eventName
                );

            /*if (
             *      funcParamsSyntaxCollections.StandardParamsSyntax.Count == 0 || (
             *              funcParamsSyntaxCollections.StandardParamsSyntax.Count > 0 &&
             *              funcParamsSyntaxCollections.StandardParamsSyntax[0].Name != "_this"
             *      )
             * ) {
             *      Debugger.Break();
             * }*/
            if (extObjectMember.Return != null)
            {
                try {
                    throw new Exception(
                              $"Event methods couldn't have a return type: `{extClass.Name.FullName}:eventName`."
                              );
                } catch (Exception ex) {
                    this.processor.Exceptions.Add(ex);
                }
            }
            extClass.AddMemberEvent(newEventItem);
            if (funcParamsSyntaxCollections.SpreadParamsSyntax.Count > 0)
            {
                // There is necessary to add second method form,
                // because there was last param with standard param
                // syntax mixed with spread param syntax:
                Event newEventItemClone = newEventItem.Clone();
                newEventItemClone.Params = funcParamsSyntaxCollections.SpreadParamsSyntax;
                extClass.AddMemberEvent(newEventItemClone);
            }
        }
Пример #6
0
        /**
         * Complete reference `funcParamsSyntaxCollections` with given `param` into proper collections.
         */
        protected void readFunctionParam(ExtObjectMember extObjectMember, MemberParam param, ref FuncParamsSyntaxCollections funcParamsSyntaxCollections, ref ParsedTypes?lastParamTypes, bool eventCompleting, string currentClassName, string eventOrMethodName, bool isStatic, bool eventsCompleting, int lastParamIndex, int paramIndex)
        {
            ParsedTypes paramTypes;
            bool        lastParamDefinition = paramIndex == lastParamIndex;

            // Parse param types - this types parsing result could have more result method forms:
            // - most often is form with normal params syntax
            // - but sometimes there could be another send method form
            //   with params spread syntax or only this syntax
            if (lastParamDefinition)
            {
                paramTypes = lastParamTypes.Value;
            }
            else
            {
                paramTypes = this.typesParser.Parse(
                    eventCompleting
                                                ? TypeDefinitionPlace.EVENT_PARAM
                                                : TypeDefinitionPlace.METHOD_PARAM,
                    currentClassName + "." + extObjectMember.Name,
                    param.Name,
                    param.Type
                    );
            }
            // If param contains any sub-definitions, then param is probably
            // some kind of configuration object, which has all it's members
            // defined in Ext documentation. Then it's practicle to generate sub-interface:
            if (param.Properties != null && param.Properties.Count > 0)
            {
                this.readFunctionParamSpecials(
                    param,
                    ref paramTypes,
                    eventCompleting,
                    currentClassName,
                    eventOrMethodName,
                    isStatic,
                    eventCompleting
                    );
            }
            //if (currentClassName == "Ext" && eventOrMethodName == "create")
            //	Debugger.Break();
            // Add completed param types into proper collection with name, param docs and all it's flags:
            this.readFunctionParamAddToParamsList(
                param,
                ref funcParamsSyntaxCollections,
                ref paramTypes,
                currentClassName,
                eventCompleting,
                lastParamDefinition
                );
        }