Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Ast/Expressions/AsExpression.cs @ 11937

Last change on this file since 11937 was 11700, checked in by jkarder, 9 years ago

#2077: created branch and added first version

File size: 4.7 KB
Line 
1//
2// AsExpression.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;
27using System;
28
29namespace ICSharpCode.NRefactory.CSharp
30{
31  /// <summary>
32  /// Expression as TypeReference
33  /// </summary>
34  public class AsExpression : Expression
35  {
36    public readonly static TokenRole AsKeywordRole = new TokenRole ("as");
37   
38    public Expression Expression {
39      get { return GetChildByRole (Roles.Expression); }
40      set { SetChildByRole(Roles.Expression, value); }
41    }
42   
43    public CSharpTokenNode AsToken {
44      get { return GetChildByRole (AsKeywordRole); }
45    }
46   
47    public AstType Type {
48      get { return GetChildByRole (Roles.Type); }
49      set { SetChildByRole(Roles.Type, value); }
50    }
51   
52    public AsExpression ()
53    {
54    }
55   
56    public AsExpression (Expression expression, AstType type)
57    {
58      AddChild (expression, Roles.Expression);
59      AddChild (type, Roles.Type);
60    }
61
62    public override void AcceptVisitor (IAstVisitor visitor)
63    {
64      visitor.VisitAsExpression (this);
65    }
66     
67    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
68    {
69      return visitor.VisitAsExpression (this);
70    }
71   
72    public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
73    {
74      return visitor.VisitAsExpression (this, data);
75    }
76   
77    protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
78    {
79      AsExpression o = other as AsExpression;
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.