~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
                bool firstUsingDeclaration;
37
37
                bool lastUsingDeclaration;
38
38
                
 
39
                public bool FoldBraces = false;
 
40
                
39
41
                public TextOutputFormatter(ITextOutput output)
40
42
                {
41
43
                        if (output == null)
114
116
                object GetCurrentLocalDefinition()
115
117
                {
116
118
                        AstNode node = nodeStack.Peek();
 
119
                        if (node is Identifier && node.Parent != null)
 
120
                                node = node.Parent;
 
121
                        
117
122
                        var parameterDef = node.Annotation<ParameterDefinition>();
118
123
                        if (parameterDef != null)
119
124
                                return parameterDef;
126
131
                                        //if (variable.OriginalVariable != null)
127
132
                                        //    return variable.OriginalVariable;
128
133
                                        return variable;
129
 
                                } else {
130
 
 
131
134
                                }
132
135
                        }
133
136
 
134
137
                        var label = node as LabelStatement;
135
 
                        if (label != null)
136
 
                        {
 
138
                        if (label != null) {
137
139
                                var method = nodeStack.Select(nd => nd.Annotation<MethodReference>()).FirstOrDefault(mr => mr != null);
138
140
                                if (method != null)
139
141
                                        return method.ToString() + label.Label;
165
167
                
166
168
                public void WriteToken(string token)
167
169
                {
168
 
                        if (string.IsNullOrEmpty (token))
169
 
                                return;
170
170
                        // Attach member reference to token only if there's no identifier in the current node.
171
171
                        MemberReference memberRef = GetCurrentMemberReference();
172
172
                        var node = nodeStack.Peek();
185
185
                {
186
186
                        if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration)
187
187
                                braceLevelWithinType++;
188
 
                        if (nodeStack.OfType<BlockStatement>().Count() <= 1) {
 
188
                        if (nodeStack.OfType<BlockStatement>().Count() <= 1 || FoldBraces) {
189
189
                                output.MarkFoldStart(defaultCollapsed: braceLevelWithinType == 1);
190
190
                        }
191
191
                        output.WriteLine();
197
197
                {
198
198
                        output.Unindent();
199
199
                        output.Write('}');
200
 
                        if (nodeStack.OfType<BlockStatement>().Count() <= 1)
 
200
                        if (nodeStack.OfType<BlockStatement>().Count() <= 1 || FoldBraces)
201
201
                                output.MarkFoldEnd();
202
202
                        if (braceLevelWithinType >= 0)
203
203
                                braceLevelWithinType--;
284
284
                        nodeStack.Push(node);
285
285
                        startLocations.Push(output.Location);
286
286
                        
 
287
                        if (node is EntityDeclaration && node.Annotation<MemberReference>() != null && node.GetChildByRole(Roles.Identifier).IsNull)
 
288
                                output.WriteDefinition("", node.Annotation<MemberReference>(), false);
 
289
                        
287
290
                        MemberMapping mapping = node.Annotation<MemberMapping>();
288
291
                        if (mapping != null) {
289
292
                                parentMemberMappings.Push(currentMemberMapping);
329
332
                
330
333
                private static bool IsDefinition(AstNode node)
331
334
                {
332
 
                        return
333
 
                                node is FieldDeclaration ||
334
 
                                node is ConstructorDeclaration ||
335
 
                                node is DestructorDeclaration ||
336
 
                                node is EventDeclaration ||
337
 
                                node is DelegateDeclaration ||
338
 
                                node is OperatorDeclaration||
339
 
                                node is EntityDeclaration ||
340
 
                                node is TypeDeclaration;
 
335
                        return node is EntityDeclaration;
341
336
                }
342
337
        }
343
338
}