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

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ExtractMethod/VariableLookupVisitor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-07-05 13:00:05 UTC
  • mfrom: (1.2.8 upstream) (1.3.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100705130005-d6hp4k5gcn1xkj8c
Tags: 2.4+dfsg-1ubuntu1
* debian/patches/remove_support_for_moonlight.patch,
  debian/patches/dont_add_moonlight_to_core_addins.patch,
  debian/control:
  + Enable support for Moonlight
* debian/rules:
  + Ensure Moonlight addin isn't shipped in main MonoDevelop package by
    mistake

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
using MonoDevelop.Projects.Dom;
33
33
using MonoDevelop.Projects.Dom.Parser;
34
34
using ICSharpCode.NRefactory;
 
35
using Mono.TextEditor;
35
36
 
36
37
namespace MonoDevelop.Refactoring.ExtractMethod
37
38
{
67
68
                        set;
68
69
                }
69
70
                
 
71
                public DocumentLocation Location {
 
72
                        get;
 
73
                        set;
 
74
                }
 
75
                
70
76
                public VariableDescriptor (string name)
71
77
                {
72
78
                        this.Name = name;
75
81
                
76
82
                public override string ToString ()
77
83
                {
78
 
                        return string.Format ("[VariableDescriptor: Name={0}, GetsChanged={1}, InitialValueUsed={2}, IsDefined={3}, ReturnType={4}]", Name, GetsChanged, InitialValueUsed, IsDefined, ReturnType);
 
84
                        return string.Format("[VariableDescriptor: Name={0}, GetsChanged={1}, InitialValueUsed={2}, GetsAssigned={3}, IsDefined={4}, ReturnType={5}, Location={6}]", Name, GetsChanged, InitialValueUsed, GetsAssigned, IsDefined, ReturnType, Location);
79
85
                }
80
 
                
81
86
        }
82
87
        
83
88
        public class VariableLookupVisitor : AbstractAstVisitor
115
120
                
116
121
                IResolver resolver;
117
122
                DomLocation position;
 
123
                public DomRegion CutRegion {
 
124
                        get;
 
125
                        set;
 
126
                }
118
127
                public VariableLookupVisitor (IResolver resolver, DomLocation position)
119
128
                {
120
129
                        this.resolver = resolver;
142
151
                
143
152
                public override object VisitLocalVariableDeclaration (LocalVariableDeclaration localVariableDeclaration, object data)
144
153
                {
145
 
                        foreach (VariableDeclaration varDecl in localVariableDeclaration.Variables) {
146
 
                                variables[varDecl.Name] = new VariableDescriptor (varDecl.Name) {
147
 
                                        IsDefined = true, 
148
 
                                        ReturnType = ConvertTypeReference (localVariableDeclaration.TypeReference)
149
 
                                };
 
154
                        if (!CutRegion.Contains (localVariableDeclaration.StartLocation.Line - 1, localVariableDeclaration.StartLocation.Column -1)) {
 
155
                                foreach (VariableDeclaration varDecl in localVariableDeclaration.Variables) {
 
156
                                        variables[varDecl.Name] = new VariableDescriptor (varDecl.Name) {
 
157
                                                IsDefined = true, 
 
158
                                                ReturnType = ConvertTypeReference (localVariableDeclaration.TypeReference),
 
159
                                                Location = new DocumentLocation (MemberLocation.Line + localVariableDeclaration.StartLocation.Line - 1, localVariableDeclaration.StartLocation.Column - 1)
 
160
                                        };
 
161
                                }
150
162
                        }
151
163
                        return base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
152
164
                }
168
180
                                // result.ResolvedType == null may be true for namespace names or undeclared variables
169
181
                                if (!result.StaticResolve && !variables.ContainsKey (identifierExpression.Identifier)) {
170
182
                                        variables[identifierExpression.Identifier] = new VariableDescriptor (identifierExpression.Identifier) {
171
 
                                                InitialValueUsed = !valueGetsChanged
 
183
                                                InitialValueUsed = !valueGetsChanged,
 
184
                                                Location = new DocumentLocation (MemberLocation.Line + identifierExpression.StartLocation.Line - 1, identifierExpression.StartLocation.Column - 1)
 
185
 
172
186
                                        };
173
187
                                        variables[identifierExpression.Identifier].ReturnType = result.ResolvedType;
174
188
                                }