From b51f5a651f9ed55e7222fd3708bf7519f62955b9 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 28 Feb 2011 14:14:29 +0100 Subject: [PATCH] Add pattern matching for MemberDeclarations. --- ICSharpCode.NRefactory/CSharp/Ast/AstType.cs | 2 +- .../Ast/Expressions/ArrayCreateExpression.cs | 2 +- .../CSharp/Ast/GeneralScope/Constraint.cs | 5 +-- .../Ast/GeneralScope/DelegateDeclaration.cs | 19 ++++++++--- .../Ast/GeneralScope/TypeDeclaration.cs | 9 +++++ .../CSharp/Ast/Statements/FixedStatement.cs | 2 +- .../CSharp/Ast/TypeMembers/Accessor.cs | 3 +- .../CSharp/Ast/TypeMembers/AttributedNode.cs | 4 +-- .../Ast/TypeMembers/ConstructorDeclaration.cs | 7 ++++ .../Ast/TypeMembers/DestructorDeclaration.cs | 8 ++++- .../Ast/TypeMembers/EnumMemberDeclaration.cs | 11 ++++-- .../Ast/TypeMembers/EventDeclaration.cs | 13 +++++++ .../Ast/TypeMembers/FieldDeclaration.cs | 6 ++++ .../Ast/TypeMembers/IndexerDeclaration.cs | 34 +++++++++++++++++-- .../Ast/TypeMembers/MemberDeclaration.cs | 6 ++++ .../Ast/TypeMembers/MethodDeclaration.cs | 14 ++++++-- .../Ast/TypeMembers/OperatorDeclaration.cs | 11 ++++-- .../Ast/TypeMembers/ParameterDeclaration.cs | 4 ++- .../Ast/TypeMembers/PropertyDeclaration.cs | 11 ++++-- .../CSharp/OutputVisitor/OutputVisitor.cs | 5 ++- .../CSharp/Parser/CSharpParser.cs | 6 ++-- .../CSharp/Parser/TypeSystemConvertVisitor.cs | 21 +++++++----- .../CSharp/Resolver/ResolveVisitor.cs | 8 ++--- 23 files changed, 168 insertions(+), 43 deletions(-) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/AstType.cs b/ICSharpCode.NRefactory/CSharp/Ast/AstType.cs index 08bf473d4b..a35204e3cd 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/AstType.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/AstType.cs @@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp return new ComposedType { BaseType = this }.MakePointerType(); } - public virtual AstType MakeArrayType(int rank) + public virtual AstType MakeArrayType(int rank = 1) { return new ComposedType { BaseType = this }.MakeArrayType(rank); } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs index 6578c58269..dffc3dd3dc 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs @@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ArrayCreateExpression o = other as ArrayCreateExpression; - return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.Initializer.DoMatch(o.Initializer, match); + return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.AdditionalArraySpecifiers.DoMatch(o.AdditionalArraySpecifiers, match) && this.Initializer.DoMatch(o.Initializer, match); } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs index 514a411922..8bac245c76 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs @@ -31,6 +31,9 @@ namespace ICSharpCode.NRefactory.CSharp /// /// where TypeParameter : BaseTypes /// + /// + /// new(), struct and class constraints are represented using a PrimitiveType "new", "struct" or "class" + /// public class Constraint : AstNode { public readonly static Role ColonRole = TypeDeclaration.ColonRole; @@ -51,8 +54,6 @@ namespace ICSharpCode.NRefactory.CSharp } } - // TODO: what about new(), struct and class constraints? - public AstNodeCollection BaseTypes { get { return GetChildrenByRole (BaseTypeRole); } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs index eccac93825..e014a4b3f8 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs @@ -40,6 +40,11 @@ namespace ICSharpCode.NRefactory.CSharp } } + public AstType ReturnType { + get { return GetChildByRole (Roles.Type); } + set { SetChildByRole (Roles.Type, value); } + } + public string Name { get { return GetChildByRole (Roles.Identifier).Name; @@ -49,11 +54,6 @@ namespace ICSharpCode.NRefactory.CSharp } } - public AstType ReturnType { - get { return GetChildByRole (Roles.Type); } - set { SetChildByRole (Roles.Type, value); } - } - public AstNodeCollection TypeParameters { get { return GetChildrenByRole (Roles.TypeParameter); } } @@ -78,5 +78,14 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitDelegateDeclaration (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + DelegateDeclaration o = other as DelegateDeclaration; + return o != null && this.MatchAttributesAndModifiers(o, match) + && this.ReturnType.DoMatch(o.ReturnType, match) && MatchString(this.Name, o.Name) + && this.TypeParameters.DoMatch(o.TypeParameters, match) && this.Parameters.DoMatch(o.Parameters, match) + && this.Constraints.DoMatch(o.Constraints, match); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs index fd638f2da9..df7ac21388 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs @@ -87,5 +87,14 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitTypeDeclaration (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + TypeDeclaration o = other as TypeDeclaration; + return o != null && this.ClassType == o.ClassType && this.MatchAttributesAndModifiers(o, match) + && MatchString(this.Name, o.Name) && this.TypeParameters.DoMatch(o.TypeParameters, match) + && this.BaseTypes.DoMatch(o.BaseTypes, match) && this.Constraints.DoMatch(o.Constraints, match) + && this.Members.DoMatch(o.Members, match); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs index b1b7759f03..9a8efbc9ac 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs @@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.CSharp protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { FixedStatement o = other as FixedStatement; - return o != null && this.Variables.DoMatch(o.Variables, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match); + return o != null && this.Type.DoMatch(o.Type, match) && this.Variables.DoMatch(o.Variables, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match); } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs index 910aec75fb..c12521335f 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs @@ -64,7 +64,8 @@ namespace ICSharpCode.NRefactory.CSharp protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { - throw new NotImplementedException(); + Accessor o = other as Accessor; + return o != null && this.MatchAttributesAndModifiers(o, match) && this.Body.DoMatch(o.Body, match); } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs index 1b878d91ce..41eec380d1 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs @@ -58,9 +58,9 @@ namespace ICSharpCode.NRefactory.CSharp } } - protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.CSharp.PatternMatching.Match match) + protected bool MatchAttributesAndModifiers(AttributedNode o, PatternMatching.Match match) { - throw new NotImplementedException(); + return this.Modifiers == o.Modifiers && this.Attributes.DoMatch(o.Attributes, match); } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs index 97f808051d..79b7c612fb 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs @@ -70,6 +70,13 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitConstructorDeclaration (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ConstructorDeclaration o = other as ConstructorDeclaration; + return o != null && this.MatchAttributesAndModifiers(o, match) && this.Parameters.DoMatch(o.Parameters, match) + && this.Initializer.DoMatch(o.Initializer, match) && this.Body.DoMatch(o.Body, match); + } } public enum ConstructorInitializerType { diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs index 2798d0660c..8a892b275c 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs @@ -1,6 +1,6 @@ // // DestructorDeclaration.cs -// +// // Author: // Mike Krüger // @@ -61,5 +61,11 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitDestructorDeclaration (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + DestructorDeclaration o = other as DestructorDeclaration; + return o != null && this.MatchAttributesAndModifiers(o, match) && this.Body.DoMatch(o.Body, match); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs index 0715898f04..e2784f565a 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs @@ -1,6 +1,6 @@ -// +// // EnumMemberDeclaration.cs -// +// // Author: // Mike Krüger // @@ -53,6 +53,13 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitEnumMemberDeclaration (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + EnumMemberDeclaration o = other as EnumMemberDeclaration; + return o != null && this.MatchAttributesAndModifiers(o, match) + && MatchString(this.Name, o.Name) && this.Initializer.DoMatch(o.Initializer, match); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs index 3a916782d3..33ba01e079 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs @@ -38,6 +38,12 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitEventDeclaration (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + EventDeclaration o = other as EventDeclaration; + return o != null && this.MatchMember(o, match) && this.Variables.DoMatch(o.Variables, match); + } } public class CustomEventDeclaration : MemberDeclaration @@ -67,5 +73,12 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitCustomEventDeclaration (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + CustomEventDeclaration o = other as CustomEventDeclaration; + return o != null && this.MatchMember(o, match) + && this.AddAccessor.DoMatch(o.AddAccessor, match) && this.RemoveAccessor.DoMatch(o.RemoveAccessor, match); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs index 3ca04772df..4aab796134 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs @@ -39,5 +39,11 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitFieldDeclaration (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + FieldDeclaration o = other as FieldDeclaration; + return o != null && this.MatchMember(o, match) && this.Variables.DoMatch(o.Variables, match); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs index 5b63c9c4f3..4d19c97d73 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs @@ -1,6 +1,6 @@ // // IndexerDeclaration.cs -// +// // Author: // Mike Krüger // @@ -29,13 +29,16 @@ using System.Linq; namespace ICSharpCode.NRefactory.CSharp { - public class IndexerDeclaration : PropertyDeclaration + public class IndexerDeclaration : MemberDeclaration { + public static readonly Role GetterRole = PropertyDeclaration.GetterRole; + public static readonly Role SetterRole = PropertyDeclaration.SetterRole; + public CSharpTokenNode LBracketToken { get { return GetChildByRole (Roles.LBracket); } } - public AstNodeCollection Parameters { + public AstNodeCollection Parameters { get { return GetChildrenByRole (Roles.Parameter); } } @@ -43,9 +46,34 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RBracket); } } + public CSharpTokenNode LBraceToken { + get { return GetChildByRole (Roles.LBrace); } + } + + public Accessor Getter { + get { return GetChildByRole(GetterRole); } + set { SetChildByRole(GetterRole, value); } + } + + public Accessor Setter { + get { return GetChildByRole(SetterRole); } + set { SetChildByRole(SetterRole, value); } + } + + public CSharpTokenNode RBraceToken { + get { return GetChildByRole (Roles.RBrace); } + } + public override S AcceptVisitor (IAstVisitor visitor, T data) { return visitor.VisitIndexerDeclaration (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + IndexerDeclaration o = other as IndexerDeclaration; + return o != null && this.MatchMember(o, match) && this.Parameters.DoMatch(o.Parameters, match) + && this.Getter.DoMatch(o.Getter, match) && this.Setter.DoMatch(o.Setter, match); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MemberDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MemberDeclaration.cs index 5cd468cfe8..a7e1b74e46 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MemberDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MemberDeclaration.cs @@ -55,5 +55,11 @@ namespace ICSharpCode.NRefactory.CSharp public override NodeType NodeType { get { return NodeType.Member; } } + + protected bool MatchMember(MemberDeclaration o, PatternMatching.Match match) + { + return MatchAttributesAndModifiers(o, match) && this.ReturnType.DoMatch(o.ReturnType, match) + && this.PrivateImplementationType.DoMatch(o.PrivateImplementationType, match) && MatchString(this.Name, o.Name); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs index ef740bd86b..556c0a3a4c 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs @@ -1,6 +1,6 @@ // // MethodDeclaration.cs -// +// // Author: // Mike Krüger // @@ -39,7 +39,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LPar); } } - public AstNodeCollection Parameters { + public AstNodeCollection Parameters { get { return GetChildrenByRole (Roles.Parameter); } } @@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.RPar); } } - public AstNodeCollection Constraints { + public AstNodeCollection Constraints { get { return GetChildrenByRole (Roles.Constraint); } } @@ -67,5 +67,13 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitMethodDeclaration (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + MethodDeclaration o = other as MethodDeclaration; + return o != null && this.MatchMember(o, match) && this.TypeParameters.DoMatch(o.TypeParameters, match) + && this.Parameters.DoMatch(o.Parameters, match) && this.Constraints.DoMatch(o.Constraints, match) + && this.Body.DoMatch(o.Body, match); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs index c8a326c497..330c489caa 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs @@ -1,6 +1,6 @@ // // OperatorDeclaration.cs -// +// // Author: // Mike Krüger // @@ -80,7 +80,7 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (Roles.LPar); } } - public AstNodeCollection Parameters { + public AstNodeCollection Parameters { get { return GetChildrenByRole (Roles.Parameter); } } @@ -107,5 +107,12 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitOperatorDeclaration (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + OperatorDeclaration o = other as OperatorDeclaration; + return o != null && this.MatchMember(o, match) && this.OperatorType == o.OperatorType + && this.Parameters.DoMatch(o.Parameters, match) && this.Body.DoMatch(o.Body, match); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs index 0334d2a3fb..27b61ccc24 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs @@ -85,7 +85,9 @@ namespace ICSharpCode.NRefactory.CSharp protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { ParameterDeclaration o = other as ParameterDeclaration; - return o != null && this.Attributes.DoMatch(o.Attributes, match) && this.ParameterModifier == o.ParameterModifier && MatchString(this.Name, o.Name) && this.DefaultExpression.DoMatch(o.DefaultExpression, match); + return o != null && this.Attributes.DoMatch(o.Attributes, match) && this.ParameterModifier == o.ParameterModifier + && this.Type.DoMatch(o.Type, match) && MatchString(this.Name, o.Name) + && this.DefaultExpression.DoMatch(o.DefaultExpression, match); } } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/PropertyDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/PropertyDeclaration.cs index d13ce8f5c1..2d1376a0ed 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/PropertyDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/PropertyDeclaration.cs @@ -1,6 +1,6 @@ -// +// // PropertyDeclaration.cs -// +// // Author: // Mike Krüger // @@ -53,5 +53,12 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitPropertyDeclaration (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + PropertyDeclaration o = other as PropertyDeclaration; + return o != null && this.MatchMember(o, match) + && this.Getter.DoMatch(o.Getter, match) && this.Setter.DoMatch(o.Setter, match); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index 1c67668d04..edf056d00a 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -1889,7 +1889,10 @@ namespace ICSharpCode.NRefactory.CSharp { StartNode(memberType); memberType.Target.AcceptVisitor(this, data); - WriteToken(".", MemberType.Roles.Dot); + if (memberType.IsDoubleColon) + WriteToken("::", MemberType.Roles.Dot); + else + WriteToken(".", MemberType.Roles.Dot); WriteIdentifier(memberType.MemberName); WriteTypeArguments(memberType.TypeArguments); return EndNode(memberType); diff --git a/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs b/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs index bb447f4c6c..d006b9af9e 100644 --- a/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs +++ b/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs @@ -2540,7 +2540,7 @@ namespace ICSharpCode.NRefactory.CSharp return EmptyList.Instance; } - public IEnumerable ParseStatements(TextReader reader) + public IEnumerable ParseStatements(TextReader reader) { string code = "void M() { " + reader.ReadToEnd() + "}"; var members = ParseTypeMembers(new StringReader(code)); @@ -2548,10 +2548,10 @@ namespace ICSharpCode.NRefactory.CSharp if (method != null && method.Body != null) return method.Body.Statements; else - return EmptyList.Instance; + return EmptyList.Instance; } - public AstNode ParseTypeReference(TextReader reader) + public AstType ParseTypeReference(TextReader reader) { // TODO: add support for parsing type references throw new NotImplementedException(); diff --git a/ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs b/ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs index 281e3e569c..52bcbff39b 100644 --- a/ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs @@ -395,13 +395,6 @@ namespace ICSharpCode.NRefactory.CSharp public override IEntity VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) { DefaultProperty p = new DefaultProperty(currentTypeDefinition, propertyDeclaration.Name); - HandlePropertyOrIndexer(p, propertyDeclaration); - currentTypeDefinition.Properties.Add(p); - return p; - } - - void HandlePropertyOrIndexer(DefaultProperty p, PropertyDeclaration propertyDeclaration) - { p.Region = MakeRegion(propertyDeclaration); p.BodyRegion = MakeBraceRegion(propertyDeclaration); ApplyModifiers(p, propertyDeclaration.Modifiers); @@ -413,13 +406,25 @@ namespace ICSharpCode.NRefactory.CSharp } p.Getter = ConvertAccessor(propertyDeclaration.Getter, p.Accessibility); p.Setter = ConvertAccessor(propertyDeclaration.Setter, p.Accessibility); + currentTypeDefinition.Properties.Add(p); + return p; } public override IEntity VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) { DefaultProperty p = new DefaultProperty(currentTypeDefinition, "Items"); p.EntityType = EntityType.Indexer; - HandlePropertyOrIndexer(p, indexerDeclaration); + p.Region = MakeRegion(indexerDeclaration); + p.BodyRegion = MakeBraceRegion(indexerDeclaration); + ApplyModifiers(p, indexerDeclaration.Modifiers); + p.ReturnType = ConvertType(indexerDeclaration.ReturnType); + ConvertAttributes(p.Attributes, indexerDeclaration.Attributes); + if (!indexerDeclaration.PrivateImplementationType.IsNull) { + p.Accessibility = Accessibility.None; + p.InterfaceImplementations.Add(ConvertInterfaceImplementation(indexerDeclaration.PrivateImplementationType, p.Name)); + } + p.Getter = ConvertAccessor(indexerDeclaration.Getter, p.Accessibility); + p.Setter = ConvertAccessor(indexerDeclaration.Setter, p.Accessibility); ConvertParameters(p.Parameters, indexerDeclaration.Parameters); currentTypeDefinition.Properties.Add(p); return p; diff --git a/ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs b/ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs index f950a474ee..047a3bfef2 100644 --- a/ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs @@ -309,14 +309,14 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver } // handle properties/indexers - ResolveResult VisitPropertyMember(PropertyDeclaration propertyDeclaration) + ResolveResult VisitPropertyMember(MemberDeclaration propertyOrIndexerDeclaration) { try { if (resolver.CurrentTypeDefinition != null) { - resolver.CurrentMember = resolver.CurrentTypeDefinition.Properties.FirstOrDefault(p => p.Region.IsInside(propertyDeclaration.StartLocation)); + resolver.CurrentMember = resolver.CurrentTypeDefinition.Properties.FirstOrDefault(p => p.Region.IsInside(propertyOrIndexerDeclaration.StartLocation)); } - for (AstNode node = propertyDeclaration.FirstChild; node != null; node = node.NextSibling) { + for (AstNode node = propertyOrIndexerDeclaration.FirstChild; node != null; node = node.NextSibling) { if (node.Role == PropertyDeclaration.SetterRole && resolver.CurrentMember != null) { resolver.PushBlock(); resolver.AddVariable(resolver.CurrentMember.ReturnType, "value"); @@ -1135,7 +1135,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver { throw new NotImplementedException(); } - */ + */ #endregion public override ResolveResult VisitIdentifier(Identifier identifier, object data)