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

Side by Side Diff: pkg/analyzer/lib/src/services/formatter_impl.dart

Issue 225863005: Annotation whitespace convention fixes (dartbug.com/17837). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/services/data/cu_tests.data » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 formatter_impl; 5 library formatter_impl;
6 6
7 import 'dart:math'; 7 import 'dart:math';
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/src/generated/parser.dart'; 10 import 'package:analyzer/src/generated/parser.dart';
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 token(node.rightParenthesis); 523 token(node.rightParenthesis);
524 space(); 524 space();
525 } else { 525 } else {
526 space(); 526 space();
527 } 527 }
528 visit(node.body); 528 visit(node.body);
529 } 529 }
530 530
531 visitClassDeclaration(ClassDeclaration node) { 531 visitClassDeclaration(ClassDeclaration node) {
532 preserveLeadingNewlines(); 532 preserveLeadingNewlines();
533 visitNodes(node.metadata, followedBy: newlines); 533 visitMemberMetadata(node.metadata);
534 modifier(node.abstractKeyword); 534 modifier(node.abstractKeyword);
535 token(node.classKeyword); 535 token(node.classKeyword);
536 space(); 536 space();
537 visit(node.name); 537 visit(node.name);
538 allowContinuedLines((){ 538 allowContinuedLines((){
539 visit(node.typeParameters); 539 visit(node.typeParameters);
540 visitNode(node.extendsClause, precededBy: space); 540 visitNode(node.extendsClause, precededBy: space);
541 visitNode(node.withClause, precededBy: space); 541 visitNode(node.withClause, precededBy: space);
542 visitNode(node.implementsClause, precededBy: space); 542 visitNode(node.implementsClause, precededBy: space);
543 visitNode(node.nativeClause, precededBy: space); 543 visitNode(node.nativeClause, precededBy: space);
544 space(); 544 space();
545 }); 545 });
546 token(node.leftBracket); 546 token(node.leftBracket);
547 indent(); 547 indent();
548 if (!node.members.isEmpty) { 548 if (!node.members.isEmpty) {
549 visitNodes(node.members, precededBy: newlines, separatedBy: newlines); 549 visitNodes(node.members, precededBy: newlines, separatedBy: newlines);
550 newlines(); 550 newlines();
551 } else { 551 } else {
552 preserveLeadingNewlines(); 552 preserveLeadingNewlines();
553 } 553 }
554 token(node.rightBracket, precededBy: unindent); 554 token(node.rightBracket, precededBy: unindent);
555 } 555 }
556 556
557 visitClassTypeAlias(ClassTypeAlias node) { 557 visitClassTypeAlias(ClassTypeAlias node) {
558 preserveLeadingNewlines(); 558 preserveLeadingNewlines();
559 visitNodes(node.metadata, followedBy: newlines); 559 visitMemberMetadata(node.metadata);
560 modifier(node.abstractKeyword); 560 modifier(node.abstractKeyword);
561 token(node.keyword); 561 token(node.keyword);
562 space(); 562 space();
563 visit(node.name); 563 visit(node.name);
564 visit(node.typeParameters); 564 visit(node.typeParameters);
565 space(); 565 space();
566 token(node.equals); 566 token(node.equals);
567 space(); 567 space();
568 visit(node.superclass); 568 visit(node.superclass);
569 visitNode(node.withClause, precededBy: space); 569 visitNode(node.withClause, precededBy: space);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 space(); 608 space();
609 visit(node.thenExpression); 609 visit(node.thenExpression);
610 space(); 610 space();
611 token(node.colon); 611 token(node.colon);
612 space(); 612 space();
613 visit(node.elseExpression); 613 visit(node.elseExpression);
614 }); 614 });
615 } 615 }
616 616
617 visitConstructorDeclaration(ConstructorDeclaration node) { 617 visitConstructorDeclaration(ConstructorDeclaration node) {
618 visitNodes(node.metadata, followedBy: newlines); 618 visitMemberMetadata(node.metadata);
619 modifier(node.externalKeyword); 619 modifier(node.externalKeyword);
620 modifier(node.constKeyword); 620 modifier(node.constKeyword);
621 modifier(node.factoryKeyword); 621 modifier(node.factoryKeyword);
622 visit(node.returnType); 622 visit(node.returnType);
623 token(node.period); 623 token(node.period);
624 visit(node.name); 624 visit(node.name);
625 visit(node.parameters); 625 visit(node.parameters);
626 626
627 // Check for redirects or initializer lists 627 // Check for redirects or initializer lists
628 if (node.separator != null) { 628 if (node.separator != null) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 token(node.semicolon); 736 token(node.semicolon);
737 } 737 }
738 738
739 visitEmptyStatement(EmptyStatement node) { 739 visitEmptyStatement(EmptyStatement node) {
740 if (!codeTransforms || node.parent is! Block) { 740 if (!codeTransforms || node.parent is! Block) {
741 token(node.semicolon); 741 token(node.semicolon);
742 } 742 }
743 } 743 }
744 744
745 visitExportDirective(ExportDirective node) { 745 visitExportDirective(ExportDirective node) {
746 visitNodes(node.metadata, followedBy: newlines); 746 visitDirectiveMetadata(node.metadata);
747 token(node.keyword); 747 token(node.keyword);
748 space(); 748 space();
749 visit(node.uri); 749 visit(node.uri);
750 allowContinuedLines((){ 750 allowContinuedLines((){
751 visitNodes(node.combinators, precededBy: space, separatedBy: space); 751 visitNodes(node.combinators, precededBy: space, separatedBy: space);
752 }); 752 });
753 token(node.semicolon); 753 token(node.semicolon);
754 } 754 }
755 755
756 visitExpressionFunctionBody(ExpressionFunctionBody node) { 756 visitExpressionFunctionBody(ExpressionFunctionBody node) {
757 token(node.functionDefinition); 757 token(node.functionDefinition);
758 space(); 758 space();
759 visit(node.expression); 759 visit(node.expression);
760 token(node.semicolon); 760 token(node.semicolon);
761 } 761 }
762 762
763 visitExpressionStatement(ExpressionStatement node) { 763 visitExpressionStatement(ExpressionStatement node) {
764 visit(node.expression); 764 visit(node.expression);
765 token(node.semicolon); 765 token(node.semicolon);
766 } 766 }
767 767
768 visitExtendsClause(ExtendsClause node) { 768 visitExtendsClause(ExtendsClause node) {
769 token(node.keyword); 769 token(node.keyword);
770 space(); 770 space();
771 visit(node.superclass); 771 visit(node.superclass);
772 } 772 }
773 773
774 visitFieldDeclaration(FieldDeclaration node) { 774 visitFieldDeclaration(FieldDeclaration node) {
775 visitNodes(node.metadata, followedBy: newlines); 775 visitMemberMetadata(node.metadata);
776 modifier(node.staticKeyword); 776 modifier(node.staticKeyword);
777 visit(node.fields); 777 visit(node.fields);
778 token(node.semicolon); 778 token(node.semicolon);
779 } 779 }
780 780
781 visitFieldFormalParameter(FieldFormalParameter node) { 781 visitFieldFormalParameter(FieldFormalParameter node) {
782 token(node.keyword, followedBy: space); 782 token(node.keyword, followedBy: space);
783 visitNode(node.type, followedBy: space); 783 visitNode(node.type, followedBy: space);
784 token(node.thisToken); 784 token(node.thisToken);
785 token(node.period); 785 token(node.period);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 } 855 }
856 token(node.rightParenthesis); 856 token(node.rightParenthesis);
857 if (node.body is! EmptyStatement) { 857 if (node.body is! EmptyStatement) {
858 space(); 858 space();
859 } 859 }
860 visit(node.body); 860 visit(node.body);
861 } 861 }
862 862
863 visitFunctionDeclaration(FunctionDeclaration node) { 863 visitFunctionDeclaration(FunctionDeclaration node) {
864 preserveLeadingNewlines(); 864 preserveLeadingNewlines();
865 visitNodes(node.metadata, followedBy: newlines); 865 visitMemberMetadata(node.metadata);
866 modifier(node.externalKeyword); 866 modifier(node.externalKeyword);
867 visitNode(node.returnType, followedBy: space); 867 visitNode(node.returnType, followedBy: space);
868 modifier(node.propertyKeyword); 868 modifier(node.propertyKeyword);
869 visit(node.name); 869 visit(node.name);
870 visit(node.functionExpression); 870 visit(node.functionExpression);
871 } 871 }
872 872
873 visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { 873 visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
874 visit(node.functionDeclaration); 874 visit(node.functionDeclaration);
875 } 875 }
876 876
877 visitFunctionExpression(FunctionExpression node) { 877 visitFunctionExpression(FunctionExpression node) {
878 visit(node.parameters); 878 visit(node.parameters);
879 if (node.body is! EmptyFunctionBody) { 879 if (node.body is! EmptyFunctionBody) {
880 space(); 880 space();
881 } 881 }
882 visit(node.body); 882 visit(node.body);
883 } 883 }
884 884
885 visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 885 visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
886 visit(node.function); 886 visit(node.function);
887 visit(node.argumentList); 887 visit(node.argumentList);
888 } 888 }
889 889
890 visitFunctionTypeAlias(FunctionTypeAlias node) { 890 visitFunctionTypeAlias(FunctionTypeAlias node) {
891 visitNodes(node.metadata, separatedBy: newlines, followedBy: newlines); 891 visitMemberMetadata(node.metadata);
892 token(node.keyword); 892 token(node.keyword);
893 space(); 893 space();
894 visitNode(node.returnType, followedBy: space); 894 visitNode(node.returnType, followedBy: space);
895 visit(node.name); 895 visit(node.name);
896 visit(node.typeParameters); 896 visit(node.typeParameters);
897 visit(node.parameters); 897 visit(node.parameters);
898 token(node.semicolon); 898 token(node.semicolon);
899 } 899 }
900 900
901 visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 901 visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 } 935 }
936 } 936 }
937 937
938 visitImplementsClause(ImplementsClause node) { 938 visitImplementsClause(ImplementsClause node) {
939 token(node.keyword); 939 token(node.keyword);
940 space(); 940 space();
941 visitCommaSeparatedNodes(node.interfaces); 941 visitCommaSeparatedNodes(node.interfaces);
942 } 942 }
943 943
944 visitImportDirective(ImportDirective node) { 944 visitImportDirective(ImportDirective node) {
945 visitNodes(node.metadata, followedBy: newlines); 945 visitDirectiveMetadata(node.metadata);
946 token(node.keyword); 946 token(node.keyword);
947 nonBreakingSpace(); 947 nonBreakingSpace();
948 visit(node.uri); 948 visit(node.uri);
949 token(node.asToken, precededBy: space, followedBy: space); 949 token(node.asToken, precededBy: space, followedBy: space);
950 allowContinuedLines((){ 950 allowContinuedLines((){
951 visit(node.prefix); 951 visit(node.prefix);
952 visitNodes(node.combinators, precededBy: space, separatedBy: space); 952 visitNodes(node.combinators, precededBy: space, separatedBy: space);
953 }); 953 });
954 token(node.semicolon); 954 token(node.semicolon);
955 } 955 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 visit(node.label); 1004 visit(node.label);
1005 token(node.colon); 1005 token(node.colon);
1006 } 1006 }
1007 1007
1008 visitLabeledStatement(LabeledStatement node) { 1008 visitLabeledStatement(LabeledStatement node) {
1009 visitNodes(node.labels, separatedBy: space, followedBy: space); 1009 visitNodes(node.labels, separatedBy: space, followedBy: space);
1010 visit(node.statement); 1010 visit(node.statement);
1011 } 1011 }
1012 1012
1013 visitLibraryDirective(LibraryDirective node) { 1013 visitLibraryDirective(LibraryDirective node) {
1014 visitNodes(node.metadata, followedBy: newlines); 1014 visitDirectiveMetadata(node.metadata);
1015 token(node.keyword); 1015 token(node.keyword);
1016 space(); 1016 space();
1017 visit(node.name); 1017 visit(node.name);
1018 token(node.semicolon); 1018 token(node.semicolon);
1019 } 1019 }
1020 1020
1021 visitLibraryIdentifier(LibraryIdentifier node) { 1021 visitLibraryIdentifier(LibraryIdentifier node) {
1022 append(node.name); 1022 append(node.name);
1023 } 1023 }
1024 1024
(...skipping 23 matching lines...) Expand all
1048 } 1048 }
1049 1049
1050 visitMapLiteralEntry(MapLiteralEntry node) { 1050 visitMapLiteralEntry(MapLiteralEntry node) {
1051 visit(node.key); 1051 visit(node.key);
1052 token(node.separator); 1052 token(node.separator);
1053 space(); 1053 space();
1054 visit(node.value); 1054 visit(node.value);
1055 } 1055 }
1056 1056
1057 visitMethodDeclaration(MethodDeclaration node) { 1057 visitMethodDeclaration(MethodDeclaration node) {
1058 visitNodes(node.metadata, followedBy: newlines); 1058 visitMemberMetadata(node.metadata);
1059 modifier(node.externalKeyword); 1059 modifier(node.externalKeyword);
1060 modifier(node.modifierKeyword); 1060 modifier(node.modifierKeyword);
1061 visitNode(node.returnType, followedBy: space); 1061 visitNode(node.returnType, followedBy: space);
1062 modifier(node.propertyKeyword); 1062 modifier(node.propertyKeyword);
1063 modifier(node.operatorKeyword); 1063 modifier(node.operatorKeyword);
1064 visit(node.name); 1064 visit(node.name);
1065 if (!node.isGetter) { 1065 if (!node.isGetter) {
1066 visit(node.parameters); 1066 visit(node.parameters);
1067 } 1067 }
1068 visitPrefixedBody(space, node.body); 1068 visitPrefixedBody(space, node.body);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 token(node.scriptTag); 1175 token(node.scriptTag);
1176 } 1176 }
1177 1177
1178 visitShowCombinator(ShowCombinator node) { 1178 visitShowCombinator(ShowCombinator node) {
1179 token(node.keyword); 1179 token(node.keyword);
1180 space(); 1180 space();
1181 visitCommaSeparatedNodes(node.shownNames); 1181 visitCommaSeparatedNodes(node.shownNames);
1182 } 1182 }
1183 1183
1184 visitSimpleFormalParameter(SimpleFormalParameter node) { 1184 visitSimpleFormalParameter(SimpleFormalParameter node) {
1185 visitNodes(node.metadata, followedBy: space); 1185 visitMemberMetadata(node.metadata);
1186 modifier(node.keyword); 1186 modifier(node.keyword);
1187 visitNode(node.type, followedBy: space); 1187 visitNode(node.type, followedBy: space);
1188 visit(node.identifier); 1188 visit(node.identifier);
1189 } 1189 }
1190 1190
1191 visitSimpleIdentifier(SimpleIdentifier node) { 1191 visitSimpleIdentifier(SimpleIdentifier node) {
1192 token(node.token); 1192 token(node.token);
1193 } 1193 }
1194 1194
1195 visitSimpleStringLiteral(SimpleStringLiteral node) { 1195 visitSimpleStringLiteral(SimpleStringLiteral node) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 visitCommaSeparatedNodes(node.arguments); 1298 visitCommaSeparatedNodes(node.arguments);
1299 token(node.rightBracket); 1299 token(node.rightBracket);
1300 } 1300 }
1301 1301
1302 visitTypeName(TypeName node) { 1302 visitTypeName(TypeName node) {
1303 visit(node.name); 1303 visit(node.name);
1304 visit(node.typeArguments); 1304 visit(node.typeArguments);
1305 } 1305 }
1306 1306
1307 visitTypeParameter(TypeParameter node) { 1307 visitTypeParameter(TypeParameter node) {
1308 visitNodes(node.metadata, followedBy: space); 1308 visitMemberMetadata(node.metadata);
1309 visit(node.name); 1309 visit(node.name);
1310 token(node.keyword /* extends */, precededBy: space, followedBy: space); 1310 token(node.keyword /* extends */, precededBy: space, followedBy: space);
1311 visit(node.bound); 1311 visit(node.bound);
1312 } 1312 }
1313 1313
1314 visitTypeParameterList(TypeParameterList node) { 1314 visitTypeParameterList(TypeParameterList node) {
1315 token(node.leftBracket); 1315 token(node.leftBracket);
1316 visitCommaSeparatedNodes(node.typeParameters); 1316 visitCommaSeparatedNodes(node.typeParameters);
1317 token(node.rightBracket); 1317 token(node.rightBracket);
1318 } 1318 }
(...skipping 10 matching lines...) Expand all
1329 visit(initializer); 1329 visit(initializer);
1330 }); 1330 });
1331 } else { 1331 } else {
1332 space(); 1332 space();
1333 visit(initializer); 1333 visit(initializer);
1334 } 1334 }
1335 } 1335 }
1336 } 1336 }
1337 1337
1338 visitVariableDeclarationList(VariableDeclarationList node) { 1338 visitVariableDeclarationList(VariableDeclarationList node) {
1339 visitNodes(node.metadata, followedBy: newlines); 1339 visitMemberMetadata(node.metadata);
1340 modifier(node.keyword); 1340 modifier(node.keyword);
1341 visitNode(node.type, followedBy: space); 1341 visitNode(node.type, followedBy: space);
1342 1342
1343 var variables = node.variables; 1343 var variables = node.variables;
1344 // Decls with initializers get their own lines (dartbug.com/16849) 1344 // Decls with initializers get their own lines (dartbug.com/16849)
1345 if (variables.any((v) => (v.initializer != null))) { 1345 if (variables.any((v) => (v.initializer != null))) {
1346 var size = variables.length; 1346 var size = variables.length;
1347 if (size > 0) { 1347 if (size > 0) {
1348 var variable; 1348 var variable;
1349 for (var i = 0; i < size; i++) { 1349 for (var i = 0; i < size; i++) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 visitCommaSeparatedNodes(node.mixinTypes); 1392 visitCommaSeparatedNodes(node.mixinTypes);
1393 } 1393 }
1394 1394
1395 /// Safely visit the given [node]. 1395 /// Safely visit the given [node].
1396 visit(AstNode node) { 1396 visit(AstNode node) {
1397 if (node != null) { 1397 if (node != null) {
1398 node.accept(this); 1398 node.accept(this);
1399 } 1399 }
1400 } 1400 }
1401 1401
1402 /// Visit member metadata
1403 visitMemberMetadata(NodeList<Annotation> metadata) {
1404 visitNodes(metadata,
1405 separatedBy: () {
1406 space();
1407 preserveLeadingNewlines();
1408 },
1409 followedBy: space);
1410 if (metadata != null && metadata.length > 0) {
1411 preserveLeadingNewlines();
1412 }
1413 }
1414
1415 /// Visit member metadata
1416 visitDirectiveMetadata(NodeList<Annotation> metadata) {
1417 visitNodes(metadata, separatedBy: newlines, followedBy: newlines);
1418 }
1419
1402 /// Visit the given function [body], printing the [prefix] before if given 1420 /// Visit the given function [body], printing the [prefix] before if given
1403 /// body is not empty. 1421 /// body is not empty.
1404 visitPrefixedBody(prefix(), FunctionBody body) { 1422 visitPrefixedBody(prefix(), FunctionBody body) {
1405 if (body is! EmptyFunctionBody) { 1423 if (body is! EmptyFunctionBody) {
1406 prefix(); 1424 prefix();
1407 } 1425 }
1408 visit(body); 1426 visit(body);
1409 } 1427 }
1410 1428
1411 /// Visit a list of [nodes] if not null, optionally separated and/or preceded 1429 /// Visit a list of [nodes] if not null, optionally separated and/or preceded
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 var lastLine = 1772 var lastLine =
1755 lineInfo.getLocation(lastOffset).lineNumber; 1773 lineInfo.getLocation(lastOffset).lineNumber;
1756 var currentLine = 1774 var currentLine =
1757 lineInfo.getLocation(currentOffset).lineNumber; 1775 lineInfo.getLocation(currentOffset).lineNumber;
1758 return currentLine - lastLine; 1776 return currentLine - lastLine;
1759 } 1777 }
1760 1778
1761 String toString() => writer.toString(); 1779 String toString() => writer.toString();
1762 1780
1763 } 1781 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/services/data/cu_tests.data » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698