Sequence diagram generator from text4/14/2023 20 3.4 Call3.fdl: Object Management and Message Parameters. 19 3.3 Call2.fdl: Comments, Remarks and Issues. 18 3.2.1 What are Modules, Processors and Objects?. 17 3.2 Call1.fdl: Introduction to the Language. 15įDL Syst System em Desig Design n Lang Language uage. 12 2.3.2 Creating Hello.scn Scenario Project. Table of Contents Table 1 Introduction.1 1.1 1.2 1.3ĮventStudio System Designer. Now you can use plantuml to create the diagrams.Copyri ght © 20002000-200 2007. The only things to notice are the starting and closing plantuml notation lines that we add to our generated files. Since ClassDiagramGenerator is nothing more than a CSharpSyntaxWalker, we just need to gather the text, parse it, and give the order to visit the tree with our walker. Using (var writer = new StreamWriter(new FileStream(outputFile + ".antuml", FileMode.OpenOrCreate, gen = new ClassDiagramGenerator(writer, " don’t show the whole main method because it’s you typical console app: very simple. Var tree = CSharpSyntaxTree.ParseText(SourceText.From(stream)) Using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read)) String outputFile = Path.Combine(outputDir, Path.GetFileNameWithoutExtension(file)) Var initValue = useLiteralInit ? (" = " + ()) : "" Var useLiteralInit = node.Initializer?.Value?.Kind().ToString().EndsWith("LiteralExpression") ? false Where(x => !x.Modifiers.Select(y => y.Kind()).Contains(SyntaxKind.PrivateKeyword)) Var modifiers = GetMemberModifiersText(node.Modifiers) Public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node) the most complicated method of this class Generating the diagram public class ClassDiagramGenerator : CSharpSyntaxWalker It’s less than 300 lines of code, including comments, so we can delve right in. Ehi, we are programmers, we are lazy, we are smart enough to leverage existing resources. In fact, I didn’t even need to write much code since there is already a small library that does it: 1. To generate class diagrams by leveraging the compiler is so easy because the compiler need to understand the source code and so every information is readily available to us. In real life it would be trivial to then create the diagrams programmatically, thanks to the command line and upload the images wherever you want. In short the idea is to create text files that are compatible with PlantUML for every class of our source code and then to use PlantUML to create the actual diagrams. For instance, you can hide private properties and methods that the user of the library doesn’t need to know. Another advantage is that by understanding the source code programmatically you can hide or shows information that are not needed by the reader. Roslyn, instead, allows you to easily create diagrams, at least some kind of diagrams such as class diagrams. The traditional way is to create them is by hand, which is prone to make them obsolete, or to use programs that reverse engineer the code itself, which is costly and not easily adaptable. In particular today we are talking about UML diagrams. No, it’s true, Roslyn would not write documentation on its own, but it can be used to make it easier and even manage other structured information. And this doesn’t even count people that don’t understand code, but they need to know the feature of the software. Time is too much valuable to lose it behind other people’s code. But, even for open source software, how many are going to wade through hundreds of files to understand how to use the damn thing ? The reality is that if there is no documentation, it doesn’t exist for most people. You may say that the point number 1 is already true in any case. you can integrate the support for these tools into the processes of continuous integration that you already use.the source code become the truth, from which everything follow.There is two great advantages to use the source code to support everything else: Another possibility is to leverage the knowledge that the compiler has, to support other tools that you use as a programmer, or that are needed by co-workers to simplify their job. That’s all well and good, but it’s not the only thing you can do when you have a compiler open and ready to do your bidding. Last week we have seen how to use Roslyn to rewrite source code to your liking. The code for this post in on GitHub: generate-diagrams-from-source-code Beyond the source code
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |