~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.CSharp/Refactoring/BaseRefactoringContext.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
ļ»æ// 
 
2
// BaseRefactoringContext.cs
 
3
//  
 
4
// Author:
 
5
//       Mike KrĆ¼ger <mkrueger@xamarin.com>
 
6
// 
 
7
// Copyright (c) 2012 Xamarin <http://xamarin.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.
 
26
 
 
27
using System;
 
28
using System.Linq;
 
29
using System.Threading;
 
30
using ICSharpCode.NRefactory.CSharp.Resolver;
 
31
using ICSharpCode.NRefactory.CSharp.TypeSystem;
 
32
using ICSharpCode.NRefactory.Semantics;
 
33
using ICSharpCode.NRefactory.TypeSystem;
 
34
using ICSharpCode.NRefactory.TypeSystem.Implementation;
 
35
using ICSharpCode.NRefactory.Editor;
 
36
using System.ComponentModel.Design;
 
37
using ICSharpCode.NRefactory.CSharp.Analysis;
 
38
using ICSharpCode.NRefactory.Utils;
 
39
using System.Collections.Generic;
 
40
 
 
41
namespace ICSharpCode.NRefactory.CSharp.Refactoring
 
42
{
 
43
        public abstract class BaseRefactoringContext : IServiceProvider
 
44
        {
 
45
                readonly CSharpAstResolver resolver;
 
46
                readonly CancellationToken cancellationToken;
 
47
                
 
48
                public virtual bool Supports(Version version)
 
49
                {
 
50
                        return true;
 
51
                }
 
52
 
 
53
                /// <summary>
 
54
                /// Gets a value indicating if 'var' keyword should be used or explicit types.
 
55
                /// </summary>
 
56
                public virtual bool UseExplicitTypes {
 
57
                        get;
 
58
                        set;
 
59
                }
 
60
                
 
61
                public CancellationToken CancellationToken {
 
62
                        get { return cancellationToken; }
 
63
                }
 
64
                
 
65
                public virtual AstNode RootNode {
 
66
                        get {
 
67
                                return resolver.RootNode;
 
68
                        }
 
69
                }
 
70
 
 
71
                public CSharpAstResolver Resolver {
 
72
                        get {
 
73
                                return resolver;
 
74
                        }
 
75
                }
 
76
 
 
77
                public virtual CSharpUnresolvedFile UnresolvedFile {
 
78
                        get {
 
79
                                return resolver.UnresolvedFile;
 
80
                        }
 
81
                }
 
82
 
 
83
                public ICompilation Compilation {
 
84
                        get { return resolver.Compilation; }
 
85
                }
 
86
 
 
87
                public BaseRefactoringContext (ICSharpCode.NRefactory.CSharp.Resolver.CSharpAstResolver resolver, System.Threading.CancellationToken cancellationToken)
 
88
                {
 
89
                        this.resolver = resolver;
 
90
                        this.cancellationToken = cancellationToken;
 
91
                        this.referenceFinder = new LocalReferenceFinder(resolver);
 
92
                }
 
93
 
 
94
 
 
95
                #region Resolving
 
96
                public ResolveResult Resolve (AstNode node)
 
97
                {
 
98
                        return resolver.Resolve (node, cancellationToken);
 
99
                }
 
100
                
 
101
                public CSharpResolver GetResolverStateBefore(AstNode node)
 
102
                {
 
103
                        return resolver.GetResolverStateBefore (node, cancellationToken);
 
104
                }
 
105
                
 
106
                public CSharpResolver GetResolverStateAfter(AstNode node)
 
107
                {
 
108
                        return resolver.GetResolverStateAfter (node, cancellationToken);
 
109
                }
 
110
 
 
111
                public IType ResolveType (AstType type)
 
112
                {
 
113
                        return resolver.Resolve (type, cancellationToken).Type;
 
114
                }
 
115
                
 
116
                public IType GetExpectedType (Expression expression)
 
117
                {
 
118
                        return resolver.GetExpectedType(expression, cancellationToken);
 
119
                }
 
120
                
 
121
                public Conversion GetConversion (Expression expression)
 
122
                {
 
123
                        return resolver.GetConversion(expression, cancellationToken);
 
124
                }
 
125
                
 
126
                public TypeSystemAstBuilder CreateTypeSytemAstBuilder(AstNode node)
 
127
                {
 
128
                        var csResolver = resolver.GetResolverStateBefore(node);
 
129
                        return new TypeSystemAstBuilder(csResolver);
 
130
                }
 
131
                #endregion
 
132
 
 
133
                #region Code Analyzation
 
134
                /// <summary>
 
135
                /// Creates a new definite assignment analysis object with a given root statement.
 
136
                /// </summary>
 
137
                /// <returns>
 
138
                /// The definite assignment analysis object.
 
139
                /// </returns>
 
140
                /// <param name='root'>
 
141
                /// The root statement.
 
142
                /// </param>
 
143
                public DefiniteAssignmentAnalysis CreateDefiniteAssignmentAnalysis (Statement root)
 
144
                {
 
145
                        return new DefiniteAssignmentAnalysis (root, resolver, CancellationToken);
 
146
                }
 
147
 
 
148
                /// <summary>
 
149
                /// Creates a new reachability analysis object with a given statement.
 
150
                /// </summary>
 
151
                /// <param name="statement">
 
152
                /// The statement to start the analysis.
 
153
                /// </param>
 
154
                /// <returns>
 
155
                /// The reachability analysis object.
 
156
                /// </returns>
 
157
                public ReachabilityAnalysis CreateReachabilityAnalysis (Statement statement)
 
158
                {
 
159
                        return ReachabilityAnalysis.Create (statement, resolver, CancellationToken);
 
160
                }
 
161
 
 
162
                /// <summary>
 
163
                /// Parses a composite format string.
 
164
                /// </summary>
 
165
                /// <returns>
 
166
                /// The format string parsing result.
 
167
                /// </returns>
 
168
                public virtual FormatStringParseResult ParseFormatString(string source)
 
169
                {
 
170
                        return new CompositeFormatStringParser().Parse(source);
 
171
                }
 
172
 
 
173
                LocalReferenceFinder referenceFinder;
 
174
 
 
175
                public IList<ReferenceResult> FindReferences(AstNode rootNode, IVariable variable)
 
176
                {
 
177
                        return referenceFinder.FindReferences(rootNode, variable);
 
178
                }
 
179
 
 
180
                #endregion
 
181
 
 
182
                /// <summary>
 
183
                /// Translates the english input string to the context language.
 
184
                /// </summary>
 
185
                /// <returns>
 
186
                /// The translated string.
 
187
                /// </returns>
 
188
                public virtual string TranslateString(string str)
 
189
                {
 
190
                        return str;
 
191
                }
 
192
 
 
193
                #region IServiceProvider implementation
 
194
                IServiceContainer services = new ServiceContainer();
 
195
                
 
196
                /// <summary>
 
197
                /// Gets a service container used to associate services with this context.
 
198
                /// </summary>
 
199
                public IServiceContainer Services {
 
200
                        get { return services; }
 
201
                        protected set { services = value; }
 
202
                }
 
203
                
 
204
                /// <summary>
 
205
                /// Retrieves a service from the refactoring context.
 
206
                /// If the service is not found in the <see cref="Services"/> container.
 
207
                /// </summary>
 
208
                public object GetService(Type serviceType)
 
209
                {
 
210
                        return services.GetService(serviceType);
 
211
                }
 
212
                #endregion
 
213
        }
 
214
        
 
215
}