public override void Visit(Constructor c) { var newConstructor = new ConstructorDeclaration(); AddAttributeSection(newConstructor, c); var location = LocationsBag.GetMemberLocation(c); AddModifiers(newConstructor, location); newConstructor.AddChild(Identifier.Create(c.MemberName.Name, Convert(c.MemberName.Location)), Roles.Identifier); if (location != null && location.Count > 0) newConstructor.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LPar), Roles.LPar); AddParameter(newConstructor, c.ParameterInfo); if (location != null && location.Count > 1) newConstructor.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.RPar), Roles.RPar); if (c.Initializer != null) { var initializer = new ConstructorInitializer(); initializer.ConstructorInitializerType = c.Initializer is ConstructorBaseInitializer ? ConstructorInitializerType.Base : ConstructorInitializerType.This; var initializerLocation = LocationsBag.GetLocations(c.Initializer); if (initializerLocation != null) newConstructor.AddChild(new CSharpTokenNode(Convert(initializerLocation [0]), Roles.Colon), Roles.Colon); if (initializerLocation != null && initializerLocation.Count > 1) { // this and base has the same length var r = initializer.ConstructorInitializerType == ConstructorInitializerType.This ? ConstructorInitializer.ThisKeywordRole : ConstructorInitializer.BaseKeywordRole; initializer.AddChild(new CSharpTokenNode(Convert(c.Initializer.Location), r), r); initializer.AddChild(new CSharpTokenNode(Convert(initializerLocation [1]), Roles.LPar), Roles.LPar); AddArguments(initializer, c.Initializer.Arguments); initializer.AddChild(new CSharpTokenNode(Convert(initializerLocation [2]), Roles.RPar), Roles.RPar); newConstructor.AddChild(initializer, ConstructorDeclaration.InitializerRole); } } if (c.Block != null) newConstructor.AddChild((BlockStatement)c.Block.Accept(this), Roles.Body); typeStack.Peek().AddChild(newConstructor, Roles.TypeMemberRole); }
public override void Visit (Constructor c) { ConstructorDeclaration newConstructor = new ConstructorDeclaration (); AddAttributeSection (newConstructor, c); var location = LocationsBag.GetMemberLocation (c); AddModifiers (newConstructor, location); newConstructor.AddChild (Identifier.Create (c.MemberName.Name, Convert (c.MemberName.Location)), AstNode.Roles.Identifier); if (location != null) newConstructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar); AddParameter (newConstructor, c.ParameterInfo); if (location != null) newConstructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar); if (c.Initializer != null) { var initializer = new ConstructorInitializer (); initializer.ConstructorInitializerType = c.Initializer is ConstructorBaseInitializer ? ConstructorInitializerType.Base : ConstructorInitializerType.This; var initializerLocation = LocationsBag.GetLocations (c.Initializer); if (initializerLocation != null) newConstructor.AddChild (new CSharpTokenNode (Convert (initializerLocation[0]), 1), ConstructorDeclaration.Roles.Colon); // this and base has the same length initializer.AddChild (new CSharpTokenNode (Convert (c.Initializer.Location), "this".Length), ConstructorDeclaration.Roles.Keyword); if (initializerLocation != null) initializer.AddChild (new CSharpTokenNode (Convert (initializerLocation[1]), 1), ConstructorDeclaration.Roles.LPar); AddArguments (initializer, LocationsBag.GetLocations (c.Initializer.Arguments), c.Initializer.Arguments); if (initializerLocation != null) initializer.AddChild (new CSharpTokenNode (Convert (initializerLocation[2]), 1), ConstructorDeclaration.Roles.RPar); newConstructor.AddChild (initializer, ConstructorDeclaration.InitializerRole); } if (c.Block != null) newConstructor.AddChild ((BlockStatement)c.Block.Accept (this), ConstructorDeclaration.Roles.Body); typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.MemberRole); }