From 60d4fe9d0f498a362519a82e500e7344c0624185 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 28 Feb 2011 14:19:51 +0100 Subject: [PATCH] Add pattern matching for query expressions. Pattern matching should now work for the complete C# AST. --- .../CSharp/Ast/Expressions/QueryExpression.cs | 59 +++++++++++++++++-- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs index 79a357e87b..3c69103c76 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs @@ -54,12 +54,6 @@ namespace ICSharpCode.NRefactory.CSharp public override NodeType NodeType { get { return NodeType.QueryClause; } } - - protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) - { - QueryClause o = other as QueryClause; - throw new NotImplementedException(); - } } /// @@ -103,6 +97,12 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitQueryContinuationClause (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + QueryContinuationClause o = other as QueryContinuationClause; + return o != null && MatchString(this.Identifier, o.Identifier) && this.PrecedingQuery.DoMatch(o.PrecedingQuery, match); + } } public class QueryFromClause : QueryClause @@ -133,6 +133,13 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitQueryFromClause (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + QueryFromClause o = other as QueryFromClause; + return o != null && this.Type.DoMatch(o.Type, match) && MatchString(this.Identifier, o.Identifier) + && this.Expression.DoMatch(o.Expression, match); + } } public class QueryLetClause : QueryClause @@ -163,6 +170,12 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitQueryLetClause (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + QueryLetClause o = other as QueryLetClause; + return o != null && MatchString(this.Identifier, o.Identifier) && this.Expression.DoMatch(o.Expression, match); + } } @@ -181,6 +194,12 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitQueryWhereClause (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + QueryWhereClause o = other as QueryWhereClause; + return o != null && this.Condition.DoMatch(o.Condition, match); + } } /// @@ -266,6 +285,16 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitQueryJoinClause (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + QueryJoinClause o = other as QueryJoinClause; + return o != null && this.IsGroupJoin == o.IsGroupJoin + && this.Type.DoMatch(o.Type, match) && MatchString(this.JoinIdentifier, o.JoinIdentifier) + && this.InExpression.DoMatch(o.InExpression, match) && this.OnExpression.DoMatch(o.OnExpression, match) + && this.EqualsExpression.DoMatch(o.EqualsExpression, match) + && MatchString(this.IntoIdentifier, o.IntoIdentifier); + } } public class QueryOrderClause : QueryClause @@ -284,6 +313,12 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitQueryOrderClause (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + QueryOrderClause o = other as QueryOrderClause; + return o != null && this.Orderings.DoMatch(o.Orderings, match); + } } public class QueryOrdering : AstNode @@ -340,6 +375,12 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitQuerySelectClause (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + QuerySelectClause o = other as QuerySelectClause; + return o != null && this.Expression.DoMatch(o.Expression, match); + } } public class QueryGroupClause : QueryClause @@ -371,5 +412,11 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitQueryGroupClause (this, data); } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + QueryGroupClause o = other as QueryGroupClause; + return o != null && this.Projection.DoMatch(o.Projection, match) && this.Key.DoMatch(o.Key, match); + } } } \ No newline at end of file