public Generate ( Microsoft.CodeAnalysis.SyntaxNode root ) : void | ||
root | Microsoft.CodeAnalysis.SyntaxNode | |
return | void |
private static bool GeneratePlantUmlFromFile(Dictionary <string, string> parameters) { var inputFileName = parameters["in"]; if (!File.Exists(inputFileName)) { Console.WriteLine($"\"{inputFileName}\" does not exist."); return(false); } var outputFileName = ""; if (parameters.ContainsKey("out")) { outputFileName = parameters["out"]; try { var outdir = Path.GetDirectoryName(outputFileName); Directory.CreateDirectory(outdir); } catch (Exception e) { Console.WriteLine(e); return(false); } } else { outputFileName = CombinePath(Path.GetDirectoryName(inputFileName), Path.GetFileNameWithoutExtension(inputFileName) + ".puml"); } try { using (var stream = new FileStream(inputFileName, FileMode.Open, FileAccess.Read)) { var tree = CSharpSyntaxTree.ParseText(SourceText.From(stream)); var root = tree.GetRoot(); Accessibilities ignoreAcc = GetIgnoreAccessibilities(parameters); using (var filestream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write)) using (var writer = new StreamWriter(filestream)) { var gen = new ClassDiagramGenerator(writer, " ", ignoreAcc); gen.Generate(root); } } } catch (Exception e) { Console.WriteLine(e); return(false); } return(true); }
public void GenerateTest_All() { var code = File.ReadAllText("testData\\inputClasses.cs"); var tree = CSharpSyntaxTree.ParseText(code); var root = tree.GetRoot(); var output = new StringBuilder(); using (var writer = new StringWriter(output)) { var gen = new ClassDiagramGenerator(writer, " "); gen.Generate(root); } var expected = ConvertNewLineCode(File.ReadAllText(@"uml\all.puml"),Environment.NewLine); var actual = output.ToString(); Console.Write(actual); Assert.AreEqual(expected, actual); }
public void GenerateTest_GenericsTypes() { var code = File.ReadAllText("testData\\GenericsType.cs"); var tree = CSharpSyntaxTree.ParseText(code); var root = tree.GetRoot(); var output = new StringBuilder(); using (var writer = new StringWriter(output)) { var gen = new ClassDiagramGenerator(writer, " ", Accessibilities.Private | Accessibilities.Internal | Accessibilities.Protected | Accessibilities.ProtectedInternal); gen.Generate(root); } var expected = ConvertNewLineCode(File.ReadAllText(@"uml\genericsType.puml"), Environment.NewLine); var actual = output.ToString(); Console.Write(actual); Assert.AreEqual(expected, actual); }
private static bool GeneratePlantUmlFromDir(Dictionary <string, string> parameters) { var inputRoot = parameters["in"]; if (!Directory.Exists(inputRoot)) { Console.WriteLine($"Directory \"{inputRoot}\" does not exist."); return(false); } var outputRoot = inputRoot; if (parameters.ContainsKey("out")) { outputRoot = parameters["out"]; try { Directory.CreateDirectory(outputRoot); } catch (Exception e) { Console.WriteLine(e); return(false); } } var excludePaths = new List <string>(); var pumlexclude = CombinePath(inputRoot, ".pumlexclude"); if (File.Exists(pumlexclude)) { excludePaths = File.ReadAllLines(pumlexclude).ToList(); } if (parameters.ContainsKey("-excludePaths")) { excludePaths.AddRange(parameters["-excludePaths"].Split(',')); } var files = Directory.EnumerateFiles(inputRoot, "*.cs", SearchOption.AllDirectories); var includeRefs = new StringBuilder(); includeRefs.AppendLine("@startuml"); var error = false; foreach (var inputFile in files) { if (excludePaths .Select(p => CombinePath(inputRoot, p)) .Any(p => inputFile.StartsWith(p, StringComparison.InvariantCultureIgnoreCase))) { Console.WriteLine($"Skipped \"{inputFile}\"..."); continue; } Console.WriteLine($"Processing \"{inputFile}\"..."); try { var outputDir = CombinePath(outputRoot, Path.GetDirectoryName(inputFile).Replace(inputRoot, "")); Directory.CreateDirectory(outputDir); var outputFile = CombinePath(outputDir, Path.GetFileNameWithoutExtension(inputFile) + ".puml"); using (var stream = new FileStream(inputFile, FileMode.Open, FileAccess.Read)) { var tree = CSharpSyntaxTree.ParseText(SourceText.From(stream)); var root = tree.GetRoot(); Accessibilities ignoreAcc = GetIgnoreAccessibilities(parameters); using (var filestream = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var writer = new StreamWriter(filestream)) { var gen = new ClassDiagramGenerator(writer, " ", ignoreAcc); gen.Generate(root); } } includeRefs.AppendLine("!include " + outputFile.Replace(outputRoot, @".\")); } catch (Exception e) { Console.WriteLine(e); error = true; } } includeRefs.AppendLine("@enduml"); File.WriteAllText(CombinePath(outputRoot, "include.puml"), includeRefs.ToString()); if (error) { Console.WriteLine("There were files that could not be processed."); return(false); } return(true); }
private static bool GeneratePlantUmlFromDir(Dictionary<string, string> parameters) { var inputRoot = parameters["in"]; if (!Directory.Exists(inputRoot)) { Console.WriteLine($"Directory \"{inputRoot}\" does not exist."); return false; } var outputRoot = inputRoot; if (parameters.ContainsKey("out")) { outputRoot = parameters["out"]; try { Directory.CreateDirectory(outputRoot); } catch (Exception e) { Console.WriteLine(e); return false; } } var excludePaths = new List<string>(); var pumlexclude = CombinePath(inputRoot, ".pumlexclude"); if (File.Exists(pumlexclude)) { excludePaths = File.ReadAllLines(pumlexclude).ToList(); } if (parameters.ContainsKey("-excludePaths")) { excludePaths.AddRange(parameters["-excludePaths"].Split(',')); } var files = Directory.EnumerateFiles(inputRoot, "*.cs", SearchOption.AllDirectories); var includeRefs = new StringBuilder(); includeRefs.AppendLine("@startuml"); var error = false; foreach (var inputFile in files) { if (excludePaths .Select(p => CombinePath(inputRoot,p)) .Any(p => inputFile.StartsWith(p,StringComparison.InvariantCultureIgnoreCase))) { Console.WriteLine($"Skipped \"{inputFile}\"..."); continue; } Console.WriteLine($"Processing \"{inputFile}\"..."); try { var outputDir = CombinePath(outputRoot, Path.GetDirectoryName(inputFile).Replace(inputRoot, "")); Directory.CreateDirectory(outputDir); var outputFile = CombinePath(outputDir, Path.GetFileNameWithoutExtension(inputFile) + ".puml"); using (var stream = new FileStream(inputFile, FileMode.Open, FileAccess.Read)) { var tree = CSharpSyntaxTree.ParseText(SourceText.From(stream)); var root = tree.GetRoot(); Accessibilities ignoreAcc = GetIgnoreAccessibilities(parameters); using (var filestream = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var writer = new StreamWriter(filestream)) { var gen = new ClassDiagramGenerator(writer, " ", ignoreAcc); gen.Generate(root); } } includeRefs.AppendLine("!include " + outputFile.Replace(outputRoot, @".\")); } catch (Exception e) { Console.WriteLine(e); error = true; } } includeRefs.AppendLine("@enduml"); File.WriteAllText(CombinePath(outputRoot, "include.puml"), includeRefs.ToString()); if (error) { Console.WriteLine("There were files that could not be processed."); return false; } return true; }
private static bool GeneratePlantUmlFromFile(Dictionary<string, string> parameters) { var inputFileName = parameters["in"]; if (!File.Exists(inputFileName)) { Console.WriteLine($"\"{inputFileName}\" does not exist."); return false; } var outputFileName = ""; if (parameters.ContainsKey("out")) { outputFileName = parameters["out"]; try { var outdir = Path.GetDirectoryName(outputFileName); Directory.CreateDirectory(outdir); } catch (Exception e) { Console.WriteLine(e); return false; } } else { outputFileName = CombinePath(Path.GetDirectoryName(inputFileName), Path.GetFileNameWithoutExtension(inputFileName) + ".puml"); } try { using (var stream = new FileStream(inputFileName, FileMode.Open, FileAccess.Read)) { var tree = CSharpSyntaxTree.ParseText(SourceText.From(stream)); var root = tree.GetRoot(); Accessibilities ignoreAcc = GetIgnoreAccessibilities(parameters); using (var filestream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write)) using (var writer = new StreamWriter(filestream)) { var gen = new ClassDiagramGenerator(writer, " ", ignoreAcc); gen.Generate(root); } } } catch (Exception e) { Console.WriteLine(e); return false; } return true; }