[11700] | 1 | // |
---|
| 2 | // AstFormattingVisitor_TypeMembers.cs |
---|
| 3 | // |
---|
| 4 | // Author: |
---|
| 5 | // Mike KrÃŒger <mkrueger@xamarin.com> |
---|
| 6 | // |
---|
| 7 | // Copyright (c) 2013 Xamarin Inc. (http://xamarin.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 | using System; |
---|
| 27 | using System.Linq; |
---|
| 28 | |
---|
| 29 | namespace ICSharpCode.NRefactory.CSharp |
---|
| 30 | { |
---|
| 31 | partial class FormattingVisitor : DepthFirstAstVisitor |
---|
| 32 | { |
---|
| 33 | public override void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration) |
---|
| 34 | { |
---|
| 35 | FixAttributesAndDocComment(propertyDeclaration); |
---|
| 36 | bool oneLine = false; |
---|
| 37 | bool fixClosingBrace = false; |
---|
| 38 | PropertyFormatting propertyFormatting; |
---|
| 39 | |
---|
| 40 | if ((propertyDeclaration.Getter.IsNull || propertyDeclaration.Getter.Body.IsNull) && |
---|
| 41 | (propertyDeclaration.Setter.IsNull || propertyDeclaration.Setter.Body.IsNull)) { |
---|
| 42 | propertyFormatting = policy.AutoPropertyFormatting; |
---|
| 43 | } else { |
---|
| 44 | propertyFormatting = policy.SimplePropertyFormatting; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | switch (propertyFormatting) { |
---|
| 48 | case PropertyFormatting.AllowOneLine: |
---|
| 49 | bool isSimple = IsSimpleAccessor(propertyDeclaration.Getter) && IsSimpleAccessor(propertyDeclaration.Setter); |
---|
| 50 | int accessorLine = propertyDeclaration.RBraceToken.StartLocation.Line; |
---|
| 51 | if (!propertyDeclaration.Getter.IsNull && propertyDeclaration.Setter.IsNull) { |
---|
| 52 | accessorLine = propertyDeclaration.Getter.StartLocation.Line; |
---|
| 53 | } else if (propertyDeclaration.Getter.IsNull && !propertyDeclaration.Setter.IsNull) { |
---|
| 54 | accessorLine = propertyDeclaration.Setter.StartLocation.Line; |
---|
| 55 | } else { |
---|
| 56 | var acc = propertyDeclaration.Getter.StartLocation < propertyDeclaration.Setter.StartLocation ? |
---|
| 57 | propertyDeclaration.Getter : propertyDeclaration.Setter; |
---|
| 58 | accessorLine = acc.StartLocation.Line; |
---|
| 59 | } |
---|
| 60 | if (isSimple && |
---|
| 61 | Math.Min(propertyDeclaration.Getter.StartLocation.Line, propertyDeclaration.Setter.StartLocation.Line) == propertyDeclaration.LBraceToken.StartLocation.Line && |
---|
| 62 | propertyDeclaration.Getter.StartLocation.Line != propertyDeclaration.Setter.StartLocation.Line) |
---|
| 63 | goto case PropertyFormatting.ForceOneLine; |
---|
| 64 | if (!isSimple || propertyDeclaration.LBraceToken.StartLocation.Line != accessorLine) { |
---|
| 65 | fixClosingBrace = true; |
---|
| 66 | FixOpenBrace(policy.PropertyBraceStyle, propertyDeclaration.LBraceToken); |
---|
| 67 | } else { |
---|
| 68 | ForceSpacesBefore(propertyDeclaration.Getter, true); |
---|
| 69 | ForceSpacesBefore(propertyDeclaration.Setter, true); |
---|
| 70 | ForceSpacesBeforeRemoveNewLines(propertyDeclaration.RBraceToken, true); |
---|
| 71 | oneLine = true; |
---|
| 72 | } |
---|
| 73 | break; |
---|
| 74 | case PropertyFormatting.ForceNewLine: |
---|
| 75 | fixClosingBrace = true; |
---|
| 76 | FixOpenBrace(policy.PropertyBraceStyle, propertyDeclaration.LBraceToken); |
---|
| 77 | break; |
---|
| 78 | case PropertyFormatting.ForceOneLine: |
---|
| 79 | isSimple = IsSimpleAccessor(propertyDeclaration.Getter) && IsSimpleAccessor(propertyDeclaration.Setter); |
---|
| 80 | if (isSimple) { |
---|
| 81 | var lBraceToken = propertyDeclaration.LBraceToken; |
---|
| 82 | var rBraceToken = propertyDeclaration.RBraceToken; |
---|
| 83 | ForceSpacesBeforeRemoveNewLines(lBraceToken, true); |
---|
| 84 | if (!propertyDeclaration.Getter.IsNull) |
---|
| 85 | ForceSpacesBeforeRemoveNewLines(propertyDeclaration.Getter, true); |
---|
| 86 | if (!propertyDeclaration.Setter.IsNull) |
---|
| 87 | ForceSpacesBeforeRemoveNewLines(propertyDeclaration.Setter, true); |
---|
| 88 | |
---|
| 89 | ForceSpacesBeforeRemoveNewLines(rBraceToken, true); |
---|
| 90 | oneLine = true; |
---|
| 91 | } else { |
---|
| 92 | fixClosingBrace = true; |
---|
| 93 | FixOpenBrace(policy.PropertyBraceStyle, propertyDeclaration.LBraceToken); |
---|
| 94 | } |
---|
| 95 | break; |
---|
| 96 | } |
---|
| 97 | if (policy.IndentPropertyBody) |
---|
| 98 | curIndent.Push(IndentType.Block); |
---|
| 99 | |
---|
| 100 | FormatAccessor(propertyDeclaration.Getter, policy.PropertyGetBraceStyle, policy.SimpleGetBlockFormatting, oneLine); |
---|
| 101 | FormatAccessor(propertyDeclaration.Setter, policy.PropertySetBraceStyle, policy.SimpleSetBlockFormatting, oneLine); |
---|
| 102 | |
---|
| 103 | if (policy.IndentPropertyBody) { |
---|
| 104 | curIndent.Pop(); |
---|
| 105 | } |
---|
| 106 | if (fixClosingBrace) |
---|
| 107 | FixClosingBrace(policy.PropertyBraceStyle, propertyDeclaration.RBraceToken); |
---|
| 108 | |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | void FormatAccessor(Accessor accessor, BraceStyle braceStyle, PropertyFormatting blockFormatting, bool oneLine) |
---|
| 112 | { |
---|
| 113 | if (accessor.IsNull) |
---|
| 114 | return; |
---|
| 115 | if (!oneLine) { |
---|
| 116 | if (!IsLineIsEmptyUpToEol(accessor.StartLocation)) { |
---|
| 117 | int offset = this.document.GetOffset(accessor.StartLocation); |
---|
| 118 | int start = SearchWhitespaceStart(offset); |
---|
| 119 | string indentString = this.curIndent.IndentString; |
---|
| 120 | AddChange(start, offset - start, this.options.EolMarker + indentString); |
---|
| 121 | } else { |
---|
| 122 | FixIndentation(accessor); |
---|
| 123 | } |
---|
| 124 | } else { |
---|
| 125 | blockFormatting = PropertyFormatting.ForceOneLine; |
---|
| 126 | if (!accessor.Body.IsNull) { |
---|
| 127 | ForceSpacesBeforeRemoveNewLines(accessor.Body.LBraceToken, true); |
---|
| 128 | ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true); |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | if (!accessor.IsNull) { |
---|
| 134 | if (!accessor.Body.IsNull) { |
---|
| 135 | if (IsSimpleAccessor (accessor)) { |
---|
| 136 | switch (blockFormatting) { |
---|
| 137 | case PropertyFormatting.AllowOneLine: |
---|
| 138 | if (accessor.Body.LBraceToken.StartLocation.Line != accessor.Body.RBraceToken.StartLocation.Line) |
---|
| 139 | goto case PropertyFormatting.ForceNewLine; |
---|
| 140 | nextStatementIndent = " "; |
---|
| 141 | VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks); |
---|
| 142 | nextStatementIndent = null; |
---|
| 143 | if (!oneLine) |
---|
| 144 | ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true); |
---|
| 145 | break; |
---|
| 146 | case PropertyFormatting.ForceOneLine: |
---|
| 147 | FixOpenBrace(BraceStyle.EndOfLine, accessor.Body.LBraceToken); |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | var statement = accessor.Body.Statements.FirstOrDefault(); |
---|
| 151 | if (statement != null) { |
---|
| 152 | ForceSpacesBeforeRemoveNewLines(statement, true); |
---|
| 153 | statement.AcceptVisitor(this); |
---|
| 154 | } |
---|
| 155 | if (!oneLine) |
---|
| 156 | ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true); |
---|
| 157 | break; |
---|
| 158 | case PropertyFormatting.ForceNewLine: |
---|
| 159 | FixOpenBrace(braceStyle, accessor.Body.LBraceToken); |
---|
| 160 | VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks); |
---|
| 161 | if (!oneLine) |
---|
| 162 | FixClosingBrace(braceStyle, accessor.Body.RBraceToken); |
---|
| 163 | break; |
---|
| 164 | } |
---|
| 165 | } else { |
---|
| 166 | FixOpenBrace(braceStyle, accessor.Body.LBraceToken); |
---|
| 167 | VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks); |
---|
| 168 | FixClosingBrace(braceStyle, accessor.Body.RBraceToken); |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | public override void VisitAccessor(Accessor accessor) |
---|
| 175 | { |
---|
| 176 | FixAttributesAndDocComment(accessor); |
---|
| 177 | |
---|
| 178 | base.VisitAccessor(accessor); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) |
---|
| 182 | { |
---|
| 183 | FixAttributesAndDocComment(indexerDeclaration); |
---|
| 184 | |
---|
| 185 | ForceSpacesBefore(indexerDeclaration.LBracketToken, policy.SpaceBeforeIndexerDeclarationBracket); |
---|
| 186 | ForceSpacesAfter(indexerDeclaration.LBracketToken, policy.SpaceWithinIndexerDeclarationBracket); |
---|
| 187 | |
---|
| 188 | FormatArguments(indexerDeclaration); |
---|
| 189 | |
---|
| 190 | bool oneLine = false; |
---|
| 191 | bool fixClosingBrace = false; |
---|
| 192 | switch (policy.SimplePropertyFormatting) { |
---|
| 193 | case PropertyFormatting.AllowOneLine: |
---|
| 194 | bool isSimple = IsSimpleAccessor(indexerDeclaration.Getter) && IsSimpleAccessor(indexerDeclaration.Setter); |
---|
| 195 | int accessorLine = indexerDeclaration.RBraceToken.StartLocation.Line; |
---|
| 196 | if (!indexerDeclaration.Getter.IsNull && indexerDeclaration.Setter.IsNull) { |
---|
| 197 | accessorLine = indexerDeclaration.Getter.StartLocation.Line; |
---|
| 198 | } else if (indexerDeclaration.Getter.IsNull && !indexerDeclaration.Setter.IsNull) { |
---|
| 199 | accessorLine = indexerDeclaration.Setter.StartLocation.Line; |
---|
| 200 | } else { |
---|
| 201 | var acc = indexerDeclaration.Getter.StartLocation < indexerDeclaration.Setter.StartLocation ? |
---|
| 202 | indexerDeclaration.Getter : indexerDeclaration.Setter; |
---|
| 203 | accessorLine = acc.StartLocation.Line; |
---|
| 204 | } |
---|
| 205 | if (!isSimple || indexerDeclaration.LBraceToken.StartLocation.Line != accessorLine) { |
---|
| 206 | fixClosingBrace = true; |
---|
| 207 | FixOpenBrace(policy.PropertyBraceStyle, indexerDeclaration.LBraceToken); |
---|
| 208 | } else { |
---|
| 209 | ForceSpacesBefore(indexerDeclaration.Getter, true); |
---|
| 210 | ForceSpacesBefore(indexerDeclaration.Setter, true); |
---|
| 211 | ForceSpacesBeforeRemoveNewLines(indexerDeclaration.RBraceToken, true); |
---|
| 212 | oneLine = true; |
---|
| 213 | } |
---|
| 214 | break; |
---|
| 215 | case PropertyFormatting.ForceNewLine: |
---|
| 216 | fixClosingBrace = true; |
---|
| 217 | FixOpenBrace(policy.PropertyBraceStyle, indexerDeclaration.LBraceToken); |
---|
| 218 | break; |
---|
| 219 | case PropertyFormatting.ForceOneLine: |
---|
| 220 | isSimple = IsSimpleAccessor(indexerDeclaration.Getter) && IsSimpleAccessor(indexerDeclaration.Setter); |
---|
| 221 | if (isSimple) { |
---|
| 222 | int offset = this.document.GetOffset(indexerDeclaration.LBraceToken.StartLocation); |
---|
| 223 | |
---|
| 224 | int start = SearchWhitespaceStart(offset); |
---|
| 225 | int end = SearchWhitespaceEnd(offset); |
---|
| 226 | AddChange(start, offset - start, " "); |
---|
| 227 | AddChange(offset + 1, end - offset - 2, " "); |
---|
| 228 | |
---|
| 229 | offset = this.document.GetOffset(indexerDeclaration.RBraceToken.StartLocation); |
---|
| 230 | start = SearchWhitespaceStart(offset); |
---|
| 231 | AddChange(start, offset - start, " "); |
---|
| 232 | oneLine = true; |
---|
| 233 | |
---|
| 234 | } else { |
---|
| 235 | fixClosingBrace = true; |
---|
| 236 | FixOpenBrace(policy.PropertyBraceStyle, indexerDeclaration.LBraceToken); |
---|
| 237 | } |
---|
| 238 | break; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | if (policy.IndentPropertyBody) |
---|
| 242 | curIndent.Push(IndentType.Block); |
---|
| 243 | |
---|
| 244 | FormatAccessor(indexerDeclaration.Getter, policy.PropertyGetBraceStyle, policy.SimpleGetBlockFormatting, oneLine); |
---|
| 245 | FormatAccessor(indexerDeclaration.Setter, policy.PropertySetBraceStyle, policy.SimpleSetBlockFormatting, oneLine); |
---|
| 246 | if (policy.IndentPropertyBody) |
---|
| 247 | curIndent.Pop(); |
---|
| 248 | |
---|
| 249 | if (fixClosingBrace) |
---|
| 250 | FixClosingBrace(policy.PropertyBraceStyle, indexerDeclaration.RBraceToken); |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | static bool IsSimpleEvent(AstNode node) |
---|
| 254 | { |
---|
| 255 | return node is EventDeclaration; |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration) |
---|
| 259 | { |
---|
| 260 | FixAttributesAndDocComment(eventDeclaration); |
---|
| 261 | |
---|
| 262 | FixOpenBrace(policy.EventBraceStyle, eventDeclaration.LBraceToken); |
---|
| 263 | if (policy.IndentEventBody) |
---|
| 264 | curIndent.Push(IndentType.Block); |
---|
| 265 | |
---|
| 266 | if (!eventDeclaration.AddAccessor.IsNull) { |
---|
| 267 | FixIndentation(eventDeclaration.AddAccessor); |
---|
| 268 | if (!eventDeclaration.AddAccessor.Body.IsNull) { |
---|
| 269 | if (!policy.AllowEventAddBlockInline || eventDeclaration.AddAccessor.Body.LBraceToken.StartLocation.Line != eventDeclaration.AddAccessor.Body.RBraceToken.StartLocation.Line) { |
---|
| 270 | FixOpenBrace(policy.EventAddBraceStyle, eventDeclaration.AddAccessor.Body.LBraceToken); |
---|
| 271 | VisitBlockWithoutFixingBraces(eventDeclaration.AddAccessor.Body, policy.IndentBlocks); |
---|
| 272 | FixClosingBrace(policy.EventAddBraceStyle, eventDeclaration.AddAccessor.Body.RBraceToken); |
---|
| 273 | } else { |
---|
| 274 | nextStatementIndent = " "; |
---|
| 275 | VisitBlockWithoutFixingBraces(eventDeclaration.AddAccessor.Body, policy.IndentBlocks); |
---|
| 276 | nextStatementIndent = null; |
---|
| 277 | } |
---|
| 278 | } |
---|
| 279 | } |
---|
| 280 | |
---|
| 281 | if (!eventDeclaration.RemoveAccessor.IsNull) { |
---|
| 282 | FixIndentation(eventDeclaration.RemoveAccessor); |
---|
| 283 | if (!eventDeclaration.RemoveAccessor.Body.IsNull) { |
---|
| 284 | if (!policy.AllowEventRemoveBlockInline || eventDeclaration.RemoveAccessor.Body.LBraceToken.StartLocation.Line != eventDeclaration.RemoveAccessor.Body.RBraceToken.StartLocation.Line) { |
---|
| 285 | FixOpenBrace(policy.EventRemoveBraceStyle, eventDeclaration.RemoveAccessor.Body.LBraceToken); |
---|
| 286 | VisitBlockWithoutFixingBraces(eventDeclaration.RemoveAccessor.Body, policy.IndentBlocks); |
---|
| 287 | FixClosingBrace(policy.EventRemoveBraceStyle, eventDeclaration.RemoveAccessor.Body.RBraceToken); |
---|
| 288 | } else { |
---|
| 289 | nextStatementIndent = " "; |
---|
| 290 | VisitBlockWithoutFixingBraces(eventDeclaration.RemoveAccessor.Body, policy.IndentBlocks); |
---|
| 291 | nextStatementIndent = null; |
---|
| 292 | } |
---|
| 293 | } |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | if (policy.IndentEventBody) |
---|
| 297 | curIndent.Pop(); |
---|
| 298 | |
---|
| 299 | FixClosingBrace(policy.EventBraceStyle, eventDeclaration.RBraceToken); |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | public override void VisitEventDeclaration(EventDeclaration eventDeclaration) |
---|
| 303 | { |
---|
| 304 | FixAttributesAndDocComment(eventDeclaration); |
---|
| 305 | |
---|
| 306 | foreach (var m in eventDeclaration.ModifierTokens) { |
---|
| 307 | ForceSpacesAfter(m, true); |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | ForceSpacesBeforeRemoveNewLines(eventDeclaration.EventToken.GetNextSibling(NoWhitespacePredicate), true); |
---|
| 311 | eventDeclaration.ReturnType.AcceptVisitor(this); |
---|
| 312 | ForceSpacesAfter(eventDeclaration.ReturnType, true); |
---|
| 313 | /* |
---|
| 314 | var lastLoc = eventDeclaration.StartLocation; |
---|
| 315 | curIndent.Push(IndentType.Block); |
---|
| 316 | foreach (var initializer in eventDeclaration.Variables) { |
---|
| 317 | if (lastLoc.Line != initializer.StartLocation.Line) { |
---|
| 318 | FixStatementIndentation(initializer.StartLocation); |
---|
| 319 | lastLoc = initializer.StartLocation; |
---|
| 320 | } |
---|
| 321 | initializer.AcceptVisitor(this); |
---|
| 322 | } |
---|
| 323 | curIndent.Pop (); |
---|
| 324 | */ |
---|
| 325 | FixSemicolon(eventDeclaration.SemicolonToken); |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | public override void VisitFieldDeclaration(FieldDeclaration fieldDeclaration) |
---|
| 329 | { |
---|
| 330 | FixAttributesAndDocComment(fieldDeclaration); |
---|
| 331 | |
---|
| 332 | fieldDeclaration.ReturnType.AcceptVisitor(this); |
---|
| 333 | ForceSpacesAfter(fieldDeclaration.ReturnType, true); |
---|
| 334 | |
---|
| 335 | FormatCommas(fieldDeclaration, policy.SpaceBeforeFieldDeclarationComma, policy.SpaceAfterFieldDeclarationComma); |
---|
| 336 | |
---|
| 337 | var lastLoc = fieldDeclaration.ReturnType.StartLocation; |
---|
| 338 | foreach (var initializer in fieldDeclaration.Variables) { |
---|
| 339 | if (lastLoc.Line != initializer.StartLocation.Line) { |
---|
| 340 | curIndent.Push(IndentType.Block); |
---|
| 341 | FixStatementIndentation(initializer.StartLocation); |
---|
| 342 | curIndent.Pop(); |
---|
| 343 | lastLoc = initializer.StartLocation; |
---|
| 344 | } |
---|
| 345 | initializer.AcceptVisitor(this); |
---|
| 346 | } |
---|
| 347 | FixSemicolon(fieldDeclaration.SemicolonToken); |
---|
| 348 | } |
---|
| 349 | |
---|
| 350 | public override void VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration) |
---|
| 351 | { |
---|
| 352 | FixAttributesAndDocComment(fixedFieldDeclaration); |
---|
| 353 | |
---|
| 354 | FormatCommas(fixedFieldDeclaration, policy.SpaceBeforeFieldDeclarationComma, policy.SpaceAfterFieldDeclarationComma); |
---|
| 355 | |
---|
| 356 | var lastLoc = fixedFieldDeclaration.StartLocation; |
---|
| 357 | curIndent.Push(IndentType.Block); |
---|
| 358 | foreach (var initializer in fixedFieldDeclaration.Variables) { |
---|
| 359 | if (lastLoc.Line != initializer.StartLocation.Line) { |
---|
| 360 | FixStatementIndentation(initializer.StartLocation); |
---|
| 361 | lastLoc = initializer.StartLocation; |
---|
| 362 | } |
---|
| 363 | initializer.AcceptVisitor(this); |
---|
| 364 | } |
---|
| 365 | curIndent.Pop(); |
---|
| 366 | FixSemicolon(fixedFieldDeclaration.SemicolonToken); |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | public override void VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration) |
---|
| 370 | { |
---|
| 371 | FixAttributesAndDocComment(enumMemberDeclaration); |
---|
| 372 | var initializer = enumMemberDeclaration.Initializer; |
---|
| 373 | if (!initializer.IsNull) { |
---|
| 374 | ForceSpacesAround(enumMemberDeclaration.AssignToken, policy.SpaceAroundAssignment); |
---|
| 375 | initializer.AcceptVisitor(this); |
---|
| 376 | } |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration) |
---|
| 380 | { |
---|
| 381 | FixAttributesAndDocComment(methodDeclaration); |
---|
| 382 | |
---|
| 383 | ForceSpacesBefore(methodDeclaration.LParToken, policy.SpaceBeforeMethodDeclarationParentheses); |
---|
| 384 | if (methodDeclaration.Parameters.Any()) { |
---|
| 385 | ForceSpacesAfter(methodDeclaration.LParToken, policy.SpaceWithinMethodDeclarationParentheses); |
---|
| 386 | FormatArguments(methodDeclaration); |
---|
| 387 | } else { |
---|
| 388 | ForceSpacesAfter(methodDeclaration.LParToken, policy.SpaceBetweenEmptyMethodDeclarationParentheses); |
---|
| 389 | ForceSpacesBefore(methodDeclaration.RParToken, policy.SpaceBetweenEmptyMethodDeclarationParentheses); |
---|
| 390 | } |
---|
| 391 | |
---|
| 392 | foreach (var constraint in methodDeclaration.Constraints) |
---|
| 393 | constraint.AcceptVisitor(this); |
---|
| 394 | |
---|
| 395 | if (!methodDeclaration.Body.IsNull) { |
---|
| 396 | FixOpenBrace(policy.MethodBraceStyle, methodDeclaration.Body.LBraceToken); |
---|
| 397 | VisitBlockWithoutFixingBraces(methodDeclaration.Body, policy.IndentMethodBody); |
---|
| 398 | FixClosingBrace(policy.MethodBraceStyle, methodDeclaration.Body.RBraceToken); |
---|
| 399 | } |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | public override void VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration) |
---|
| 403 | { |
---|
| 404 | FixAttributesAndDocComment(operatorDeclaration); |
---|
| 405 | |
---|
| 406 | ForceSpacesBefore(operatorDeclaration.LParToken, policy.SpaceBeforeMethodDeclarationParentheses); |
---|
| 407 | if (operatorDeclaration.Parameters.Any()) { |
---|
| 408 | ForceSpacesAfter(operatorDeclaration.LParToken, policy.SpaceWithinMethodDeclarationParentheses); |
---|
| 409 | FormatArguments(operatorDeclaration); |
---|
| 410 | } else { |
---|
| 411 | ForceSpacesAfter(operatorDeclaration.LParToken, policy.SpaceBetweenEmptyMethodDeclarationParentheses); |
---|
| 412 | ForceSpacesBefore(operatorDeclaration.RParToken, policy.SpaceBetweenEmptyMethodDeclarationParentheses); |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | if (!operatorDeclaration.Body.IsNull) { |
---|
| 416 | FixOpenBrace(policy.MethodBraceStyle, operatorDeclaration.Body.LBraceToken); |
---|
| 417 | VisitBlockWithoutFixingBraces(operatorDeclaration.Body, policy.IndentMethodBody); |
---|
| 418 | FixClosingBrace(policy.MethodBraceStyle, operatorDeclaration.Body.RBraceToken); |
---|
| 419 | } |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) |
---|
| 423 | { |
---|
| 424 | FixAttributesAndDocComment(constructorDeclaration); |
---|
| 425 | |
---|
| 426 | ForceSpacesBefore(constructorDeclaration.LParToken, policy.SpaceBeforeConstructorDeclarationParentheses); |
---|
| 427 | if (constructorDeclaration.Parameters.Any()) { |
---|
| 428 | ForceSpacesAfter(constructorDeclaration.LParToken, policy.SpaceWithinConstructorDeclarationParentheses); |
---|
| 429 | FormatArguments(constructorDeclaration); |
---|
| 430 | } else { |
---|
| 431 | ForceSpacesAfter(constructorDeclaration.LParToken, policy.SpaceBetweenEmptyConstructorDeclarationParentheses); |
---|
| 432 | ForceSpacesBefore(constructorDeclaration.RParToken, policy.SpaceBetweenEmptyConstructorDeclarationParentheses); |
---|
| 433 | } |
---|
| 434 | |
---|
| 435 | var initializer = constructorDeclaration.Initializer; |
---|
| 436 | if (!initializer.IsNull) { |
---|
| 437 | curIndent.Push(IndentType.Block); |
---|
| 438 | PlaceOnNewLine(policy.NewLineBeforeConstructorInitializerColon, constructorDeclaration.ColonToken); |
---|
| 439 | PlaceOnNewLine(policy.NewLineAfterConstructorInitializerColon, initializer); |
---|
| 440 | initializer.AcceptVisitor(this); |
---|
| 441 | curIndent.Pop(); |
---|
| 442 | } |
---|
| 443 | if (!constructorDeclaration.Body.IsNull) { |
---|
| 444 | FixOpenBrace(policy.ConstructorBraceStyle, constructorDeclaration.Body.LBraceToken); |
---|
| 445 | VisitBlockWithoutFixingBraces(constructorDeclaration.Body, policy.IndentMethodBody); |
---|
| 446 | FixClosingBrace(policy.ConstructorBraceStyle, constructorDeclaration.Body.RBraceToken); |
---|
| 447 | } |
---|
| 448 | } |
---|
| 449 | public override void VisitConstructorInitializer(ConstructorInitializer constructorInitializer) |
---|
| 450 | { |
---|
| 451 | ForceSpacesBefore(constructorInitializer.LParToken, policy.SpaceBeforeMethodCallParentheses); |
---|
| 452 | if (constructorInitializer.Arguments.Any()) { |
---|
| 453 | ForceSpacesAfter(constructorInitializer.LParToken, policy.SpaceWithinMethodCallParentheses); |
---|
| 454 | } else { |
---|
| 455 | ForceSpacesAfter(constructorInitializer.LParToken, policy.SpaceBetweenEmptyMethodCallParentheses); |
---|
| 456 | ForceSpacesBefore(constructorInitializer.RParToken, policy.SpaceBetweenEmptyMethodCallParentheses); |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | FormatArguments(constructorInitializer); |
---|
| 460 | |
---|
| 461 | } |
---|
| 462 | public override void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration) |
---|
| 463 | { |
---|
| 464 | FixAttributesAndDocComment(destructorDeclaration); |
---|
| 465 | |
---|
| 466 | CSharpTokenNode lParen = destructorDeclaration.LParToken; |
---|
| 467 | ForceSpaceBefore(lParen, policy.SpaceBeforeConstructorDeclarationParentheses); |
---|
| 468 | |
---|
| 469 | if (!destructorDeclaration.Body.IsNull) { |
---|
| 470 | FixOpenBrace(policy.DestructorBraceStyle, destructorDeclaration.Body.LBraceToken); |
---|
| 471 | VisitBlockWithoutFixingBraces(destructorDeclaration.Body, policy.IndentMethodBody); |
---|
| 472 | FixClosingBrace(policy.DestructorBraceStyle, destructorDeclaration.Body.RBraceToken); |
---|
| 473 | } |
---|
| 474 | } |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | |
---|