Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: lib/src/source_visitor.dart

Issue 824763004: Allow splitting in clauses in C-style for loop. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/regression/100.stmt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } 480 }
481 481
482 visitEmptyFunctionBody(EmptyFunctionBody node) { 482 visitEmptyFunctionBody(EmptyFunctionBody node) {
483 token(node.semicolon); 483 token(node.semicolon);
484 } 484 }
485 485
486 visitEmptyStatement(EmptyStatement node) { 486 visitEmptyStatement(EmptyStatement node) {
487 token(node.semicolon); 487 token(node.semicolon);
488 } 488 }
489 489
490 visitEnumConstantDeclaration(EnumConstantDeclaration node) {
491 throw new UnimplementedError("Enum formatting is not implemented yet.");
492 }
493
494 visitEnumDeclaration(EnumDeclaration node) {
495 throw new UnimplementedError("Enum formatting is not implemented yet.");
496 }
497
490 visitExportDirective(ExportDirective node) { 498 visitExportDirective(ExportDirective node) {
491 visitDeclarationMetadata(node.metadata); 499 visitDeclarationMetadata(node.metadata);
492 token(node.keyword); 500 token(node.keyword);
493 space(); 501 space();
494 visit(node.uri); 502 visit(node.uri);
495 _visitCombinators(node.combinators); 503 _visitCombinators(node.combinators);
496 token(node.semicolon); 504 token(node.semicolon);
497 } 505 }
498 506
499 visitExpressionFunctionBody(ExpressionFunctionBody node) { 507 visitExpressionFunctionBody(ExpressionFunctionBody node) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 } 562 }
555 space(); 563 space();
556 token(node.inKeyword); 564 token(node.inKeyword);
557 space(); 565 space();
558 visit(node.iterator); 566 visit(node.iterator);
559 token(node.rightParenthesis); 567 token(node.rightParenthesis);
560 space(); 568 space();
561 visit(node.body); 569 visit(node.body);
562 } 570 }
563 571
564 visitEnumConstantDeclaration(EnumConstantDeclaration node) {
565 throw new UnimplementedError("Enum formatting is not implemented yet.");
566 }
567
568 visitEnumDeclaration(EnumDeclaration node) {
569 throw new UnimplementedError("Enum formatting is not implemented yet.");
570 }
571
572 visitFormalParameterList(FormalParameterList node) { 572 visitFormalParameterList(FormalParameterList node) {
573 token(node.leftParenthesis); 573 token(node.leftParenthesis);
574 574
575 // Allow splitting after the "(" but not for lambdas. 575 // Allow splitting after the "(" but not for lambdas.
576 // TODO(rnystrom): Need to check for comments in empty parameter list. 576 // TODO(rnystrom): Need to check for comments in empty parameter list.
577 // See visitArgumentList. 577 // See visitArgumentList.
578 if (node.parameters.isNotEmpty && !_isLambda(node)) zeroSplit(); 578 if (node.parameters.isNotEmpty && !_isLambda(node)) zeroSplit();
579 579
580 // Try to keep the parameters together. 580 // Try to keep the parameters together.
581 _writer.startSpan(); 581 _writer.startSpan();
(...skipping 21 matching lines...) Expand all
603 token(node.rightDelimiter); 603 token(node.rightDelimiter);
604 604
605 token(node.rightParenthesis); 605 token(node.rightParenthesis);
606 _writer.endSpan(); 606 _writer.endSpan();
607 } 607 }
608 608
609 visitForStatement(ForStatement node) { 609 visitForStatement(ForStatement node) {
610 token(node.forKeyword); 610 token(node.forKeyword);
611 space(); 611 space();
612 token(node.leftParenthesis); 612 token(node.leftParenthesis);
613
614 _writer.startMultisplit();
615
616 // The initialization clause.
613 if (node.initialization != null) { 617 if (node.initialization != null) {
614 visit(node.initialization); 618 visit(node.initialization);
615 } else { 619 } else {
616 if (node.variables == null) { 620 if (node.variables == null) {
617 space(); 621 space();
618 } else { 622 } else {
619 visit(node.variables); 623 // Indent split variables more so they aren't at the same level
624 // as the rest of the loop clauses.
625 _writer.indent(2);
626
627 var declaration = node.variables;
628 visitDeclarationMetadata(declaration.metadata);
629 modifier(declaration.keyword);
630 visitNode(declaration.type, after: space);
631
632 visitCommaSeparatedNodes(declaration.variables, between: () {
633 _writer.multisplit(space: true, nest: true);
634 });
635
636 _writer.unindent(2);
620 } 637 }
621 } 638 }
639
622 token(node.leftSeparator); 640 token(node.leftSeparator);
623 space(); 641 _writer.multisplit(nest: true, space: true);
642
643 // The condition clause.
624 visit(node.condition); 644 visit(node.condition);
625 token(node.rightSeparator); 645 token(node.rightSeparator);
646
647 // The update clause.
626 if (node.updaters != null) { 648 if (node.updaters != null) {
627 space(); 649 _writer.multisplit(nest: true, space: true);
628 visitCommaSeparatedNodes(node.updaters); 650 visitCommaSeparatedNodes(node.updaters,
651 between: () => _writer.multisplit(nest: true, space: true));
629 } 652 }
653
630 token(node.rightParenthesis); 654 token(node.rightParenthesis);
631 if (node.body is! EmptyStatement) { 655 _writer.endMultisplit();
632 space(); 656
633 } 657 // The body.
658 if (node.body is! EmptyStatement) space();
634 visit(node.body); 659 visit(node.body);
635 } 660 }
636 661
637 visitFunctionDeclaration(FunctionDeclaration node) { 662 visitFunctionDeclaration(FunctionDeclaration node) {
638 visitMemberMetadata(node.metadata); 663 visitMemberMetadata(node.metadata);
639 modifier(node.externalKeyword); 664 modifier(node.externalKeyword);
640 visitNode(node.returnType, after: space); 665 visitNode(node.returnType, after: space);
641 modifier(node.propertyKeyword); 666 modifier(node.propertyKeyword);
642 visit(node.name); 667 visit(node.name);
643 visit(node.functionExpression); 668 visit(node.functionExpression);
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 /// Gets the 1-based line number that the beginning of [token] lies on. 1560 /// Gets the 1-based line number that the beginning of [token] lies on.
1536 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber; 1561 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber;
1537 1562
1538 /// Gets the 1-based line number that the end of [token] lies on. 1563 /// Gets the 1-based line number that the end of [token] lies on.
1539 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber; 1564 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber;
1540 1565
1541 /// Gets the 1-based column number that the beginning of [token] lies on. 1566 /// Gets the 1-based column number that the beginning of [token] lies on.
1542 int _startColumn(Token token) => 1567 int _startColumn(Token token) =>
1543 _lineInfo.getLocation(token.offset).columnNumber; 1568 _lineInfo.getLocation(token.offset).columnNumber;
1544 } 1569 }
OLDNEW
« no previous file with comments | « no previous file | test/regression/100.stmt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698