5
// Mike Krüger <mkrueger@xamarin.com>
7
// Copyright (c) 2013 Xamarin Inc. (http://xamarin.com)
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
27
using ICSharpCode.NRefactory.CSharp.Resolver;
28
using MonoDevelop.Ide.Gui;
29
using ICSharpCode.NRefactory.CSharp;
30
using ICSharpCode.NRefactory.CSharp.TypeSystem;
31
using ICSharpCode.NRefactory.TypeSystem;
32
using ICSharpCode.NRefactory.Semantics;
33
using System.Threading.Tasks;
35
namespace MonoDevelop.Refactoring
37
public static class ExtensionMethods
39
class ResolverAnnotation
41
public Task<CSharpAstResolver> Task;
42
public CSharpUnresolvedFile ParsedFile;
46
/// Returns a full C# syntax tree resolver which is shared between semantic highlighting, source analysis and refactoring.
47
/// For code analysis tasks this should be used instead of generating an own resolver. Only exception is if a local resolving is done using a
48
/// resolve navigator.
49
/// Note: The shared resolver is fully resolved.
51
public static Task<CSharpAstResolver> GetSharedResolver (this Document document)
53
var parsedDocument = document.ParsedDocument;
54
if (parsedDocument == null)
57
var unit = parsedDocument.GetAst<SyntaxTree> ();
58
var parsedFile = parsedDocument.ParsedFile as CSharpUnresolvedFile;
59
if (unit == null || parsedFile == null)
62
var resolverAnnotation = document.Annotation<ResolverAnnotation> ();
64
if (resolverAnnotation != null) {
65
if (resolverAnnotation.ParsedFile == parsedFile)
66
return resolverAnnotation.Task;
67
document.RemoveAnnotations<ResolverAnnotation> ();
70
var resolveTask = Task.Factory.StartNew (delegate {
71
var result = new CSharpAstResolver (document.Compilation, unit, parsedFile);
72
result.ApplyNavigator (new ConstantModeResolveVisitorNavigator (ResolveVisitorNavigationMode.Resolve, null));
75
document.AddAnnotation (new ResolverAnnotation {
77
ParsedFile = parsedFile
82
sealed class ConstantModeResolveVisitorNavigator : IResolveVisitorNavigator
84
readonly ResolveVisitorNavigationMode mode;
85
readonly IResolveVisitorNavigator targetForResolveCalls;
87
public ConstantModeResolveVisitorNavigator(ResolveVisitorNavigationMode mode, IResolveVisitorNavigator targetForResolveCalls)
90
this.targetForResolveCalls = targetForResolveCalls;
93
ResolveVisitorNavigationMode IResolveVisitorNavigator.Scan(AstNode node)
98
void IResolveVisitorNavigator.Resolved(AstNode node, ResolveResult result)
100
if (targetForResolveCalls != null)
101
targetForResolveCalls.Resolved(node, result);
104
void IResolveVisitorNavigator.ProcessConversion(Expression expression, ResolveResult result, Conversion conversion, IType targetType)
106
if (targetForResolveCalls != null)
107
targetForResolveCalls.ProcessConversion(expression, result, conversion, targetType);
b'\\ No newline at end of file'