public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node) { var defineName = string.Empty; var qNode = node.ChildNodes().OfType <QualifiedNameSyntax>().FirstOrDefault(); if (Util.IsNotNull(qNode)) { // Namespace NS1.NS2 defineName = qNode.ToString(); } else { // Namespace NS1 var iNode = node.ChildNodes().OfType <IdentifierNameSyntax>().FirstOrDefault(); defineName = iNode.ToString(); } var startLength = node.Span.Start; var endLength = node.Span.End; var parentNamespace = GetNamespace(DefineKinds.Namespace, startLength, endLength); UserDefinitions.Add(new UserDefinition { DefineKinds = DefineKinds.Namespace, Namespace = parentNamespace, DefineName = defineName, DefineFullName = string.IsNullOrEmpty(parentNamespace) ? defineName : $"{parentNamespace}.{defineName}", SourceFile = SourceFile, StartLength = startLength, EndLength = endLength, }); base.VisitNamespaceDeclaration(node); }
private static void PrintNamespaceNode(NamespaceDeclarationSyntax member, int depth) { Console.WriteLine($"NAMESPACE {member.Name}"); foreach (var childMember in member.ChildNodes()) { PrintTree(childMember, depth); } }
private static bool CheckKind(NamespaceDeclarationSyntax namespaceDeclaration, SyntaxKind kind) { return(namespaceDeclaration .ChildNodes() .Count(t => t.IsKind(kind)) > 1); }
public void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node) { if (node == null) throw new ArgumentNullException("node"); node.Validate(); WriteLeadingTrivia(node); _writer.WriteIndent(); _writer.WriteKeyword(PrinterKeyword.Namespace); _writer.WriteSpace(); node.Name.Accept(this); _writer.PushBraceFormatting(_writer.Configuration.BracesLayout.TypeAndNamespaceDeclaration); if (!node.ChildNodes().Any()) { _writer.EmptyBlock(_writer.Configuration.BlankLines.InsideNamespace); } else { _writer.BeginBlock(); _writer.WriteLine(_writer.Configuration.BlankLines.InsideNamespace); WriteGlobalNodes( node.Usings, node.Externs, node.Members, null ); _writer.WriteLine(_writer.Configuration.BlankLines.InsideNamespace); _writer.EndBlock(); } _writer.PopBraceFormatting(); WriteTrailingTrivia(node); }
void ProcessInterfaces(YNamespace @namespace, NamespaceDeclarationSyntax inputNamespace) { // Interfaces: foreach (var inputInterace in inputNamespace.ChildNodes().OfType <InterfaceDeclarationSyntax>()) { var interfaceName = inputInterace.GetName(); if (interfaceName == "") { continue; } var @interface = new YClass(interfaceName); @namespace.AddChild(@interface); _generationUnits.Add(new GenerationUnit(@interface)); // Methods: foreach (var inputMethod in inputInterace.ChildNodes().OfType <MethodDeclarationSyntax>()) { var name = inputMethod.Identifier.ToString(); var methodReturnType = inputMethod.ReturnType; var parameterList = inputMethod.ParameterList; YMethod method; // Signature: if (parameterList.Parameters.Count() <= 0) { method = new YMethod(name, inputMethod.ReturnType.GetYType()); } else { var @params = new List <YParameter>(); foreach (var p in parameterList.Parameters) { @params.Add(new YParameter(p.GetName(), p.Type.GetYType())); } method = new YMethod(name, inputMethod.ReturnType.GetYType(), @params.ToArray()); } // Body: // all methods of an interface are public and pure by default method.IsPure = true; method.Visibility = YVisibility.Public; @interface.AddChild(method); } // Misc: var destructor = new YDestructor(); destructor.IsVirtual = true; destructor.Visibility = YVisibility.Public; destructor.Body = new YBlock(); @interface.AddChild(destructor); } }
void ProcessClasses(YNamespace @namespace, NamespaceDeclarationSyntax inputNamespace) { // Classes: foreach (var inputClass in inputNamespace.ChildNodes().OfType <ClassDeclarationSyntax>()) { var className = inputClass.GetName(); if (className == "") { continue; } var @class = new YClass(className); @namespace.AddChild(@class); _generationUnits.Add(new GenerationUnit(@class)); // Fields: foreach (var inputField in inputClass.ChildNodes().OfType <FieldDeclarationSyntax>()) { var declaration = inputField.Declaration; var declarationType = declaration.Type; var variables = declaration.Variables; if (variables.Count == 1) { var variable = variables[0]; var field = new YField() { Type = declarationType.GetYType(), Name = variable.GetName() }; field.Visibility = inputField.Modifiers.GetYVisibility(); // expresions: literal // todo process negative numbers if (variable.Initializer?.Value is LiteralExpressionSyntax) { var literalExperssion = (LiteralExpressionSyntax)variable.Initializer.Value; if (literalExperssion.Token.Value is int) { field.Value = new YConstExpr((int)literalExperssion.Token.Value); } } @class.AddChild(field); } else { throw new TException("Unsupported"); } } // Methods: foreach (var inputMethod in inputClass.ChildNodes().OfType <MethodDeclarationSyntax>()) { var name = inputMethod.Identifier.ToString(); var methodReturnType = inputMethod.ReturnType; var parameterList = inputMethod.ParameterList; YMethod method; // Signature: if (parameterList.Parameters.Count() <= 0) { method = new YMethod(name, inputMethod.ReturnType.GetYType()); } else { var @params = new List <YParameter>(); foreach (var p in parameterList.Parameters) { @params.Add(new YParameter(p.GetName(), p.Type.GetYType())); } method = new YMethod(name, inputMethod.ReturnType.GetYType(), @params.ToArray()); } // Body: method.Visibility = inputMethod.Modifiers.GetYVisibility(); method.Body = ProcessStatement(inputMethod.Body); @class.AddChild(method); } } }