From 904b05fe5e0e0f3db3e7f0a1ac854e2f6c492976 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 18 Feb 2011 21:38:16 +0100 Subject: [PATCH 1/2] NRefactory: remove collection setters from AST; expose AstNodeCollection instead. --- ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs | 31 +--- .../CSharp/Ast/AstNodeCollection.cs | 156 ++++++++++++++++++ .../CSharp/Ast/ComposedType.cs | 3 +- .../Expressions/AnonymousMethodExpression.cs | 5 +- .../Ast/Expressions/ArgListExpression.cs | 5 +- .../Ast/Expressions/ArrayCreateExpression.cs | 6 +- .../Expressions/ArrayInitializerExpression.cs | 5 +- .../CSharp/Ast/Expressions/Expression.cs | 39 +++-- .../Ast/Expressions/IdentifierExpression.cs | 5 +- .../Ast/Expressions/IndexerExpression.cs | 5 +- .../Ast/Expressions/InvocationExpression.cs | 5 +- .../Ast/Expressions/LambdaExpression.cs | 5 +- .../Expressions/MemberReferenceExpression.cs | 5 +- .../Ast/Expressions/ObjectCreateExpression.cs | 5 +- .../Expressions/PointerReferenceExpression.cs | 5 +- .../CSharp/Ast/Expressions/QueryExpression.cs | 6 +- .../CSharp/Ast/GeneralScope/Attribute.cs | 5 +- .../Ast/GeneralScope/AttributeSection.cs | 5 +- .../CSharp/Ast/GeneralScope/Constraint.cs | 5 +- .../Ast/GeneralScope/DelegateDeclaration.cs | 11 +- .../Ast/GeneralScope/NamespaceDeclaration.cs | 10 +- .../Ast/GeneralScope/TypeDeclaration.cs | 14 +- .../CSharp/Ast/MemberType.cs | 5 +- .../CSharp/Ast/SimpleType.cs | 5 +- .../CSharp/Ast/Statements/BlockStatement.cs | 5 +- .../CSharp/Ast/Statements/FixedStatement.cs | 5 +- .../CSharp/Ast/Statements/ForStatement.cs | 8 +- .../CSharp/Ast/Statements/SwitchStatement.cs | 11 +- .../Ast/Statements/TryCatchStatement.cs | 5 +- .../VariableDeclarationStatement.cs | 15 +- .../CSharp/Ast/TypeMembers/AttributedNode.cs | 3 +- .../Ast/TypeMembers/ConstructorDeclaration.cs | 8 +- .../Ast/TypeMembers/EventDeclaration.cs | 5 +- .../Ast/TypeMembers/FieldDeclaration.cs | 5 +- .../Ast/TypeMembers/IndexerDeclaration.cs | 5 +- .../Ast/TypeMembers/MethodDeclaration.cs | 11 +- .../Ast/TypeMembers/OperatorDeclaration.cs | 5 +- .../Ast/TypeMembers/ParameterDeclaration.cs | 5 +- .../CSharp/Parser/CSharpParser.cs | 4 +- .../ICSharpCode.NRefactory.csproj | 3 +- 40 files changed, 277 insertions(+), 177 deletions(-) create mode 100644 ICSharpCode.NRefactory/CSharp/Ast/AstNodeCollection.cs diff --git a/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs b/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs index 5a81449d20..bfafd16330 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs @@ -1,4 +1,4 @@ -// +// // AstNode.cs // // Author: @@ -164,16 +164,9 @@ namespace ICSharpCode.NRefactory.CSharp return role.NullObject; } - public IEnumerable GetChildrenByRole(Role role) where T : AstNode + public AstNodeCollection GetChildrenByRole(Role role) where T : AstNode { - AstNode next; - for (AstNode cur = firstChild; cur != null; cur = next) { - // Remember next before yielding cur. - // This allows removing/replacing nodes while iterating through the list. - next = cur.nextSibling; - if (cur.role == role) - yield return (T)cur; - } + return new AstNodeCollection(this, role); } protected void SetChildByRole(Role role, T newChild) where T : AstNode @@ -185,24 +178,6 @@ namespace ICSharpCode.NRefactory.CSharp oldChild.ReplaceWith(newChild); } - protected void SetChildrenByRole(Role role, IEnumerable newChildren) where T : AstNode - { - // Evaluate 'newChildren' first, since it might change when we remove the old children - // Example: SetChildren(role, GetChildrenByRole(role)); - if (newChildren != null) - newChildren = newChildren.ToList(); - - // remove old children - foreach (AstNode node in GetChildrenByRole(role)) - node.Remove(); - // add new children - if (newChildren != null) { - foreach (T node in newChildren) { - AddChild(node, role); - } - } - } - public void AddChild(T child, Role role) where T : AstNode { if (role == null) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/AstNodeCollection.cs b/ICSharpCode.NRefactory/CSharp/Ast/AstNodeCollection.cs new file mode 100644 index 0000000000..89556dca8f --- /dev/null +++ b/ICSharpCode.NRefactory/CSharp/Ast/AstNodeCollection.cs @@ -0,0 +1,156 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under MIT X11 license (for details please see \doc\license.txt) + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace ICSharpCode.NRefactory.CSharp +{ + /// + /// Represents the children of an AstNode that have a specific role. + /// + public struct AstNodeCollection : ICollection where T : AstNode + { + readonly AstNode node; + readonly Role role; + + public AstNodeCollection(AstNode node, Role role) + { + if (node == null) + throw new ArgumentNullException("node"); + if (role == null) + throw new ArgumentNullException("role"); + this.node = node; + this.role = role; + } + + public int Count { + get { + var e = GetEnumerator(); + int count = 0; + while (e.MoveNext()) + count++; + return count; + } + } + + public void Add(T element) + { + node.AddChild(element, role); + } + + public void AddRange(IEnumerable nodes) + { + // Evaluate 'nodes' first, since it might change when we add the new children + // Example: collection.AddRange(collection); + if (nodes != null) { + foreach (T node in nodes.ToList()) + Add(node); + } + } + + public void AddRange(T[] nodes) + { + // Fast overload for arrays - we don't need to create a copy + if (nodes != null) { + foreach (T node in nodes) + Add(node); + } + } + + public void ReplaceWith(IEnumerable nodes) + { + // Evaluate 'nodes' first, since it might change when we call Clear() + // Example: collection.ReplaceWith(collection); + if (nodes != null) + nodes = nodes.ToList(); + Clear(); + foreach (T node in nodes) + Add(node); + } + + public void MoveTo(ICollection targetCollection) + { + foreach (T node in this) { + node.Remove(); + targetCollection.Add(node); + } + } + + public bool Contains(T element) + { + return element != null && element.Parent == node && element.Role == role; + } + + public bool Remove(T element) + { + if (Contains(element)) { + element.Remove(); + return true; + } else { + return false; + } + } + + public void CopyTo(T[] array, int arrayIndex) + { + foreach (T item in this) + array[arrayIndex++] = item; + } + + public void Clear() + { + foreach (T item in this) + item.Remove(); + } + + bool ICollection.IsReadOnly { + get { return false; } + } + + public IEnumerator GetEnumerator() + { + AstNode next; + for (AstNode cur = node.FirstChild; cur != null; cur = next) { + // Remember next before yielding cur. + // This allows removing/replacing nodes while iterating through the list. + next = cur.NextSibling; + if (cur.Role == role) + yield return (T)cur; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + #region Equals and GetHashCode implementation + public override bool Equals(object obj) + { + if (obj is AstNodeCollection) { + return ((AstNodeCollection)obj) == this; + } else { + return false; + } + } + + public override int GetHashCode() + { + return node.GetHashCode() ^ role.GetHashCode(); + } + + public static bool operator ==(AstNodeCollection left, AstNodeCollection right) + { + return left.role == right.role && left.node == right.node; + } + + public static bool operator !=(AstNodeCollection left, AstNodeCollection right) + { + return !(left.role == right.role && left.node == right.node); + } + #endregion + } +} diff --git a/ICSharpCode.NRefactory/CSharp/Ast/ComposedType.cs b/ICSharpCode.NRefactory/CSharp/Ast/ComposedType.cs index 0a22debe12..e4316de30a 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/ComposedType.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/ComposedType.cs @@ -67,9 +67,8 @@ namespace ICSharpCode.NRefactory.CSharp } } - public IEnumerable ArraySpecifiers { + public AstNodeCollection ArraySpecifiers { get { return GetChildrenByRole (ArraySpecifierRole); } - set { SetChildrenByRole (ArraySpecifierRole, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs index 10d497eda9..324bbff885 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs @@ -1,4 +1,4 @@ -// +// // AnonymousMethodExpression.cs // // Author: @@ -47,9 +47,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LPar); } } - public IEnumerable Parameters { + public AstNodeCollection Parameters { get { return GetChildrenByRole (Roles.Parameter); } - set { SetChildrenByRole (Roles.Parameter, value); } } public CSharpTokenNode RParToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArgListExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArgListExpression.cs index 533bf2fb85..d18d543f18 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArgListExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArgListExpression.cs @@ -1,4 +1,4 @@ -// +// // ArgListExpression.cs // // Author: @@ -45,9 +45,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LPar); } } - public IEnumerable Arguments { + public AstNodeCollection Arguments { get { return GetChildrenByRole(Roles.Argument); } - set { SetChildrenByRole(Roles.Argument, value); } } public CSharpTokenNode RParToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs index 7befd673e9..e4122170e5 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs @@ -16,18 +16,16 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Type, value); } } - public IEnumerable Arguments { + public AstNodeCollection Arguments { get { return GetChildrenByRole (Roles.Argument); } - set { SetChildrenByRole (Roles.Argument, value); } } /// /// Gets additional array ranks (those without size info). /// Empty for "new int[5,1]"; will contain a single element for "new int[5][]". /// - public IEnumerable AdditionalArraySpecifiers { + public AstNodeCollection AdditionalArraySpecifiers { get { return GetChildrenByRole(AdditionalArraySpecifierRole); } - set { SetChildrenByRole (AdditionalArraySpecifierRole, value); } } public ArrayInitializerExpression Initializer { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayInitializerExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayInitializerExpression.cs index 8f897048ca..a654ecff7b 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayInitializerExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayInitializerExpression.cs @@ -1,4 +1,4 @@ -// +// // ArrayInitializerExpression.cs // // Author: @@ -55,9 +55,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LBrace); } } - public IEnumerable Elements { + public AstNodeCollection Elements { get { return GetChildrenByRole(Roles.Expression); } - set { SetChildrenByRole(Roles.Expression, value); } } public CSharpTokenNode RBraceToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs index 6a6e3d9a3c..b82530464b 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs @@ -66,7 +66,10 @@ namespace ICSharpCode.NRefactory.CSharp /// public IndexerExpression Indexer(IEnumerable arguments) { - return new IndexerExpression { Target = this, Arguments = arguments }; + IndexerExpression expr = new IndexerExpression(); + expr.Target = this; + expr.Arguments.AddRange(arguments); + return expr; } /// @@ -74,7 +77,10 @@ namespace ICSharpCode.NRefactory.CSharp /// public IndexerExpression Indexer(params Expression[] arguments) { - return new IndexerExpression { Target = this, Arguments = arguments }; + IndexerExpression expr = new IndexerExpression(); + expr.Target = this; + expr.Arguments.AddRange(arguments); + return expr; } /// @@ -98,14 +104,14 @@ namespace ICSharpCode.NRefactory.CSharp /// public InvocationExpression Invoke(string methodName, IEnumerable typeArguments, IEnumerable arguments) { - return new InvocationExpression { - Target = new MemberReferenceExpression { - Target = this, - MemberName = methodName, - TypeArguments = typeArguments - }, - Arguments = arguments - }; + InvocationExpression ie = new InvocationExpression(); + MemberReferenceExpression mre = new MemberReferenceExpression(); + mre.Target = this; + mre.MemberName = methodName; + mre.TypeArguments.AddRange(typeArguments); + ie.Target = mre; + ie.Arguments.AddRange(arguments); + return ie; } /// @@ -113,10 +119,10 @@ namespace ICSharpCode.NRefactory.CSharp /// public InvocationExpression Invoke(IEnumerable arguments) { - return new InvocationExpression { - Target = this, - Arguments = arguments - }; + InvocationExpression ie = new InvocationExpression(); + ie.Target = this; + ie.Arguments.AddRange(arguments); + return ie; } /// @@ -124,7 +130,10 @@ namespace ICSharpCode.NRefactory.CSharp /// public InvocationExpression Invoke(params Expression[] arguments) { - return Invoke(arguments.AsEnumerable()); + InvocationExpression ie = new InvocationExpression(); + ie.Target = this; + ie.Arguments.AddRange(arguments); + return ie; } public CastExpression CastTo(AstType type) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IdentifierExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IdentifierExpression.cs index c56b9e5640..fce5f9c808 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IdentifierExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IdentifierExpression.cs @@ -1,4 +1,4 @@ -// +// // IdentifierExpression.cs // // Author: @@ -56,9 +56,8 @@ namespace ICSharpCode.NRefactory.CSharp } } - public IEnumerable TypeArguments { + public AstNodeCollection TypeArguments { get { return GetChildrenByRole (Roles.TypeArgument); } - set { SetChildrenByRole (Roles.TypeArgument, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs index 71a8517f35..a5950bb0d6 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs @@ -1,4 +1,4 @@ -// +// // IndexerExpression.cs // // Author: @@ -42,9 +42,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LBracket); } } - public IEnumerable Arguments { + public AstNodeCollection Arguments { get { return GetChildrenByRole(Roles.Argument); } - set { SetChildrenByRole(Roles.Argument, value); } } public CSharpTokenNode RBracketToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs index 9efe86284c..7b69440dd2 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs @@ -1,4 +1,4 @@ -// +// // InvocationExpression.cs // // Author: @@ -42,9 +42,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LPar); } } - public IEnumerable Arguments { + public AstNodeCollection Arguments { get { return GetChildrenByRole(Roles.Argument); } - set { SetChildrenByRole(Roles.Argument, value); } } public CSharpTokenNode RParToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/LambdaExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/LambdaExpression.cs index 06baa857c3..dff50f074e 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/LambdaExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/LambdaExpression.cs @@ -1,4 +1,4 @@ -// +// // LambdaExpression.cs // // Author: @@ -36,9 +36,8 @@ namespace ICSharpCode.NRefactory.CSharp public readonly static Role ArrowRole = new Role("Arrow", CSharpTokenNode.Null); public static readonly Role BodyRole = new Role("Body", AstNode.Null); - public IEnumerable Parameters { + public AstNodeCollection Parameters { get { return GetChildrenByRole (Roles.Parameter); } - set { SetChildrenByRole (Roles.Parameter, value); } } public CSharpTokenNode ArrowToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs index c20d2ce071..43fa24714e 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs @@ -1,4 +1,4 @@ -// +// // MemberReferenceExpression.cs // // Author: @@ -51,9 +51,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LChevron); } } - public IEnumerable TypeArguments { + public AstNodeCollection TypeArguments { get { return GetChildrenByRole (Roles.TypeArgument); } - set { SetChildrenByRole (Roles.TypeArgument, value); } } public CSharpTokenNode RChevronToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs index efccad91ad..9b935ce48a 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs @@ -1,4 +1,4 @@ -// +// // ObjectCreateExpression.cs // // Author: @@ -48,9 +48,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LPar); } } - public IEnumerable Arguments { + public AstNodeCollection Arguments { get { return GetChildrenByRole (Roles.Argument); } - set { SetChildrenByRole (Roles.Argument, value); } } public CSharpTokenNode RParToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PointerReferenceExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PointerReferenceExpression.cs index 17bd5b72c7..e1ee936696 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PointerReferenceExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/PointerReferenceExpression.cs @@ -1,4 +1,4 @@ -// +// // PointerReferenceExpression.cs // // Author: @@ -49,9 +49,8 @@ namespace ICSharpCode.NRefactory.CSharp } } - public IEnumerable TypeArguments { + public AstNodeCollection TypeArguments { get { return GetChildrenByRole (Roles.TypeArgument); } - set { SetChildrenByRole (Roles.TypeArgument, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs index d71be3d8d8..b7f01a473a 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs @@ -28,9 +28,8 @@ namespace ICSharpCode.NRefactory.CSharp } #endregion - public IEnumerable Clauses { + public AstNodeCollection Clauses { get { return GetChildrenByRole(ClauseRole); } - set { SetChildrenByRole(ClauseRole, value); } } public override S AcceptVisitor(IAstVisitor visitor, T data) @@ -260,9 +259,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.Keyword); } } - public IEnumerable Orderings { + public AstNodeCollection Orderings { get { return GetChildrenByRole (OrderingRole); } - set { SetChildrenByRole (OrderingRole, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs index 162a4e33bc..5c08c14912 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs @@ -1,4 +1,4 @@ -// +// // Attribute.cs // // Author: @@ -44,9 +44,8 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Type, value); } } - public IEnumerable Arguments { + public AstNodeCollection Arguments { get { return base.GetChildrenByRole (Roles.Argument); } - set { SetChildrenByRole (Roles.Argument, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs index 35d170dda2..17c5e2f7f6 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs @@ -1,4 +1,4 @@ -// +// // AttributeSection.cs // // Author: @@ -49,9 +49,8 @@ namespace ICSharpCode.NRefactory.CSharp set; } - public IEnumerable Attributes { + public AstNodeCollection Attributes { get { return base.GetChildrenByRole (AttributeRole); } - set { SetChildrenByRole (AttributeRole, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs index dae8d4e193..a2de49fffb 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs @@ -1,4 +1,4 @@ -// +// // Constraint.cs // // Author: @@ -53,9 +53,8 @@ namespace ICSharpCode.NRefactory.CSharp // TODO: what about new(), struct and class constraints? - public IEnumerable BaseTypes { + public AstNodeCollection BaseTypes { get { return GetChildrenByRole (BaseTypeRole); } - set { SetChildrenByRole (BaseTypeRole, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs index 1b71cd4c6e..eccac93825 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs @@ -1,4 +1,4 @@ -// +// // DelegateDeclaration.cs // // Author: @@ -54,27 +54,24 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Type, value); } } - public IEnumerable TypeParameters { + public AstNodeCollection TypeParameters { get { return GetChildrenByRole (Roles.TypeParameter); } - set { SetChildrenByRole (Roles.TypeParameter, value); } } public CSharpTokenNode LParToken { get { return GetChildByRole (Roles.LPar); } } - public IEnumerable Parameters { + public AstNodeCollection Parameters { get { return GetChildrenByRole (Roles.Parameter); } - set { SetChildrenByRole (Roles.Parameter, value); } } public CSharpTokenNode RParToken { get { return GetChildByRole (Roles.RPar); } } - public IEnumerable Constraints { + public AstNodeCollection Constraints { get { return GetChildrenByRole (Roles.Constraint); } - set { SetChildrenByRole (Roles.Constraint, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs index f082150b66..8111b5c3dd 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs @@ -1,4 +1,4 @@ -// +// // NamespaceDeclaration.cs // // Author: @@ -54,13 +54,12 @@ namespace ICSharpCode.NRefactory.CSharp return builder.ToString (); } set { - SetChildrenByRole (Roles.Identifier, value.Split('.').Select(ident => new Identifier(ident, AstLocation.Empty))); + GetChildrenByRole(Roles.Identifier).ReplaceWith(value.Split('.').Select(ident => new Identifier(ident, AstLocation.Empty))); } } - public IEnumerable Identifiers { + public AstNodeCollection Identifiers { get { return GetChildrenByRole (Roles.Identifier); } - set { SetChildrenByRole (Roles.Identifier, value); } } /// @@ -79,9 +78,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LBrace); } } - public IEnumerable Members { + public AstNodeCollection Members { get { return GetChildrenByRole(MemberRole); } - set { SetChildrenByRole(MemberRole, value); } } public CSharpTokenNode RBraceToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs index 36381aafd2..fd638f2da9 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs @@ -1,4 +1,4 @@ -// +// // TypeDeclaration.cs // // Author: @@ -59,28 +59,24 @@ namespace ICSharpCode.NRefactory.CSharp } } - public IEnumerable TypeParameters { + public AstNodeCollection TypeParameters { get { return GetChildrenByRole (Roles.TypeParameter); } - set { SetChildrenByRole (Roles.TypeParameter, value); } } - public IEnumerable BaseTypes { + public AstNodeCollection BaseTypes { get { return GetChildrenByRole (BaseTypeRole); } - set { SetChildrenByRole (BaseTypeRole, value); } } - public IEnumerable Constraints { + public AstNodeCollection Constraints { get { return GetChildrenByRole (Roles.Constraint); } - set { SetChildrenByRole (Roles.Constraint, value); } } public CSharpTokenNode LBraceToken { get { return GetChildByRole (Roles.LBrace); } } - public IEnumerable Members { + public AstNodeCollection Members { get { return GetChildrenByRole (MemberRole); } - set { SetChildrenByRole (MemberRole, value); } } public CSharpTokenNode RBraceToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs b/ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs index 8d600b575b..cf5f1dd8f1 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs @@ -1,4 +1,4 @@ -// +// // FullTypeName.cs // // Author: @@ -51,9 +51,8 @@ namespace ICSharpCode.NRefactory.CSharp } } - public IEnumerable TypeArguments { + public AstNodeCollection TypeArguments { get { return GetChildrenByRole (Roles.TypeArgument); } - set { SetChildrenByRole (Roles.TypeArgument, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs b/ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs index ac3eb02104..ec6db27f16 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs @@ -1,4 +1,4 @@ -// +// // FullTypeName.cs // // Author: @@ -56,9 +56,8 @@ namespace ICSharpCode.NRefactory.CSharp } } - public IEnumerable TypeArguments { + public AstNodeCollection TypeArguments { get { return GetChildrenByRole (Roles.TypeArgument); } - set { SetChildrenByRole (Roles.TypeArgument, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs index eb3a6f9a33..5d02ebea77 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs @@ -1,4 +1,4 @@ -// +// // BlockStatement.cs // // Author: @@ -56,9 +56,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LBrace); } } - public IEnumerable Statements { + public AstNodeCollection Statements { get { return GetChildrenByRole (StatementRole); } - set { SetChildrenByRole (StatementRole, value); } } public CSharpTokenNode RBraceToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs index 5d44b66e08..d500c8dbfa 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs @@ -1,4 +1,4 @@ -// +// // FixedStatement.cs // // Author: @@ -46,9 +46,8 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Type, value); } } - public IEnumerable Variables { + public AstNodeCollection Variables { get { return GetChildrenByRole (Roles.Variable); } - set { SetChildrenByRole (Roles.Variable, value); } } public CSharpTokenNode RParToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForStatement.cs index c667e60861..d50b0d3ff5 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/ForStatement.cs @@ -1,4 +1,4 @@ -// +// // ForStatement.cs // // Author: @@ -49,9 +49,8 @@ namespace ICSharpCode.NRefactory.CSharp /// Note: this contains multiple statements for "for (a = 2, b = 1; a > b; a--)", but contains /// only a single statement for "for (int a = 2, b = 1; a > b; a--)" (a single VariableDeclarationStatement with two variables) /// - public IEnumerable Initializers { + public AstNodeCollection Initializers { get { return GetChildrenByRole (InitializerRole); } - set { SetChildrenByRole (InitializerRole, value); } } public Expression Condition { @@ -59,9 +58,8 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Condition, value); } } - public IEnumerable Iterators { + public AstNodeCollection Iterators { get { return GetChildrenByRole (IteratorRole); } - set { SetChildrenByRole (IteratorRole, value); } } public CSharpTokenNode RParToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs index 99fb7009b6..ed8a9df02a 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs @@ -1,4 +1,4 @@ -// +// // SwitchStatement.cs // // Author: @@ -57,9 +57,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LBrace); } } - public IEnumerable SwitchSections { + public AstNodeCollection SwitchSections { get { return GetChildrenByRole (SwitchSectionRole); } - set { SetChildrenByRole (SwitchSectionRole, value); } } public CSharpTokenNode RBraceToken { @@ -82,14 +81,12 @@ namespace ICSharpCode.NRefactory.CSharp } } - public IEnumerable CaseLabels { + public AstNodeCollection CaseLabels { get { return GetChildrenByRole (CaseLabelRole); } - set { SetChildrenByRole (CaseLabelRole, value); } } - public IEnumerable Statements { + public AstNodeCollection Statements { get { return GetChildrenByRole (Roles.EmbeddedStatement); } - set { SetChildrenByRole (Roles.EmbeddedStatement, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/TryCatchStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/TryCatchStatement.cs index 70f48dd29d..a50662dd4a 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/TryCatchStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/TryCatchStatement.cs @@ -1,4 +1,4 @@ -// +// // TryCatchStatement.cs // // Author: @@ -49,9 +49,8 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (TryBlockRole, value); } } - public IEnumerable CatchClauses { + public AstNodeCollection CatchClauses { get { return GetChildrenByRole (CatchClauseRole); } - set { SetChildrenByRole (CatchClauseRole, value); } } public CSharpTokenNode FinallyToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/VariableDeclarationStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/VariableDeclarationStatement.cs index 7be7b5a330..084ea12bf5 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/VariableDeclarationStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/VariableDeclarationStatement.cs @@ -1,4 +1,4 @@ -// +// // VariableDeclarationStatement.cs // // Author: @@ -33,6 +33,16 @@ namespace ICSharpCode.NRefactory.CSharp { public static readonly Role ModifierRole = AttributedNode.ModifierRole; + public VariableDeclarationStatement() + { + } + + public VariableDeclarationStatement(AstType type, string name, Expression initializer = null) + { + this.Type = type; + this.Variables.Add(new VariableInitializer(name, initializer)); + } + public Modifiers Modifiers { get { return AttributedNode.GetModifiers(this); } set { AttributedNode.SetModifiers(this, value); } @@ -43,9 +53,8 @@ namespace ICSharpCode.NRefactory.CSharp set { SetChildByRole (Roles.Type, value); } } - public IEnumerable Variables { + public AstNodeCollection Variables { get { return GetChildrenByRole (Roles.Variable); } - set { SetChildrenByRole (Roles.Variable, value); } } public CSharpTokenNode SemicolonToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs index a2734ae4fc..1f8db8fce2 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs @@ -11,9 +11,8 @@ namespace ICSharpCode.NRefactory.CSharp public static readonly Role AttributeRole = new Role("Attribute"); public static readonly Role ModifierRole = new Role("Modifier"); - public IEnumerable Attributes { + public AstNodeCollection Attributes { get { return base.GetChildrenByRole (AttributeRole); } - set { SetChildrenByRole (AttributeRole, value); } } public Modifiers Modifiers { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs index 1097605c33..ec81013909 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs @@ -1,4 +1,4 @@ -// +// // ConstructorDeclaration.cs // // Author: @@ -37,9 +37,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LPar); } } - public IEnumerable Parameters { + public AstNodeCollection Parameters { get { return GetChildrenByRole (Roles.Parameter); } - set { SetChildrenByRole (Roles.Parameter, value); } } public CSharpTokenNode RParToken { @@ -105,9 +104,8 @@ namespace ICSharpCode.NRefactory.CSharp set; } - public IEnumerable Arguments { + public AstNodeCollection Arguments { get { return GetChildrenByRole (Roles.Argument); } - set { SetChildrenByRole (Roles.Argument, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs index dde1926632..3a916782d3 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs @@ -1,4 +1,4 @@ -// +// // EventDeclaration.cs // // Author: @@ -30,9 +30,8 @@ namespace ICSharpCode.NRefactory.CSharp { public class EventDeclaration : MemberDeclaration { - public IEnumerable Variables { + public AstNodeCollection Variables { get { return GetChildrenByRole (Roles.Variable); } - set { SetChildrenByRole (Roles.Variable, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs index 8969d50b05..3ca04772df 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs @@ -1,4 +1,4 @@ -// +// // FieldDeclaration.cs // // Author: @@ -31,9 +31,8 @@ namespace ICSharpCode.NRefactory.CSharp { public class FieldDeclaration : MemberDeclaration { - public IEnumerable Variables { + public AstNodeCollection Variables { get { return GetChildrenByRole (Roles.Variable); } - set { SetChildrenByRole (Roles.Variable, value); } } public override S AcceptVisitor (IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs index 88d80ce50b..5b63c9c4f3 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs @@ -1,4 +1,4 @@ -// +// // IndexerDeclaration.cs // // Author: @@ -35,9 +35,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LBracket); } } - public IEnumerable Parameters { + public AstNodeCollection Parameters { get { return GetChildrenByRole (Roles.Parameter); } - set { SetChildrenByRole (Roles.Parameter, value); } } public CSharpTokenNode RBracketToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs index 84ff90819f..ef740bd86b 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs @@ -1,4 +1,4 @@ -// +// // MethodDeclaration.cs // // Author: @@ -31,27 +31,24 @@ namespace ICSharpCode.NRefactory.CSharp { public class MethodDeclaration : MemberDeclaration { - public IEnumerable TypeParameters { + public AstNodeCollection TypeParameters { get { return GetChildrenByRole (Roles.TypeParameter); } - set { SetChildrenByRole (Roles.TypeParameter, value); } } public CSharpTokenNode LParToken { get { return GetChildByRole (Roles.LPar); } } - public IEnumerable Parameters { + public AstNodeCollection Parameters { get { return GetChildrenByRole (Roles.Parameter); } - set { SetChildrenByRole (Roles.Parameter, value); } } public CSharpTokenNode RParToken { get { return GetChildByRole (Roles.RPar); } } - public IEnumerable Constraints { + public AstNodeCollection Constraints { get { return GetChildrenByRole (Roles.Constraint); } - set { SetChildrenByRole (Roles.Constraint, value); } } public BlockStatement Body { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs index 4b3a1693b2..c8a326c497 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs @@ -1,4 +1,4 @@ -// +// // OperatorDeclaration.cs // // Author: @@ -80,9 +80,8 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LPar); } } - public IEnumerable Parameters { + public AstNodeCollection Parameters { get { return GetChildrenByRole (Roles.Parameter); } - set { SetChildrenByRole (Roles.Parameter, value); } } public CSharpTokenNode RParToken { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs index 21c1f644ea..6ae4994e82 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs @@ -1,4 +1,4 @@ -// +// // ParameterDeclarationExpression.cs // // Author: @@ -49,9 +49,8 @@ namespace ICSharpCode.NRefactory.CSharp } } - public IEnumerable Attributes { + public AstNodeCollection Attributes { get { return GetChildrenByRole (AttributeRole); } - set { SetChildrenByRole (AttributeRole, value); } } public ParameterModifier ParameterModifier { diff --git a/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs b/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs index a8cc6acac7..bb447f4c6c 100644 --- a/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs +++ b/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs @@ -122,9 +122,7 @@ namespace ICSharpCode.NRefactory.CSharp if (location != null) spec.AddChild (new CSharpTokenNode (Convert (location[0]), 1), FieldDeclaration.Roles.RBracket); - result.ArraySpecifiers = new ArraySpecifier[] { - spec - }; + result.ArraySpecifiers.Add(spec); } return result; } diff --git a/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj b/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj index 0f23db4854..619f2070e3 100644 --- a/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj +++ b/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj @@ -1,4 +1,4 @@ - + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} @@ -56,6 +56,7 @@ + From 1af927c426a242b227653b101e52389395bd7412 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 18 Feb 2011 22:00:15 +0100 Subject: [PATCH 2/2] Fix lambda expression output bug. --- ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index 88b8b04886..397fe30720 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -675,10 +675,10 @@ namespace ICSharpCode.NRefactory.CSharp bool LambdaNeedsParenthesis(LambdaExpression lambdaExpression) { - if (lambdaExpression.Parameters.Count() != 1) + if (lambdaExpression.Parameters.Count != 1) return true; var p = lambdaExpression.Parameters.Single(); - return p.Type.IsNull && p.ParameterModifier == ParameterModifier.None; + return !(p.Type.IsNull && p.ParameterModifier == ParameterModifier.None); } public object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)