OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library dart_style.src.source_visitor; | 5 library dart_style.src.source_visitor; |
6 | 6 |
7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
8 import 'package:analyzer/src/generated/scanner.dart'; | 8 import 'package:analyzer/src/generated/scanner.dart'; |
9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
10 | 10 |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 modifier(node.factoryKeyword); | 531 modifier(node.factoryKeyword); |
532 visit(node.returnType); | 532 visit(node.returnType); |
533 token(node.period); | 533 token(node.period); |
534 visit(node.name); | 534 visit(node.name); |
535 | 535 |
536 // Make the rule for the ":" span both the preceding parameter list and | 536 // Make the rule for the ":" span both the preceding parameter list and |
537 // the entire initialization list. This ensures that we split before the | 537 // the entire initialization list. This ensures that we split before the |
538 // ":" if the parameters and initialization list don't all fit on one line. | 538 // ":" if the parameters and initialization list don't all fit on one line. |
539 builder.startRule(); | 539 builder.startRule(); |
540 | 540 |
| 541 // If the redirecting constructor happens to wrap, we want to make sure |
| 542 // the parameter list gets more deeply indented. |
| 543 if (node.redirectedConstructor != null) builder.nestExpression(); |
| 544 |
541 _visitBody(node.parameters, node.body, () { | 545 _visitBody(node.parameters, node.body, () { |
542 // Check for redirects or initializer lists. | 546 // Check for redirects or initializer lists. |
543 if (node.redirectedConstructor != null) { | 547 if (node.redirectedConstructor != null) { |
544 _visitConstructorRedirects(node); | 548 _visitConstructorRedirects(node); |
| 549 builder.unnest(); |
545 } else if (node.initializers.isNotEmpty) { | 550 } else if (node.initializers.isNotEmpty) { |
546 _visitConstructorInitializers(node); | 551 _visitConstructorInitializers(node); |
547 } | 552 } |
548 }); | 553 }); |
549 } | 554 } |
550 | 555 |
551 void _visitConstructorRedirects(ConstructorDeclaration node) { | 556 void _visitConstructorRedirects(ConstructorDeclaration node) { |
552 token(node.separator /* = */, before: space, after: space); | 557 token(node.separator /* = */, before: space); |
| 558 soloSplit(); |
553 visitCommaSeparatedNodes(node.initializers); | 559 visitCommaSeparatedNodes(node.initializers); |
554 visit(node.redirectedConstructor); | 560 visit(node.redirectedConstructor); |
555 } | 561 } |
556 | 562 |
557 void _visitConstructorInitializers(ConstructorDeclaration node) { | 563 void _visitConstructorInitializers(ConstructorDeclaration node) { |
558 // Shift the ":" forward. | 564 // Shift the ":" forward. |
559 builder.indent(Indent.constructorInitializer); | 565 builder.indent(Indent.constructorInitializer); |
560 | 566 |
561 split(); | 567 split(); |
562 token(node.separator); // ":". | 568 token(node.separator); // ":". |
(...skipping 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2340 /// Gets the 1-based line number that the beginning of [token] lies on. | 2346 /// Gets the 1-based line number that the beginning of [token] lies on. |
2341 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber; | 2347 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber; |
2342 | 2348 |
2343 /// Gets the 1-based line number that the end of [token] lies on. | 2349 /// Gets the 1-based line number that the end of [token] lies on. |
2344 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber; | 2350 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber; |
2345 | 2351 |
2346 /// Gets the 1-based column number that the beginning of [token] lies on. | 2352 /// Gets the 1-based column number that the beginning of [token] lies on. |
2347 int _startColumn(Token token) => | 2353 int _startColumn(Token token) => |
2348 _lineInfo.getLocation(token.offset).columnNumber; | 2354 _lineInfo.getLocation(token.offset).columnNumber; |
2349 } | 2355 } |
OLD | NEW |