2
// NRefactoryResolverVisitor.cs
5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.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
28
using ICSharpCode.NRefactory.Visitors;
29
using Mono.Debugging.Client;
30
using System.Collections.Generic;
33
namespace Mono.Debugging.Evaluation
35
public class NRefactoryResolverVisitor: AbstractAstVisitor
37
SourceLocation location;
38
DebuggerSession session;
40
List<Replacement> replacements = new List<Replacement> ();
46
public string NewText;
49
public NRefactoryResolverVisitor (DebuggerSession session, SourceLocation location, string expression)
51
this.expression = expression.Replace ("\n","").Replace ("\r","");
52
this.session = session;
53
this.location = location;
56
internal string GetResolvedExpression ()
58
if (replacements.Count == 0)
61
replacements.Sort (delegate (Replacement r1, Replacement r2) { return r1.Offset.CompareTo (r2.Offset); });
62
StringBuilder sb = new StringBuilder ();
64
foreach (Replacement r in replacements) {
65
sb.Append (expression, i, r.Offset - i);
66
sb.Append (r.NewText);
67
i = r.Offset + r.Length;
69
Replacement last = replacements [replacements.Count - 1];
70
sb.Append (expression, last.Offset + last.Length, expression.Length - (last.Offset + last.Length));
72
return sb.ToString ();
75
public override object VisitIdentifierExpression (ICSharpCode.NRefactory.Ast.IdentifierExpression identifierExpression, object data)
77
string type = session.ResolveIdentifierAsType (identifierExpression.Identifier, location);
78
if (!string.IsNullOrEmpty (type)) {
79
type = "global::" + type;
80
Replacement r = new Replacement () { Offset = identifierExpression.StartLocation.Column - 1, Length=identifierExpression.Identifier.Length, NewText = type };