~ubuntu-branches/ubuntu/quantal/monodevelop/quantal

« back to all changes in this revision

Viewing changes to src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpNRefactoryASTProvider.cs

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2011-06-29 06:56:25 UTC
  • mfrom: (1.8.1 upstream) (1.3.11 experimental)
  • Revision ID: james.westby@ubuntu.com-20110629065625-7xx19c4vb95j65pl
Tags: 2.5.92+dfsg-1ubuntu1
* Merge from Debian experimental:
 - Dropped patches & changes to debian/control for Moonlight
   + debian/patches/remove_support_for_moonlight.patch,
   + debian/patches/dont_add_moonlight_to_core_addins.patch,
 - Remaining patches:
   + debian/patches/no_appmenu:

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
using ICSharpCode.NRefactory;
33
33
using System.IO;
34
34
using MonoDevelop.CSharp.Formatting;
 
35
using MonoDevelop.Projects.Policies;
 
36
using MonoDevelop.Ide.Gui.Content;
 
37
using MonoDevelop.Projects.Text;
 
38
using System.Reflection;
 
39
using System.Collections.Generic;
 
40
using MonoDevelop.Ide;
35
41
 
36
42
namespace MonoDevelop.CSharp.Refactoring
37
43
{
50
56
                public string OutputNode (ProjectDom dom, INode node, string indent)
51
57
                {
52
58
                        CSharpOutputVisitor outputVisitor = new CSharpOutputVisitor ();
53
 
                        CSharpFormatter.SetFormatOptions (outputVisitor, dom != null && dom.Project != null ? dom.Project.Policies : null);
54
 
                        int col = CSharpFormatter.GetColumn (indent, 0, 4);
 
59
                        SetFormatOptions (outputVisitor, dom != null && dom.Project != null ? dom.Project.Policies : null);
 
60
                        int col = GetColumn (indent, 0, 4);
55
61
                        outputVisitor.OutputFormatter.IndentationLevel = System.Math.Max (0, col / 4);
56
62
                        node.AcceptVisitor (outputVisitor, null);
57
63
                        return outputVisitor.Text;
58
64
                }
59
65
                
 
66
                static void SetFormatOptions (CSharpOutputVisitor outputVisitor, PolicyContainer policyParent)
 
67
                {
 
68
                        IEnumerable<string> types = DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType);
 
69
                        TextStylePolicy currentPolicy = policyParent != null ? policyParent.Get<TextStylePolicy> (types) : MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<TextStylePolicy> (types);
 
70
                        CSharpFormattingPolicy codePolicy = policyParent != null ? policyParent.Get<CSharpFormattingPolicy> (types) : MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<CSharpFormattingPolicy> (types);
 
71
 
 
72
                        outputVisitor.Options.IndentationChar = currentPolicy.TabsToSpaces ? ' ' : '\t';
 
73
                        outputVisitor.Options.TabSize = currentPolicy.TabWidth;
 
74
                        outputVisitor.Options.IndentSize = currentPolicy.TabWidth;
 
75
 
 
76
                        outputVisitor.Options.EolMarker = TextStylePolicy.GetEolMarker(currentPolicy.EolMarker);
 
77
                        Type optionType = outputVisitor.Options.GetType ();
 
78
 
 
79
                        foreach (var property in typeof (CSharpFormattingPolicy).GetProperties ()) {
 
80
                                PropertyInfo info = optionType.GetProperty (property.Name);
 
81
                                if (info == null) 
 
82
                                        continue;
 
83
                                object val = property.GetValue (codePolicy, null);
 
84
                                object cval = null;
 
85
                                if (info.PropertyType.IsEnum) {
 
86
                                        cval = Enum.Parse (info.PropertyType, val.ToString ());
 
87
                                } else if (info.PropertyType == typeof(bool)) {
 
88
                                        cval = Convert.ToBoolean (val);
 
89
                                } else {
 
90
                                        cval = Convert.ChangeType (val, info.PropertyType);
 
91
                                }
 
92
                                info.SetValue (outputVisitor.Options, cval, null);
 
93
                        }
 
94
                }
 
95
                
 
96
                public static int GetColumn (string wrapper, int i, int tabSize)
 
97
                {
 
98
                        int j = i;
 
99
                        int col = 0;
 
100
                        for (; j < wrapper.Length && (wrapper[j] == ' ' || wrapper[j] == '\t'); j++) {
 
101
                                if (wrapper[j] == ' ') {
 
102
                                        col++;
 
103
                                } else {
 
104
                                        col = GetNextTabstop (col, tabSize);
 
105
                                }
 
106
                        }
 
107
                        return col;
 
108
                }
 
109
                static int GetNextTabstop (int currentColumn, int tabSize)
 
110
                {
 
111
                        int result = currentColumn + tabSize;
 
112
                        return (result / tabSize) * tabSize;
 
113
                }
 
114
                
60
115
                public ICSharpCode.NRefactory.Parser.Errors LastErrors {
61
116
                        get;
62
117
                        private set;