示例#1
0
        public static void EmitComment(IAbstractEmitterBlock block, AstNode node, bool?getter = null, VariableInitializer varInitializer = null)
        {
            if (block.Emitter.AssemblyInfo.GenerateDocumentation == Bridge.Contract.DocumentationMode.None || node.Parent == null)
            {
                return;
            }

            var visitor = new DocumentationCommentVisitor();

            node.AcceptChildren(visitor);

            if (block.Emitter.AssemblyInfo.GenerateDocumentation == Bridge.Contract.DocumentationMode.Basic && visitor.Comments.Count == 0)
            {
                return;
            }

            object value  = null;
            var    rr     = block.Emitter.Resolver.ResolveNode(varInitializer ?? node, block.Emitter);
            string source = BuildCommentString(visitor.Comments);

            if (node is FieldDeclaration)
            {
                var initializer = varInitializer.Initializer as PrimitiveExpression;

                if (initializer != null)
                {
                    value = initializer.Value;
                }
            }
            else if (node is EventDeclaration)
            {
                var eventDecl = (EventDeclaration)node;
                foreach (var evVar in eventDecl.Variables)
                {
                    var ev_rr = block.Emitter.Resolver.ResolveNode(evVar, block.Emitter);
                    var memberResolveResult = ev_rr as MemberResolveResult;
                    var ev = memberResolveResult.Member as IEvent;

                    if (!getter.HasValue || getter.Value)
                    {
                        var comment = new JsDocComment();
                        InitMember(comment, ev.AddAccessor, block.Emitter, null);
                        comment.Function = Helpers.GetEventRef(ev, block.Emitter, false);
                        block.Write(
                            block.WriteIndentToString(XmlToJsDoc.ReadComment(source, ev_rr, block.Emitter, comment)));
                        block.WriteNewLine();
                    }

                    if (!getter.HasValue || !getter.Value)
                    {
                        var comment = new JsDocComment();
                        InitMember(comment, ev.RemoveAccessor, block.Emitter, null);
                        comment.Function = Helpers.GetEventRef(ev, block.Emitter, true);
                        block.Write(
                            block.WriteIndentToString(XmlToJsDoc.ReadComment(source, ev_rr, block.Emitter, comment)));
                        block.WriteNewLine();
                    }
                }

                return;
            }

            var prop = node as PropertyDeclaration;

            if (prop != null)
            {
                var memberResolveResult = rr as MemberResolveResult;
                var rProp = memberResolveResult.Member as IProperty;

                var comment = new JsDocComment();
                InitMember(comment, rProp, block.Emitter, null);
                comment.Function = Helpers.GetPropertyRef(rProp, block.Emitter);
                block.Write(block.WriteIndentToString(XmlToJsDoc.ReadComment(source, rr, block.Emitter, comment)));
                block.WriteNewLine();
                return;
            }

            var indexer = node as IndexerDeclaration;

            if (indexer != null)
            {
                var memberResolveResult = rr as MemberResolveResult;
                var rProp = memberResolveResult.Member as IProperty;

                var comment = new JsDocComment();
                InitMember(comment, getter.HasValue && getter.Value ? rProp.Getter : rProp.Setter, block.Emitter, null);
                block.Write(block.WriteIndentToString(XmlToJsDoc.ReadComment(source, rr, block.Emitter, comment)));
                block.WriteNewLine();
                return;
            }

            block.Write(block.WriteIndentToString(XmlToJsDoc.Convert(source, rr, block.Emitter, value)));

            block.WriteNewLine();
        }
示例#2
0
        public static void EmitComment(IAbstractEmitterBlock block, AstNode node)
        {
            if (block.Emitter.AssemblyInfo.GenerateDocumentation == Bridge.Contract.DocumentationMode.None || node.Parent == null)
            {
                return;
            }

            var visitor = new DocumentationCommentVisitor();

            node.AcceptChildren(visitor);

            if (block.Emitter.AssemblyInfo.GenerateDocumentation == Bridge.Contract.DocumentationMode.Basic && visitor.Comments.Count == 0)
            {
                return;
            }

            object value = null;

            if (node is FieldDeclaration)
            {
                var fieldDecl = (FieldDeclaration)node;
                node = fieldDecl.Variables.First();
                var initializer = fieldDecl.Variables.First().Initializer as PrimitiveExpression;

                if (initializer != null)
                {
                    value = initializer.Value;
                }
            }
            else if (node is EventDeclaration)
            {
                var eventDecl = (EventDeclaration)node;
                node = eventDecl.Variables.First();
                var initializer = eventDecl.Variables.First().Initializer as PrimitiveExpression;

                if (initializer != null)
                {
                    value = initializer.Value;
                }
            }

            var    rr     = block.Emitter.Resolver.ResolveNode(node, block.Emitter);
            string source = BuildCommentString(visitor.Comments);

            var prop = node as PropertyDeclaration;

            if (prop != null)
            {
                var memberResolveResult = rr as MemberResolveResult;
                var rProp = memberResolveResult.Member as DefaultResolvedProperty;

                var comment = new JsDocComment();
                InitMember(comment, rProp.Getter, block.Emitter, null);
                comment.Function = Helpers.GetPropertyRef(rProp, block.Emitter, false);
                block.Write(block.WriteIndentToString(XmlToJsDoc.ReadComment(source, rr, block.Emitter, comment)));
                block.WriteNewLine();

                comment = new JsDocComment();
                InitMember(comment, rProp.Setter, block.Emitter, null);
                comment.Function = Helpers.GetPropertyRef(rProp, block.Emitter, true);
                block.Write(block.WriteIndentToString(XmlToJsDoc.ReadComment(source, rr, block.Emitter, comment)));
                block.WriteNewLine();
                return;
            }

            block.Write(block.WriteIndentToString(XmlToJsDoc.Convert(source, rr, block.Emitter, value)));

            block.WriteNewLine();
        }