Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Ast/Expressions/IsExpression.cs @ 17578

Last change on this file since 17578 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 4.6 KB
Line 
1//
2// TypeOfIsExpression.cs
3//
4// Author:
5//       Mike Krüger <mkrueger@novell.com>
6//
7// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
8//
9// Permission is hereby granted, free of charge, to any person obtaining a copy
10// of this software and associated documentation files (the "Software"), to deal
11// in the Software without restriction, including without limitation the rights
12// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13// copies of the Software, and to permit persons to whom the Software is
14// furnished to do so, subject to the following conditions:
15//
16// The above copyright notice and this permission notice shall be included in
17// all copies or substantial portions of the Software.
18//
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25// THE SOFTWARE.
26using System.Collections.Generic;
27
28namespace ICSharpCode.NRefactory.CSharp
29{
30  /// <summary>
31  /// Expression is Type
32  /// </summary>
33  public class IsExpression : Expression
34  {
35    public readonly static TokenRole IsKeywordRole = new TokenRole ("is");
36   
37    public Expression Expression {
38      get { return GetChildByRole(Roles.Expression); }
39      set { SetChildByRole(Roles.Expression, value); }
40    }
41   
42    public CSharpTokenNode IsToken {
43      get { return GetChildByRole (IsKeywordRole); }
44    }
45   
46    public AstType Type {
47      get { return GetChildByRole(Roles.Type); }
48      set { SetChildByRole(Roles.Type, value); }
49    }
50
51    public IsExpression()
52    {
53    }
54
55    public IsExpression (Expression expression, AstType type)
56    {
57      AddChild (expression, Roles.Expression);
58      AddChild (type, Roles.Type);
59    }
60
61   
62    public override void AcceptVisitor (IAstVisitor visitor)
63    {
64      visitor.VisitIsExpression (this);
65    }
66     
67    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
68    {
69      return visitor.VisitIsExpression (this);
70    }
71   
72    public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
73    {
74      return visitor.VisitIsExpression (this, data);
75    }
76   
77    protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
78    {
79      IsExpression o = other as IsExpression;
80      return o != null && this.Expression.DoMatch(o.Expression, match) && this.Type.DoMatch(o.Type, match);
81    }
82
83    #region Builder methods
84    public override MemberReferenceExpression Member(string memberName)
85    {
86      return new MemberReferenceExpression { Target = this, MemberName = memberName };
87    }
88
89    public override IndexerExpression Indexer(IEnumerable<Expression> arguments)
90    {
91      IndexerExpression expr = new IndexerExpression();
92      expr.Target = new ParenthesizedExpression(this);
93      expr.Arguments.AddRange(arguments);
94      return expr;
95    }
96
97    public override IndexerExpression Indexer(params Expression[] arguments)
98    {
99      IndexerExpression expr = new IndexerExpression();
100      expr.Target = new ParenthesizedExpression(this);
101      expr.Arguments.AddRange(arguments);
102      return expr;
103    }
104
105    public override InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments)
106    {
107      InvocationExpression ie = new InvocationExpression();
108      MemberReferenceExpression mre = new MemberReferenceExpression();
109      mre.Target = new ParenthesizedExpression(this);
110      mre.MemberName = methodName;
111      mre.TypeArguments.AddRange(typeArguments);
112      ie.Target = mre;
113      ie.Arguments.AddRange(arguments);
114      return ie;
115    }
116
117    public override InvocationExpression Invoke(IEnumerable<Expression> arguments)
118    {
119      InvocationExpression ie = new InvocationExpression();
120      ie.Target = new ParenthesizedExpression(this);
121      ie.Arguments.AddRange(arguments);
122      return ie;
123    }
124
125    public override InvocationExpression Invoke(params Expression[] arguments)
126    {
127      InvocationExpression ie = new InvocationExpression();
128      ie.Target = new ParenthesizedExpression(this);
129      ie.Arguments.AddRange(arguments);
130      return ie;
131    }
132
133    public override CastExpression CastTo(AstType type)
134    {
135      return new CastExpression { Type = type,  Expression = new ParenthesizedExpression(this) };
136    }
137
138    public override AsExpression CastAs(AstType type)
139    {
140      return new AsExpression { Type = type,  Expression = new ParenthesizedExpression(this) };
141    }
142
143    public override IsExpression IsType(AstType type)
144    {
145      return new IsExpression { Type = type,  Expression = new ParenthesizedExpression(this) };
146    }
147    #endregion
148  }
149}
150
Note: See TracBrowser for help on using the repository browser.