Beispiel #1
0
        private CommentLineContext ProcessCommentLine(
            FileInfo file, string line, string lineArgument, CommentLineContext commentLineContext, char[] whitespace, int lineNumber)
        {
            if (commentLineContext.XmlFragmentContext == null)
            {
                if (lineArgument.TrimStart(whitespace).StartsWith("<" + FunctionDeclaration.ElementName))
                {
                    return(new CommentLineContext(ProcessXmlFragmentOpeningTagLine(line, lineArgument, whitespace, lineNumber), null, false));
                }

                return(commentLineContext);
            }
            else
            {
                commentLineContext.XmlFragmentContext.XmlFragment.AppendLine();
                commentLineContext.XmlFragmentContext.XmlFragment.Append(lineArgument);
                commentLineContext.XmlFragmentContext.Indents.Add(line.IndexOf(lineArgument));
                if (lineArgument.TrimEnd(whitespace).EndsWith("</" + FunctionDeclaration.ElementName + ">"))
                {
                    return(ProcessXmlFragmentClosingTagLine(commentLineContext.XmlFragmentContext, file));
                }
                else
                {
                    return(commentLineContext);
                }
            }
        }
Beispiel #2
0
        public void ProcessFile(FileInfo file, char[] whitespace, CodeCompileUnit unit)
        {
            CommentLineContext commentLineContext       = new CommentLineContext(null, null, false);
            List <string>      importNamespaces         = new List <string>(); // namespaces to import
            StringBuilder      currentNamespaceBuilder  = new StringBuilder();
            Action <string>    currentNamespaceAppender = s =>
            {
                if (currentNamespaceBuilder.Length > 0)
                {
                    currentNamespaceBuilder.Append(".");
                }
                currentNamespaceBuilder.Append(s);
            };

            StreamReader reader     = new StreamReader(file.FullName, true);
            int          lineNumber = 1;

            for (string line = reader.ReadLine(); line != null; line = reader.ReadLine(), lineNumber++)
            {
                string       lineArgument;
                CodeLineType lineType = _languageProvider.ParseLine(line, out lineArgument);

                if (lineType == CodeLineType.NamespaceImport)
                {
                    ProcessNamespaceImportLine(importNamespaces, lineArgument);
                }
                else if (lineType == CodeLineType.NamespaceDeclaration)
                {
                    ProcessNamespaceDeclarationLine(lineArgument, currentNamespaceAppender);
                }
                else if (lineType == CodeLineType.LineComment)
                {
                    commentLineContext = ProcessCommentLine(file, line, lineArgument, commentLineContext, whitespace, lineNumber);
                    if (commentLineContext.IsXmlFragmentComplete)
                    {
                        continue;
                    }
                }
                else if (lineType == CodeLineType.ClassDeclaration)
                {
                    if (!commentLineContext.IsXmlFragmentComplete && commentLineContext.XmlFragmentContext != null)
                    {
                        ProcessXmlFragment(commentLineContext.XmlFragmentContext, file);
                    }

                    ProcessClassDeclarationLine(lineArgument, currentNamespaceBuilder.ToString(), commentLineContext.FunctionDeclaration);
                    break;
                }
            }

            if (commentLineContext.IsXmlFragmentComplete && commentLineContext.FunctionDeclaration != null)
            {
                GenerateClass(file, importNamespaces, commentLineContext.FunctionDeclaration, unit, commentLineContext.XmlFragmentContext.FirstLineNumber);
            }
        }