void WriteRoutine(SourceRoutineSymbol routine)
 {
     if (routine.IsGlobalScope)
     {
         return;                         // global code have no XML annotation
     }
     WriteRoutine(CommentIdResolver.GetId(routine), routine);
 }
Esempio n. 2
0
        void WriteType(SourceTypeSymbol type)
        {
            _writer.WriteLine($"<member name=\"{CommentIdResolver.GetId(type)}\">");
            var phpdoc = type.Syntax?.PHPDoc;

            if (phpdoc != null)
            {
                WriteSummary(phpdoc.Summary);
            }
            _writer.WriteLine("</member>");

            //
            // fields
            //

            foreach (var field in type.GetMembers().OfType <SourceFieldSymbol>())
            {
                if ((phpdoc = field.PhpDocBlock) != null)
                {
                    var summary = phpdoc.Summary;
                    var value   = string.Empty;
                    if (string.IsNullOrEmpty(summary))
                    {
                        // try @var or @staticvar:
                        var vartag = field.FindPhpDocVarTag();
                        if (vartag != null)
                        {
                            summary = vartag.Description;

                            if (!string.IsNullOrEmpty(vartag.TypeNames))
                            {
                                value = string.Format("<value>{0}</value>", XmlEncode(vartag.TypeNames));
                            }
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(summary))
                    {
                        _writer.WriteLine($"<member name=\"{CommentIdResolver.GetId(field)}\">");
                        WriteSummary(summary);
                        _writer.WriteLine(value);
                        _writer.WriteLine("</member>");
                    }
                }
            }

            //
            // .ctor
            //
            foreach (var ctor in type.InstanceConstructors)
            {
                if (ctor is SynthesizedPhpCtorSymbol synctor && synctor.PhpConstructor is SourceRoutineSymbol phpctor)
                {
                    WriteRoutine(CommentIdResolver.GetId(synctor), phpctor);
                }
            }
        }
        void WriteType(SourceTypeSymbol type)
        {
            _writer.WriteLine($"<member name=\"{CommentIdResolver.GetId(type)}\">");
            var phpdoc = type.Syntax?.PHPDoc;

            if (phpdoc != null)
            {
                WriteSummary(phpdoc.Summary);
            }
            _writer.WriteLine("</member>");
        }
Esempio n. 4
0
        void WriteRoutine(SourceRoutineSymbol routine)
        {
            var ps = routine.Parameters;

            //
            _writer.WriteLine($"<member name=\"{CommentIdResolver.GetId(routine)}\">");

            // PHPDoc
            var phpdoc = routine.PHPDocBlock;

            if (phpdoc != null)
            {
                WriteSummary(phpdoc.Summary);

                // user parameters
                foreach (var p in phpdoc.Params)
                {
                    // TODO: note the parameter type into Doc comment

                    if (p.VariableName != null)
                    {
                        WriteParam(p.VariableName.TrimStart('$'), p.Description, p.TypeNames);
                    }
                }
                var rtag = phpdoc.Returns;
                if (rtag != null && !string.IsNullOrWhiteSpace(rtag.Description))
                {
                    _writer.WriteLine("<returns>{0}</returns>", XmlEncode(rtag.Description));
                }
            }

            // TODO: <exception> ... if any

            //// implicit parameters
            //foreach (var p in ps)
            //{
            //    if (p.IsImplicitlyDeclared)
            //    {
            //        if (SpecialParameterSymbol.IsContextParameter(p))
            //        {
            //            // WriteParam(p.MetadataName, PhpResources.XmlDoc_ContextParamDescription);
            //        }
            //    }
            //    else
            //    {
            //        break;  // implicit parameters are always at begining
            //    }
            //}

            _writer.WriteLine("</member>");
        }
Esempio n. 5
0
 void WriteRoutine(SourceRoutineSymbol routine) => WriteRoutine(CommentIdResolver.GetId(routine), routine);
        void WriteType(SourceTypeSymbol type)
        {
            _writer.WriteLine($"<member name=\"{CommentIdResolver.GetId(type)}\">");
            var phpdoc = type.Syntax?.PHPDoc;

            if (phpdoc != null)
            {
                WriteSummary(_writer, phpdoc.Summary);
            }
            _writer.WriteLine("</member>");

            //
            // fields
            //

            foreach (var field in type.GetMembers().OfType <SourceFieldSymbol>())
            {
                if ((phpdoc = field.PHPDocBlock) != null)
                {
                    var summary = phpdoc.Summary;
                    var value   = string.Empty;
                    if (string.IsNullOrEmpty(summary))
                    {
                        // try @var or @staticvar:
                        var vartag = field.FindPhpDocVarTag();
                        if (vartag != null)
                        {
                            summary = vartag.Description;

                            if (!string.IsNullOrEmpty(vartag.TypeNames))
                            {
                                value = string.Format("<value>{0}</value>", XmlEncode(vartag.TypeNames));
                            }
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(summary))
                    {
                        _writer.WriteLine($"<member name=\"{CommentIdResolver.GetId(field)}\">");
                        WriteSummary(_writer, summary);
                        _writer.WriteLine(value);
                        _writer.WriteLine("</member>");
                    }
                }
            }

            //
            // .ctor
            //
            var ctors = type.InstanceConstructors;

            for (int i = 0; i < ctors.Length; i++)
            {
                // find __construct()
                if (ctors[i] is SynthesizedPhpCtorSymbol synctor && synctor.PhpConstructor is SourceRoutineSymbol php_construct)
                {
                    // annotate all generated .ctor() methods:
                    for (int j = 0; j < ctors.Length; j++)
                    {
                        var ctor_id = CommentIdResolver.GetId(ctors[j]);

                        if (ctors[j].IsFieldsOnlyConstructor())
                        {
                            // annotate special .ctor that initializes only fields
                            _writer.WriteLine($"<member name=\"{ctor_id}\">");
                            WriteSummary(_writer, Peachpie.CodeAnalysis.PhpResources.XmlDoc_FieldsOnlyCtor);
                            _writer.WriteLine("</member>");
                        }
                        else
                        {
                            WriteRoutine(ctor_id, php_construct);
                        }
                    }

                    break;
                }
            }
        }