~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/core/Mono.Debugging/Mono.Debugging.Evaluation/NRefactoryResolverVisitor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-02-02 11:39:59 UTC
  • mfrom: (1.4.4 upstream)
  • mto: (1.5.1 sid)
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: james.westby@ubuntu.com-20100202113959-n3u848nfj35yyd03
* New upstream release
* debian/control:
  + Standards version 3.8.4 (no changes needed)
* debian/patches/remove_support_for_non_debian_functionality.patch,
  debian/patches/remove_support_for_soft_debugger.patch,
  debian/patches/remove_support_for_moonlight.patch,
  debian/rules:
  + Split patch into two pieces, to make it easier to enable either
    SDB or Moonlight support with a rebuild
* debian/monodevelop-moonlight.install,
  debian/monodevelop-debugger-sdb.install,
  debian/control:
  + Create packaging data for the Soft Debugger addin and Moonlight addin -
    and comment them out of debian/control as we can't provide them on
    Debian for now

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// NRefactoryResolverVisitor.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez Gual <lluis@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.
 
26
 
 
27
using System;
 
28
using ICSharpCode.NRefactory.Visitors;
 
29
using Mono.Debugging.Client;
 
30
using System.Collections.Generic;
 
31
using System.Text;
 
32
 
 
33
namespace Mono.Debugging.Evaluation
 
34
{
 
35
        public class NRefactoryResolverVisitor: AbstractAstVisitor
 
36
        {
 
37
                SourceLocation location;
 
38
                DebuggerSession session;
 
39
                string expression;
 
40
                List<Replacement> replacements = new List<Replacement> ();
 
41
                
 
42
                class Replacement
 
43
                {
 
44
                        public int Offset;
 
45
                        public int Length;
 
46
                        public string NewText;
 
47
                }
 
48
 
 
49
                public NRefactoryResolverVisitor (DebuggerSession session, SourceLocation location, string expression)
 
50
                {
 
51
                        this.expression = expression.Replace ("\n","").Replace ("\r","");
 
52
                        this.session = session;
 
53
                        this.location = location;
 
54
                }
 
55
                
 
56
                internal string GetResolvedExpression ()
 
57
                {
 
58
                        if (replacements.Count == 0)
 
59
                                return expression;
 
60
                        
 
61
                        replacements.Sort (delegate (Replacement r1, Replacement r2) { return r1.Offset.CompareTo (r2.Offset); });
 
62
                        StringBuilder sb = new StringBuilder ();
 
63
                        int i = 0;
 
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;
 
68
                        }
 
69
                        Replacement last = replacements [replacements.Count - 1];
 
70
                        sb.Append (expression, last.Offset + last.Length, expression.Length - (last.Offset + last.Length));
 
71
                        
 
72
                        return sb.ToString ();
 
73
                }
 
74
                
 
75
                public override object VisitIdentifierExpression (ICSharpCode.NRefactory.Ast.IdentifierExpression identifierExpression, object data)
 
76
                {
 
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 };
 
81
                                replacements.Add (r);
 
82
                        }
 
83
                        return null;
 
84
                }
 
85
        }
 
86
}
 
87