Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_experimental/analyzer.dart'; | 9 import 'package:analyzer_experimental/analyzer.dart'; |
| 10 import 'package:analyzer_experimental/src/generated/parser.dart'; | 10 import 'package:analyzer_experimental/src/generated/parser.dart'; |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 | 380 |
| 381 visitContinueStatement(ContinueStatement node) { | 381 visitContinueStatement(ContinueStatement node) { |
| 382 token(node.keyword); | 382 token(node.keyword); |
| 383 visitPrefixed(' ', node.label); | 383 visitPrefixed(' ', node.label); |
| 384 token(node.semicolon); | 384 token(node.semicolon); |
| 385 } | 385 } |
| 386 | 386 |
| 387 visitDeclaredIdentifier(DeclaredIdentifier node) { | 387 visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 388 token(node.keyword); | 388 token(node.keyword); |
| 389 space(); | 389 space(); |
| 390 visitSuffixed(node.type, ' '); | 390 visit(node.type); |
| 391 space(); | |
|
Brian Wilkerson
2013/08/21 18:18:53
Do you want to mark somehow (comment perhaps) that
pquitslund
2013/08/21 19:40:40
Good catch. Fixed!
| |
| 391 visit(node.identifier); | 392 visit(node.identifier); |
| 392 } | 393 } |
| 393 | 394 |
| 394 visitDefaultFormalParameter(DefaultFormalParameter node) { | 395 visitDefaultFormalParameter(DefaultFormalParameter node) { |
| 395 visit(node.parameter); | 396 visit(node.parameter); |
| 396 if (node.separator != null) { | 397 if (node.separator != null) { |
| 397 space(); | 398 space(); |
| 398 token(node.separator); | 399 token(node.separator); |
| 399 visitPrefixed(' ', node.defaultValue); | 400 visitPrefixed(' ', node.defaultValue); |
| 400 } | 401 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 visitFieldDeclaration(FieldDeclaration node) { | 455 visitFieldDeclaration(FieldDeclaration node) { |
| 455 token(node.keyword); | 456 token(node.keyword); |
| 456 space(); | 457 space(); |
| 457 visit(node.fields); | 458 visit(node.fields); |
| 458 token(node.semicolon); | 459 token(node.semicolon); |
| 459 } | 460 } |
| 460 | 461 |
| 461 visitFieldFormalParameter(FieldFormalParameter node) { | 462 visitFieldFormalParameter(FieldFormalParameter node) { |
| 462 token(node.keyword); | 463 token(node.keyword); |
| 463 space(); | 464 space(); |
| 464 visitSuffixed(node.type, ' '); | 465 visit(node.type); |
| 466 space(); | |
| 465 token(node.thisToken); | 467 token(node.thisToken); |
| 466 token(node.period); | 468 token(node.period); |
| 467 visit(node.identifier); | 469 visit(node.identifier); |
| 468 visit(node.parameters); | 470 visit(node.parameters); |
| 469 } | 471 } |
| 470 | 472 |
| 471 visitForEachStatement(ForEachStatement node) { | 473 visitForEachStatement(ForEachStatement node) { |
| 472 token(node.forKeyword); | 474 token(node.forKeyword); |
| 473 space(); | 475 space(); |
| 474 token(node.leftParenthesis); | 476 token(node.leftParenthesis); |
| 475 visit(node.loopVariable); | 477 visit(node.loopVariable); |
| 476 space(); | 478 space(); |
| 477 token(node.inKeyword); | 479 token(node.inKeyword); |
| 478 space(); | 480 space(); |
| 479 visit(node.iterator); | 481 visit(node.iterator); |
| 480 token(node.leftParenthesis); | 482 token(node.rightParenthesis); |
| 481 space(); | 483 space(); |
| 482 visit(node.body); | 484 visit(node.body); |
| 483 } | 485 } |
| 484 | 486 |
| 485 visitFormalParameterList(FormalParameterList node) { | 487 visitFormalParameterList(FormalParameterList node) { |
| 486 var groupEnd = null; | 488 var groupEnd = null; |
| 487 token(node.leftParenthesis); | 489 token(node.leftParenthesis); |
| 488 var parameters = node.parameters; | 490 var parameters = node.parameters; |
| 489 var size = parameters.length; | 491 var size = parameters.length; |
| 490 for (var i = 0; i < size; i++) { | 492 for (var i = 0; i < size; i++) { |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 827 token(node.scriptTag); | 829 token(node.scriptTag); |
| 828 } | 830 } |
| 829 | 831 |
| 830 visitShowCombinator(ShowCombinator node) { | 832 visitShowCombinator(ShowCombinator node) { |
| 831 token(node.keyword); | 833 token(node.keyword); |
| 832 space(); | 834 space(); |
| 833 visitList(node.shownNames, ', '); | 835 visitList(node.shownNames, ', '); |
| 834 } | 836 } |
| 835 | 837 |
| 836 visitSimpleFormalParameter(SimpleFormalParameter node) { | 838 visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 837 token(node.keyword); | 839 modifier(node.keyword); |
| 838 space(); | |
| 839 visitSuffixed(node.type, ' '); | 840 visitSuffixed(node.type, ' '); |
| 840 visit(node.identifier); | 841 visit(node.identifier); |
| 841 } | 842 } |
| 842 | 843 |
| 843 visitSimpleIdentifier(SimpleIdentifier node) { | 844 visitSimpleIdentifier(SimpleIdentifier node) { |
| 844 token(node.token); | 845 token(node.token); |
| 845 } | 846 } |
| 846 | 847 |
| 847 visitSimpleStringLiteral(SimpleStringLiteral node) { | 848 visitSimpleStringLiteral(SimpleStringLiteral node) { |
| 848 token(node.literal); | 849 token(node.literal); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 907 token(node.keyword); | 908 token(node.keyword); |
| 908 } | 909 } |
| 909 | 910 |
| 910 visitThrowExpression(ThrowExpression node) { | 911 visitThrowExpression(ThrowExpression node) { |
| 911 token(node.keyword); | 912 token(node.keyword); |
| 912 space(); | 913 space(); |
| 913 visit(node.expression); | 914 visit(node.expression); |
| 914 } | 915 } |
| 915 | 916 |
| 916 visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 917 visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 917 visitSuffixed(node.variables, ';'); | 918 preservePrecedingNewlines = true; |
| 919 visit(node.variables); | |
| 920 token(node.semicolon); | |
| 918 } | 921 } |
| 919 | 922 |
| 920 visitTryStatement(TryStatement node) { | 923 visitTryStatement(TryStatement node) { |
| 921 preservePrecedingNewlines = true; | 924 preservePrecedingNewlines = true; |
| 922 token(node.tryKeyword); | 925 token(node.tryKeyword); |
| 923 space(); | 926 space(); |
| 924 visit(node.body); | 927 visit(node.body); |
| 925 visitPrefixedList(' ', node.catchClauses, ' '); | 928 visitPrefixedList(' ', node.catchClauses, ' '); |
| 926 visitPrefixed(' finally ', node.finallyClause); | 929 visitPrefixed(' finally ', node.finallyClause); |
| 927 } | 930 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 943 } | 946 } |
| 944 | 947 |
| 945 visitTypeParameterList(TypeParameterList node) { | 948 visitTypeParameterList(TypeParameterList node) { |
| 946 token(node.leftBracket); | 949 token(node.leftBracket); |
| 947 visitList(node.typeParameters, ', '); | 950 visitList(node.typeParameters, ', '); |
| 948 token(node.rightBracket); | 951 token(node.rightBracket); |
| 949 } | 952 } |
| 950 | 953 |
| 951 visitVariableDeclaration(VariableDeclaration node) { | 954 visitVariableDeclaration(VariableDeclaration node) { |
| 952 visit(node.name); | 955 visit(node.name); |
| 953 visitPrefixed(' = ', node.initializer); | 956 space(); |
|
Brian Wilkerson
2013/08/21 18:18:53
Similarly here, the spaces and equals are only wan
pquitslund
2013/08/21 19:40:40
Exactly right. Thanks!
| |
| 957 token(node.equals); | |
| 958 space(); | |
| 959 visit(node.initializer); | |
| 954 } | 960 } |
| 955 | 961 |
| 956 visitVariableDeclarationList(VariableDeclarationList node) { | 962 visitVariableDeclarationList(VariableDeclarationList node) { |
| 957 token(node.keyword); | 963 token(node.keyword); |
| 958 space(); | 964 space(); |
| 959 visitSuffixed(node.type, ' '); | 965 visitSuffixed(node.type, ' '); |
| 960 visitList(node.variables, ', '); | 966 visitList(node.variables, ', '); |
| 961 } | 967 } |
| 962 | 968 |
| 963 visitVariableDeclarationStatement(VariableDeclarationStatement node) { | 969 visitVariableDeclarationStatement(VariableDeclarationStatement node) { |
| 964 visit(node.variables); | 970 visit(node.variables); |
| 965 token(node.semicolon); | 971 token(node.semicolon); |
| 972 needsNewline = true; | |
| 966 } | 973 } |
| 967 | 974 |
| 968 visitWhileStatement(WhileStatement node) { | 975 visitWhileStatement(WhileStatement node) { |
| 969 token(node.keyword); | 976 token(node.keyword); |
| 970 space(); | 977 space(); |
| 971 token(node.leftParenthesis); | 978 token(node.leftParenthesis); |
| 972 visit(node.condition); | 979 visit(node.condition); |
| 973 token(node.rightParenthesis); | 980 token(node.rightParenthesis); |
| 974 space(); | 981 space(); |
| 975 visit(node.body); | 982 visit(node.body); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1151 var lastLine = | 1158 var lastLine = |
| 1152 lineInfo.getLocation(last.offset).lineNumber; | 1159 lineInfo.getLocation(last.offset).lineNumber; |
| 1153 var currentLine = | 1160 var currentLine = |
| 1154 lineInfo.getLocation(current.offset).lineNumber; | 1161 lineInfo.getLocation(current.offset).lineNumber; |
| 1155 return currentLine - lastLine; | 1162 return currentLine - lastLine; |
| 1156 } | 1163 } |
| 1157 | 1164 |
| 1158 String toString() => writer.toString(); | 1165 String toString() => writer.toString(); |
| 1159 | 1166 |
| 1160 } | 1167 } |
| OLD | NEW |