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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Core/MonoDevelop.Projects.CodeGeneration/BaseRefactorer.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
                        sw.Close ();
89
89
                        
90
90
                        
91
 
                        ICompilationUnit pi = ProjectDomService.Parse (ctx.ParserContext.Project, file, null).CompilationUnit;
 
91
                        ICompilationUnit pi = ProjectDomService.Parse (ctx.ParserContext.Project, file).CompilationUnit;
92
92
                        IList<IType> clss = pi.Types;
93
93
                        if (clss.Count > 0)
94
94
                                return clss [0];
111
111
                        IEditableTextFile buffer = ctx.GetFile (cls.CompilationUnit.FileName);
112
112
                        
113
113
                        int pos = GetNewMemberPosition (buffer, cls, member);
114
 
                        string code = GenerateCodeFromMember (member);
 
114
                        string code = GenerateCodeFromMember (member).Trim ();
115
115
                        
116
116
                        int line, col;
117
117
                        buffer.GetLineColumnFromPosition (pos, out line, out col);
118
118
                        
119
119
                        string indent = GetLineIndent (buffer, cls.Location.Line) + "\t";
120
120
                        code = Indent (code, indent, false);
121
 
//                      code = code.Trim (' ', '\t');
122
 
                        code += "\n";
123
121
                        buffer.InsertText (pos, code);
124
122
                        
125
123
                        return FindGeneratedMember (ctx, buffer, cls, member, line);
170
168
                        StringBuilder generatedString = new StringBuilder ();
171
169
                        bool isFirst = true;
172
170
                        foreach (CodeTypeMember member in members) {
 
171
                                if (generatedString.Length > 0) {
 
172
                                        generatedString.AppendLine ();
 
173
                                }
173
174
                                generatedString.Append (Indent (GenerateCodeFromMember (member), indent, isFirst));
174
 
                                generatedString.AppendLine ();
175
 
                                generatedString.Append (indent);
176
175
                                isFirst = false;
177
176
                        }
 
177
                        
178
178
                        // remove last new line + indent
179
179
                        generatedString.Length -= indent.Length + Environment.NewLine.Length;
180
180
                        // remove indent from last generated code member
698
698
                        file.DeleteText (pos, txt.Length);
699
699
                        file.InsertText (pos, newName);
700
700
                        
701
 
                        ProjectDomService.Parse (ctx.ParserContext.Project, file.Name, null, delegate () { return file.Text; });
 
701
                        ProjectDomService.Parse (ctx.ParserContext.Project, file.Name, delegate () { return file.Text; });
702
702
                        
703
703
                        return true;
704
704
                }
750
750
                        file.DeleteText (pos, txt.Length);
751
751
                        file.InsertText (pos, newName);
752
752
                        
753
 
                        ProjectDomService.Parse (ctx.ParserContext.Project, file.Name, null, delegate () { return file.Text; });
 
753
                        ProjectDomService.Parse (ctx.ParserContext.Project, file.Name, delegate () { return file.Text; });
754
754
                        
755
755
                        return true;
756
756
                }
845
845
                {
846
846
                        // Don't get the class from the parse results because in that class the types are not resolved.
847
847
                        // Get the class from the database instead.
848
 
                        ParsedDocument doc = ProjectDomService.Parse (ctx.ParserContext.Project, buffer.Name, null, delegate () { return buffer.Text; });
 
848
                        ParsedDocument doc = ProjectDomService.Parse (ctx.ParserContext.Project, buffer.Name, delegate () { return buffer.Text; });
849
849
                        IType result = ctx.ParserContext.GetType (cls.FullName, cls.TypeParameters.Count, true, true);
850
850
                        if (result is CompoundType) {
851
851
                                IType hintType = doc.CompilationUnit.GetType (cls.FullName, cls.TypeParameters.Count);
979
979
                
980
980
                protected int EnsurePositionIsNotInRegionsAndIndented (Project p, IEditableTextFile buffer, string indent, int position)
981
981
                {
982
 
                        ParsedDocument doc = ProjectDomService.Parse (p, buffer.Name, null, delegate () { return buffer.Text; });
 
982
                        ParsedDocument doc = ProjectDomService.Parse (p, buffer.Name, delegate () { return buffer.Text; });
983
983
                        int line, column;
984
984
                        buffer.GetLineColumnFromPosition (position, out line, out column);
985
985
                        
1065
1065
                protected virtual int GetNewMethodPosition (IEditableTextFile buffer, IType cls)
1066
1066
                {
1067
1067
                        cls = GetMainPart (cls);
1068
 
                        if (cls.MethodCount == 0) {
 
1068
                        if (cls.MethodCount + cls.ConstructorCount == 0) {
1069
1069
                                return GetNewPropertyPosition (buffer, cls);
1070
1070
                                /*int pos = GetNewPropertyPosition (buffer, cls);
1071
1071
                                int line, col;
1074
1074
                                pos = GetNextLine (buffer, pos);
1075
1075
                                return EnsurePositionIsNotInRegionsAndIndented (cls.SourceProject as Project, buffer, ind, pos);*/
1076
1076
                        } else {
1077
 
                                IMethod m = cls.Methods.Last ();
 
1077
                                var m = cls.Members .Last ();
1078
1078
                                
1079
1079
                                int pos;
1080
 
                                if (!m.BodyRegion.IsEmpty && m.BodyRegion.End.Line > 0) {
 
1080
                                if (!m.BodyRegion.IsEmpty && m.BodyRegion.End.Line > 1) {
1081
1081
                                        pos = buffer.GetPositionFromLineColumn (m.BodyRegion.End.Line, m.BodyRegion.End.Column);
1082
1082
                                        pos = GetNextLine (buffer, pos);
1083
1083
                                        pos = SkipBlankLine (buffer, pos);