public override AstNode VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) { ThisReferenceExpression thisExpression = new ThisReferenceExpression(); ReturnStatement statement = new ReturnStatement(thisExpression); Role <Statement> role = new Role <Statement>("Statement"); Statement returnStatement = statement.Clone(); constructorDeclaration.Body.Add(statement); constructorDeclaration.AddChild(returnStatement, role); return(base.VisitConstructorDeclaration(constructorDeclaration, data)); }
public override void Visit (Constructor c) { ConstructorDeclaration newConstructor = new ConstructorDeclaration (); var location = LocationsBag.GetMemberLocation (c); AddModifiers (newConstructor, location); newConstructor.AddChild (new Identifier (c.MemberName.Name, Convert (c.MemberName.Location)), AbstractNode.Roles.Identifier); if (location != null) { newConstructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar); newConstructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar); } if (c.Block != null) newConstructor.AddChild ((INode)c.Block.Accept (this), ConstructorDeclaration.Roles.Body); typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.Roles.Member); }
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); }
public override void Visit (Constructor c) { ConstructorDeclaration newConstructor = new ConstructorDeclaration (); var location = LocationsBag.GetMemberLocation (c); AddModifiers (newConstructor, location); newConstructor.AddChild (new Identifier (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) { newConstructor.Initializer = new ConstructorInitializer(); if (c.Initializer is ConstructorBaseInitializer) newConstructor.Initializer.ConstructorInitializerType = ConstructorInitializerType.Base; if (c.Initializer is ConstructorThisInitializer) newConstructor.Initializer.ConstructorInitializerType = ConstructorInitializerType.This; AddArguments(newConstructor.Initializer, location, c.Initializer.Arguments); } if (c.Block != null) newConstructor.AddChild ((BlockStatement)c.Block.Accept (this), ConstructorDeclaration.Roles.Body); typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.MemberRole); }