/// <summary>
        /// Determines the amount of offset to add to the line number of the next argument
        /// for a comment or attribute. 
        /// </summary>
        /// <param name="item">The starting item.</param>
        /// <returns>Returns the amount of offset to add.</returns>
        private static int ParameterPrewordOffset(CodeUnit item)
        {
            Param.AssertNotNull(item, "tokenNode");

            Debug.Assert(item.Is(CodeUnitType.Attribute) || item.Is(LexicalElementType.Comment), "The item must be an attribute or a comment.");

            // Find the start of the next argument.
            for (CodeUnit next = item.FindLast().FindNext(); next != null; next = next.FindNext())
            {
                if (next.Is(LexicalElementType.EndOfLine))
                {
                    return item.Location.LineSpan;
                }
                else if (!next.Is(LexicalElementType.WhiteSpace) &&
                    !next.Is(LexicalElementType.WhiteSpace) &&
                    !next.Is(CodeUnitType.Attribute))
                {
                    return Math.Max(0, next.Location.StartPoint.LineNumber - item.Location.StartPoint.LineNumber);
                }
            }

            return 0;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Visits one code unit in the document.
        /// </summary>
        /// <param name="codeUnit">The item being visited.</param>
        /// <param name="parentElement">The parent element, if any.</param>
        /// <param name="parentStatement">The parent statement, if any.</param>
        /// <param name="parentExpression">The parent expression, if any.</param>
        /// <param name="parentClause">The parent query clause, if any.</param>
        /// <param name="parentToken">The parent token, if any.</param>
        /// <param name="settings">The settings.</param>
        /// <returns>Returns true to continue, or false to stop the walker.</returns>
        private bool VisitCodeUnit(
            CodeUnit codeUnit,
            Element parentElement,
            Statement parentStatement,
            Expression parentExpression,
            QueryClause parentClause,
            Token parentToken,
            Settings settings)
        {
            Param.AssertNotNull(codeUnit, "codeUnit");
            Param.Ignore(parentElement, parentStatement, parentExpression, parentClause, parentToken);
            Param.AssertNotNull(settings, "settings");

            if (codeUnit.CodeUnitType == CodeUnitType.Element)
            {
                return this.VisitElement((Element)codeUnit, settings);
            }
            else if (codeUnit.CodeUnitType == CodeUnitType.Expression)
            {
                return this.VisitExpression((Expression)codeUnit, parentElement);
            }
            else if (codeUnit.Is(LexicalElementType.Token))
            {
                Token token = (Token)codeUnit;
                if (token.TokenType == TokenType.Type && !token.Parent.Is(TokenType.Type))
                {
                    // Check that the type is using the built-in types, if applicable.
                    this.CheckBuiltInType((TypeToken)token, parentElement);
                }
                else if (token.TokenType == TokenType.String)
                {
                    // Check that the string is not using the empty string "" syntax.
                    this.CheckEmptyString(token, parentElement);
                }
            }
            else if (codeUnit.Is(PreprocessorType.Region))
            {
                this.CheckRegion((RegionDirective)codeUnit, parentElement, settings);
            }
            else if (codeUnit.Is(LexicalElementType.Comment))
            {
                this.CheckForEmptyComments((Comment)codeUnit, parentElement);
            }

            return !this.Cancel;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Records information about the given item, under the given node.
        /// </summary>
        /// <param name="item">The item to record.</param>
        /// <param name="parentNode">The Xml node to record this item beneath.</param>
        /// <returns>Returns the new Xml node describing this item.</returns>
        private static XmlNode RecordItem(CodeUnit item, XmlNode parentNode)
        {
            Param.AssertNotNull(item, "item");
            Param.AssertNotNull(parentNode, "parentNode");

            // Create a new node for this item and add it to the parent.
            XmlNode codeUnitNode = parentNode.OwnerDocument.CreateElement("CodeUnit");
            parentNode.AppendChild(codeUnitNode);

            if (item.Is(CodeUnitType.LexicalElement))
            {
                XmlAttribute text = parentNode.OwnerDocument.CreateAttribute("Text");
                text.Value = ((LexicalElement)item).Text;
                codeUnitNode.Attributes.Append(text);
            }

            XmlAttribute type = parentNode.OwnerDocument.CreateAttribute("Type");
            type.Value = item.GetType().Name;
            codeUnitNode.Attributes.Append(type);

            return codeUnitNode;
        }