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

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

Issue 125253005: Formatter support for metadata. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 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/java_core.dart' show CharSequence; 10 import 'package:analyzer/src/generated/java_core.dart' show CharSequence;
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 token(node.rightParenthesis); 489 token(node.rightParenthesis);
490 space(); 490 space();
491 } else { 491 } else {
492 space(); 492 space();
493 } 493 }
494 visit(node.body); 494 visit(node.body);
495 } 495 }
496 496
497 visitClassDeclaration(ClassDeclaration node) { 497 visitClassDeclaration(ClassDeclaration node) {
498 preserveLeadingNewlines(); 498 preserveLeadingNewlines();
499 visitNodes(node.metadata, followedBy: newlines);
499 modifier(node.abstractKeyword); 500 modifier(node.abstractKeyword);
500 token(node.classKeyword); 501 token(node.classKeyword);
501 space(); 502 space();
502 visit(node.name); 503 visit(node.name);
503 allowContinuedLines((){ 504 allowContinuedLines((){
504 visit(node.typeParameters); 505 visit(node.typeParameters);
505 visitNode(node.extendsClause, precededBy: space); 506 visitNode(node.extendsClause, precededBy: space);
506 visitNode(node.withClause, precededBy: space); 507 visitNode(node.withClause, precededBy: space);
507 visitNode(node.implementsClause, precededBy: space); 508 visitNode(node.implementsClause, precededBy: space);
508 space(); 509 space();
509 }); 510 });
510 token(node.leftBracket); 511 token(node.leftBracket);
511 indent(); 512 indent();
512 visitNodes(node.members, precededBy: newlines, separatedBy: newlines); 513 visitNodes(node.members, precededBy: newlines, separatedBy: newlines);
513 unindent(); 514 unindent();
514 newlines(); 515 newlines();
515 token(node.rightBracket); 516 token(node.rightBracket);
516 } 517 }
517 518
518 visitClassTypeAlias(ClassTypeAlias node) { 519 visitClassTypeAlias(ClassTypeAlias node) {
519 preserveLeadingNewlines(); 520 preserveLeadingNewlines();
521 visitNodes(node.metadata, followedBy: newlines);
520 //TODO(pquitslund): the following _should_ work (dartbug.com/15912) 522 //TODO(pquitslund): the following _should_ work (dartbug.com/15912)
521 //modifier(node.abstractKeyword); 523 //modifier(node.abstractKeyword);
522 // ... in the meantime we use this workaround 524 // ... in the meantime we use this workaround
523 var prev = node.keyword.previous; 525 var prev = node.keyword.previous;
524 if (prev.keyword == Keyword.ABSTRACT) { 526 if (prev is KeywordToken && prev.keyword == Keyword.ABSTRACT) {
525 token(prev); 527 token(prev);
526 space(); 528 space();
527 } 529 }
528 token(node.keyword); 530 token(node.keyword);
529 space(); 531 space();
530 visit(node.name); 532 visit(node.name);
531 visit(node.typeParameters); 533 visit(node.typeParameters);
532 space(); 534 space();
533 token(node.equals); 535 token(node.equals);
534 space(); 536 space();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 space(); 577 space();
576 visit(node.thenExpression); 578 visit(node.thenExpression);
577 space(); 579 space();
578 token(node.colon); 580 token(node.colon);
579 space(); 581 space();
580 visit(node.elseExpression); 582 visit(node.elseExpression);
581 }); 583 });
582 } 584 }
583 585
584 visitConstructorDeclaration(ConstructorDeclaration node) { 586 visitConstructorDeclaration(ConstructorDeclaration node) {
587 visitNodes(node.metadata, followedBy: newlines);
585 modifier(node.externalKeyword); 588 modifier(node.externalKeyword);
586 modifier(node.constKeyword); 589 modifier(node.constKeyword);
587 modifier(node.factoryKeyword); 590 modifier(node.factoryKeyword);
588 visit(node.returnType); 591 visit(node.returnType);
589 token(node.period); 592 token(node.period);
590 visit(node.name); 593 visit(node.name);
591 visit(node.parameters); 594 visit(node.parameters);
592 595
593 // Check for redirects or initializer lists 596 // Check for redirects or initializer lists
594 if (node.separator != null) { 597 if (node.separator != null) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 698
696 visitEmptyFunctionBody(EmptyFunctionBody node) { 699 visitEmptyFunctionBody(EmptyFunctionBody node) {
697 token(node.semicolon); 700 token(node.semicolon);
698 } 701 }
699 702
700 visitEmptyStatement(EmptyStatement node) { 703 visitEmptyStatement(EmptyStatement node) {
701 token(node.semicolon); 704 token(node.semicolon);
702 } 705 }
703 706
704 visitExportDirective(ExportDirective node) { 707 visitExportDirective(ExportDirective node) {
708 visitNodes(node.metadata, followedBy: newlines);
705 token(node.keyword); 709 token(node.keyword);
706 space(); 710 space();
707 visit(node.uri); 711 visit(node.uri);
708 allowContinuedLines((){ 712 allowContinuedLines((){
709 visitNodes(node.combinators, precededBy: space, separatedBy: space); 713 visitNodes(node.combinators, precededBy: space, separatedBy: space);
710 }); 714 });
711 token(node.semicolon); 715 token(node.semicolon);
712 } 716 }
713 717
714 visitExpressionFunctionBody(ExpressionFunctionBody node) { 718 visitExpressionFunctionBody(ExpressionFunctionBody node) {
715 token(node.functionDefinition); 719 token(node.functionDefinition);
716 space(); 720 space();
717 visit(node.expression); 721 visit(node.expression);
718 token(node.semicolon); 722 token(node.semicolon);
719 } 723 }
720 724
721 visitExpressionStatement(ExpressionStatement node) { 725 visitExpressionStatement(ExpressionStatement node) {
722 visit(node.expression); 726 visit(node.expression);
723 token(node.semicolon); 727 token(node.semicolon);
724 } 728 }
725 729
726 visitExtendsClause(ExtendsClause node) { 730 visitExtendsClause(ExtendsClause node) {
727 token(node.keyword); 731 token(node.keyword);
728 space(); 732 space();
729 visit(node.superclass); 733 visit(node.superclass);
730 } 734 }
731 735
732 visitFieldDeclaration(FieldDeclaration node) { 736 visitFieldDeclaration(FieldDeclaration node) {
737 visitNodes(node.metadata, followedBy: newlines);
733 modifier(node.staticKeyword); 738 modifier(node.staticKeyword);
734 visit(node.fields); 739 visit(node.fields);
735 token(node.semicolon); 740 token(node.semicolon);
736 } 741 }
737 742
738 visitFieldFormalParameter(FieldFormalParameter node) { 743 visitFieldFormalParameter(FieldFormalParameter node) {
739 token(node.keyword, followedBy: space); 744 token(node.keyword, followedBy: space);
740 visitNode(node.type, followedBy: space); 745 visitNode(node.type, followedBy: space);
741 token(node.thisToken); 746 token(node.thisToken);
742 token(node.period); 747 token(node.period);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 } 813 }
809 token(node.rightParenthesis); 814 token(node.rightParenthesis);
810 if (node.body is! EmptyStatement) { 815 if (node.body is! EmptyStatement) {
811 space(); 816 space();
812 } 817 }
813 visit(node.body); 818 visit(node.body);
814 } 819 }
815 820
816 visitFunctionDeclaration(FunctionDeclaration node) { 821 visitFunctionDeclaration(FunctionDeclaration node) {
817 preserveLeadingNewlines(); 822 preserveLeadingNewlines();
823 visitNodes(node.metadata, followedBy: newlines);
818 modifier(node.externalKeyword); 824 modifier(node.externalKeyword);
819 //TODO(pquitslund): remove this workaround once setter functions 825 //TODO(pquitslund): remove this workaround once setter functions
820 //have their return types properly set (dartbug.com/15914) 826 //have their return types properly set (dartbug.com/15914)
821 if (node.returnType == null && node.propertyKeyword != null) { 827 if (node.returnType == null && node.propertyKeyword != null) {
822 modifier(node.propertyKeyword.previous); 828 modifier(node.propertyKeyword.previous);
823 } else { 829 } else {
824 visitNode(node.returnType, followedBy: space); 830 visitNode(node.returnType, followedBy: space);
825 } 831 }
826 modifier(node.propertyKeyword); 832 modifier(node.propertyKeyword);
827 visit(node.name); 833 visit(node.name);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 } 894 }
889 } 895 }
890 896
891 visitImplementsClause(ImplementsClause node) { 897 visitImplementsClause(ImplementsClause node) {
892 token(node.keyword); 898 token(node.keyword);
893 space(); 899 space();
894 visitCommaSeparatedNodes(node.interfaces); 900 visitCommaSeparatedNodes(node.interfaces);
895 } 901 }
896 902
897 visitImportDirective(ImportDirective node) { 903 visitImportDirective(ImportDirective node) {
904 visitNodes(node.metadata, followedBy: newlines);
898 token(node.keyword); 905 token(node.keyword);
899 space(); 906 space();
900 visit(node.uri); 907 visit(node.uri);
901 token(node.asToken, precededBy: space, followedBy: space); 908 token(node.asToken, precededBy: space, followedBy: space);
902 allowContinuedLines((){ 909 allowContinuedLines((){
903 visit(node.prefix); 910 visit(node.prefix);
904 visitNodes(node.combinators, precededBy: space, separatedBy: space); 911 visitNodes(node.combinators, precededBy: space, separatedBy: space);
905 }); 912 });
906 token(node.semicolon); 913 token(node.semicolon);
907 } 914 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 visit(node.label); 963 visit(node.label);
957 token(node.colon); 964 token(node.colon);
958 } 965 }
959 966
960 visitLabeledStatement(LabeledStatement node) { 967 visitLabeledStatement(LabeledStatement node) {
961 visitNodes(node.labels, separatedBy: space, followedBy: space); 968 visitNodes(node.labels, separatedBy: space, followedBy: space);
962 visit(node.statement); 969 visit(node.statement);
963 } 970 }
964 971
965 visitLibraryDirective(LibraryDirective node) { 972 visitLibraryDirective(LibraryDirective node) {
973 visitNodes(node.metadata, followedBy: newlines);
966 token(node.keyword); 974 token(node.keyword);
967 space(); 975 space();
968 visit(node.name); 976 visit(node.name);
969 token(node.semicolon); 977 token(node.semicolon);
970 } 978 }
971 979
972 visitLibraryIdentifier(LibraryIdentifier node) { 980 visitLibraryIdentifier(LibraryIdentifier node) {
973 append(node.name); 981 append(node.name);
974 } 982 }
975 983
(...skipping 22 matching lines...) Expand all
998 } 1006 }
999 1007
1000 visitMapLiteralEntry(MapLiteralEntry node) { 1008 visitMapLiteralEntry(MapLiteralEntry node) {
1001 visit(node.key); 1009 visit(node.key);
1002 token(node.separator); 1010 token(node.separator);
1003 space(); 1011 space();
1004 visit(node.value); 1012 visit(node.value);
1005 } 1013 }
1006 1014
1007 visitMethodDeclaration(MethodDeclaration node) { 1015 visitMethodDeclaration(MethodDeclaration node) {
1016 visitNodes(node.metadata, followedBy: newlines);
1008 modifier(node.externalKeyword); 1017 modifier(node.externalKeyword);
1009 modifier(node.modifierKeyword); 1018 modifier(node.modifierKeyword);
1010 visitNode(node.returnType, followedBy: space); 1019 visitNode(node.returnType, followedBy: space);
1011 modifier(node.propertyKeyword); 1020 modifier(node.propertyKeyword);
1012 modifier(node.operatorKeyword); 1021 modifier(node.operatorKeyword);
1013 visit(node.name); 1022 visit(node.name);
1014 if (!node.isGetter) { 1023 if (!node.isGetter) {
1015 visit(node.parameters); 1024 visit(node.parameters);
1016 } 1025 }
1017 visitPrefixedBody(space, node.body); 1026 visitPrefixedBody(space, node.body);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 token(node.scriptTag); 1133 token(node.scriptTag);
1125 } 1134 }
1126 1135
1127 visitShowCombinator(ShowCombinator node) { 1136 visitShowCombinator(ShowCombinator node) {
1128 token(node.keyword); 1137 token(node.keyword);
1129 space(); 1138 space();
1130 visitCommaSeparatedNodes(node.shownNames); 1139 visitCommaSeparatedNodes(node.shownNames);
1131 } 1140 }
1132 1141
1133 visitSimpleFormalParameter(SimpleFormalParameter node) { 1142 visitSimpleFormalParameter(SimpleFormalParameter node) {
1143 visitNodes(node.metadata, followedBy: space);
1134 modifier(node.keyword); 1144 modifier(node.keyword);
1135 visitNode(node.type, followedBy: space); 1145 visitNode(node.type, followedBy: space);
1136 visit(node.identifier); 1146 visit(node.identifier);
1137 } 1147 }
1138 1148
1139 visitSimpleIdentifier(SimpleIdentifier node) { 1149 visitSimpleIdentifier(SimpleIdentifier node) {
1140 token(node.token); 1150 token(node.token);
1141 } 1151 }
1142 1152
1143 visitSimpleStringLiteral(SimpleStringLiteral node) { 1153 visitSimpleStringLiteral(SimpleStringLiteral node) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 visitCommaSeparatedNodes(node.arguments); 1237 visitCommaSeparatedNodes(node.arguments);
1228 token(node.rightBracket); 1238 token(node.rightBracket);
1229 } 1239 }
1230 1240
1231 visitTypeName(TypeName node) { 1241 visitTypeName(TypeName node) {
1232 visit(node.name); 1242 visit(node.name);
1233 visit(node.typeArguments); 1243 visit(node.typeArguments);
1234 } 1244 }
1235 1245
1236 visitTypeParameter(TypeParameter node) { 1246 visitTypeParameter(TypeParameter node) {
1247 visitNodes(node.metadata, followedBy: space);
1237 visit(node.name); 1248 visit(node.name);
1238 token(node.keyword /* extends */, precededBy: space, followedBy: space); 1249 token(node.keyword /* extends */, precededBy: space, followedBy: space);
1239 visit(node.bound); 1250 visit(node.bound);
1240 } 1251 }
1241 1252
1242 visitTypeParameterList(TypeParameterList node) { 1253 visitTypeParameterList(TypeParameterList node) {
1243 token(node.leftBracket); 1254 token(node.leftBracket);
1244 visitCommaSeparatedNodes(node.typeParameters); 1255 visitCommaSeparatedNodes(node.typeParameters);
1245 token(node.rightBracket); 1256 token(node.rightBracket);
1246 } 1257 }
(...skipping 10 matching lines...) Expand all
1257 visit(initializer); 1268 visit(initializer);
1258 }); 1269 });
1259 } else { 1270 } else {
1260 space(); 1271 space();
1261 visit(initializer); 1272 visit(initializer);
1262 } 1273 }
1263 } 1274 }
1264 } 1275 }
1265 1276
1266 visitVariableDeclarationList(VariableDeclarationList node) { 1277 visitVariableDeclarationList(VariableDeclarationList node) {
1278 visitNodes(node.metadata, followedBy: newlines);
1267 modifier(node.keyword); 1279 modifier(node.keyword);
1268 visitNode(node.type, followedBy: space); 1280 visitNode(node.type, followedBy: space);
1269 visitCommaSeparatedNodes(node.variables); 1281 visitCommaSeparatedNodes(node.variables);
1270 } 1282 }
1271 1283
1272 visitVariableDeclarationStatement(VariableDeclarationStatement node) { 1284 visitVariableDeclarationStatement(VariableDeclarationStatement node) {
1273 visit(node.variables); 1285 visit(node.variables);
1274 token(node.semicolon); 1286 token(node.semicolon);
1275 } 1287 }
1276 1288
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 var lastLine = 1654 var lastLine =
1643 lineInfo.getLocation(lastOffset).lineNumber; 1655 lineInfo.getLocation(lastOffset).lineNumber;
1644 var currentLine = 1656 var currentLine =
1645 lineInfo.getLocation(currentOffset).lineNumber; 1657 lineInfo.getLocation(currentOffset).lineNumber;
1646 return currentLine - lastLine; 1658 return currentLine - lastLine;
1647 } 1659 }
1648 1660
1649 String toString() => writer.toString(); 1661 String toString() => writer.toString();
1650 1662
1651 } 1663 }
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