public void Initialize(LocationStore locationStore, ClassStore classStore) { char[] delimiters = new char[] { ' ', '\t', '\r', '\n' }; if (Type == CommentType.SingleLine) { string normalizedContent = WordTransform.RemoveSpecialCharacters(Content); WordsCount = normalizedContent.Split(delimiters, StringSplitOptions.RemoveEmptyEntries).Length; } if (locationStore.LocationsRelativeToMethod.ContainsKey(LineEnd)) { LocationRelativeToMethod = locationStore.LocationsRelativeToMethod[LineEnd].Location; MethodName = locationStore.LocationsRelativeToMethod[LineEnd].Method; } if (locationStore.LocationsRelativeToClass.ContainsKey(LineEnd)) { LocationRelativeToClass = locationStore.LocationsRelativeToClass[LineEnd].Location; Class @class = classStore.Classes.Single(c => c.Name == locationStore.LocationsRelativeToClass[LineEnd].Class.Name && c.Namespace == locationStore.LocationsRelativeToClass[LineEnd].Class.Namespace); @class.Comments.Add(this); this.Class = @class; } HasNothing = new Regex("nothing", RegexOptions.IgnoreCase).IsMatch(Content); HasQuestionMark = new Regex(@"\?($|\W)").IsMatch(Content); HasExclamationMark = new Regex("!").IsMatch(Content); HasCode = CodeDetector.HasCode(Content); if (MethodName != null && LocationRelativeToMethod == LocationRelativeToMethod.MethodDescription) { CoherenceCoefficient = CommentsAnalysis.CoherenceCoefficient.Compute(Content, MethodName); } }
public void AddCommentTrivia(SyntaxTrivia trivia, LocationStore commentLocationstore, ClassStore classStore, string fileName) { if (trivia.Kind() == SyntaxKind.SingleLineCommentTrivia) { Comment comment = new SingleLineComment(trivia.ToString(), trivia.GetLocation().GetLineSpan().EndLinePosition.Line + 1) { FileName = fileName, }; comment.Initialize(commentLocationstore, classStore); Comments.Add(comment); } else if (trivia.Kind() == SyntaxKind.MultiLineCommentTrivia) { Comment comment = new MultiLineComment(trivia.ToString(), trivia.GetLocation().GetLineSpan().StartLinePosition.Line + 1, trivia.GetLocation().GetLineSpan().EndLinePosition.Line + 1) { FileName = fileName, }; comment.Initialize(commentLocationstore, classStore); Comments.Add(comment); } }
public CommentsWalker(string fileName, LocationStore commentLocationStore, CommentStore commentStore, ClassStore classStore) : base(SyntaxWalkerDepth.StructuredTrivia) { _fileName = fileName; _commentLocationStore = commentLocationStore; _commentStore = commentStore; _classStore = classStore; }
public void AddCommentNode(DocumentationCommentTriviaSyntax node, LocationStore commentLocationstore, ClassStore classStore, string fileName) { Comment comment = new DocComment(node.ToString(), node.GetLocation().GetLineSpan().StartLinePosition.Line + 1, node.GetLocation().GetLineSpan().EndLinePosition.Line) { FileName = fileName, }; comment.Initialize(commentLocationstore, classStore); Comments.Add(comment); }
//static string folderName = "EntityFrameworkCore"; //static string designiteFileName = "Designite_EFCore.xls"; //static string solutionName = "EFCore"; //static string folderName = "ScreenToGif"; //static string designiteFileName = "Designite_GifRecorder.xls"; //static string solutionName = "GifRecorder"; static void Main(string[] args) { SmellsStore.Initialize($@"../../../../DesigniteResults/{designiteFileName}", solutionName); string fileContent; SyntaxTree tree; SyntaxNode root; CommentsWalker commentsWalker; MethodsAndClassesWalker methodsAndClassesWalker; string[] files = Directory.GetFiles($@"../../../../Projects/{folderName}", $"*.cs", SearchOption.AllDirectories) .Where(s => !s.EndsWith(".designer.cs", StringComparison.InvariantCultureIgnoreCase)).ToArray(); var commentStore = new CommentStore(); var classStore = new ClassStore(); Console.WriteLine("Reading files..."); ProgressBar progressBar = new ProgressBar(files.Length); foreach (var file in files) { fileContent = File.ReadAllText(file); fileContent = TransformSingleLineComments(fileContent); tree = CSharpSyntaxTree.ParseText(fileContent); root = tree.GetRoot(); var locationStore = new LocationStore(); string filePath = new Regex($@"{folderName}\\(.*)").Match(file).Groups[1].ToString(); methodsAndClassesWalker = new MethodsAndClassesWalker(filePath, locationStore, classStore); methodsAndClassesWalker.Visit(root); commentsWalker = new CommentsWalker(filePath, locationStore, commentStore, classStore); commentsWalker.Visit(root); progressBar.UpdateAndDisplay(); } Console.WriteLine("\nCreating excel file..."); ExcelWriter excelWriter = new ExcelWriter($"{solutionName}_comments.xlsx"); excelWriter.Write(commentStore, classStore); Console.WriteLine("Finished"); Console.ReadKey(); }
public MethodsAndClassesWalker(string fileName, LocationStore locationStore, ClassStore classStore) { _fileName = fileName; _locationStore = locationStore; _classStore = classStore; }