| 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/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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 visitNodes(node.metadata, followedBy: newlines); | 499 visitNodes(node.metadata, followedBy: newlines); |
| 500 modifier(node.abstractKeyword); | 500 modifier(node.abstractKeyword); |
| 501 token(node.classKeyword); | 501 token(node.classKeyword); |
| 502 space(); | 502 space(); |
| 503 visit(node.name); | 503 visit(node.name); |
| 504 allowContinuedLines((){ | 504 allowContinuedLines((){ |
| 505 visit(node.typeParameters); | 505 visit(node.typeParameters); |
| 506 visitNode(node.extendsClause, precededBy: space); | 506 visitNode(node.extendsClause, precededBy: space); |
| 507 visitNode(node.withClause, precededBy: space); | 507 visitNode(node.withClause, precededBy: space); |
| 508 visitNode(node.implementsClause, precededBy: space); | 508 visitNode(node.implementsClause, precededBy: space); |
| 509 visitNode(node.nativeClause, precededBy: space); |
| 509 space(); | 510 space(); |
| 510 }); | 511 }); |
| 511 token(node.leftBracket); | 512 token(node.leftBracket); |
| 512 indent(); | 513 indent(); |
| 513 visitNodes(node.members, precededBy: newlines, separatedBy: newlines); | 514 visitNodes(node.members, precededBy: newlines, separatedBy: newlines); |
| 514 unindent(); | 515 unindent(); |
| 515 newlines(); | 516 newlines(); |
| 516 token(node.rightBracket); | 517 token(node.rightBracket); |
| 517 } | 518 } |
| 518 | 519 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 visit(node.body); | 819 visit(node.body); |
| 819 } | 820 } |
| 820 | 821 |
| 821 visitFunctionDeclaration(FunctionDeclaration node) { | 822 visitFunctionDeclaration(FunctionDeclaration node) { |
| 822 preserveLeadingNewlines(); | 823 preserveLeadingNewlines(); |
| 823 visitNodes(node.metadata, followedBy: newlines); | 824 visitNodes(node.metadata, followedBy: newlines); |
| 824 modifier(node.externalKeyword); | 825 modifier(node.externalKeyword); |
| 825 //TODO(pquitslund): remove this workaround once setter functions | 826 //TODO(pquitslund): remove this workaround once setter functions |
| 826 //have their return types properly set (dartbug.com/15914) | 827 //have their return types properly set (dartbug.com/15914) |
| 827 if (node.returnType == null && node.propertyKeyword != null) { | 828 if (node.returnType == null && node.propertyKeyword != null) { |
| 828 modifier(node.propertyKeyword.previous); | 829 var previous = node.propertyKeyword.previous; |
| 830 if (previous is KeywordToken && previous.keyword == Keyword.VOID) { |
| 831 modifier(previous); |
| 832 } |
| 829 } else { | 833 } else { |
| 830 visitNode(node.returnType, followedBy: space); | 834 visitNode(node.returnType, followedBy: space); |
| 831 } | 835 } |
| 832 modifier(node.propertyKeyword); | 836 modifier(node.propertyKeyword); |
| 833 visit(node.name); | 837 visit(node.name); |
| 834 visit(node.functionExpression); | 838 visit(node.functionExpression); |
| 835 } | 839 } |
| 836 | 840 |
| 837 visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { | 841 visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { |
| 838 visit(node.functionDeclaration); | 842 visit(node.functionDeclaration); |
| 839 } | 843 } |
| 840 | 844 |
| 841 visitFunctionExpression(FunctionExpression node) { | 845 visitFunctionExpression(FunctionExpression node) { |
| 842 visit(node.parameters); | 846 visit(node.parameters); |
| 843 if (node.body is! EmptyFunctionBody) { | 847 if (node.body is! EmptyFunctionBody) { |
| 844 space(); | 848 space(); |
| 845 } | 849 } |
| 846 visit(node.body); | 850 visit(node.body); |
| 847 } | 851 } |
| 848 | 852 |
| 849 visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | 853 visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 850 visit(node.function); | 854 visit(node.function); |
| 851 visit(node.argumentList); | 855 visit(node.argumentList); |
| 852 } | 856 } |
| 853 | 857 |
| 854 visitFunctionTypeAlias(FunctionTypeAlias node) { | 858 visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 859 visitNodes(node.metadata, separatedBy: newlines, followedBy: newlines); |
| 855 token(node.keyword); | 860 token(node.keyword); |
| 856 space(); | 861 space(); |
| 857 visitNode(node.returnType, followedBy: space); | 862 visitNode(node.returnType, followedBy: space); |
| 858 visit(node.name); | 863 visit(node.name); |
| 859 visit(node.typeParameters); | 864 visit(node.typeParameters); |
| 860 visit(node.parameters); | 865 visit(node.parameters); |
| 861 token(node.semicolon); | 866 token(node.semicolon); |
| 862 } | 867 } |
| 863 | 868 |
| 864 visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | 869 visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 space(); | 1203 space(); |
| 1199 token(node.leftBracket); | 1204 token(node.leftBracket); |
| 1200 indent(); | 1205 indent(); |
| 1201 newlines(); | 1206 newlines(); |
| 1202 visitNodes(node.members, separatedBy: newlines, followedBy: newlines); | 1207 visitNodes(node.members, separatedBy: newlines, followedBy: newlines); |
| 1203 unindent(); | 1208 unindent(); |
| 1204 token(node.rightBracket); | 1209 token(node.rightBracket); |
| 1205 } | 1210 } |
| 1206 | 1211 |
| 1207 visitSymbolLiteral(SymbolLiteral node) { | 1212 visitSymbolLiteral(SymbolLiteral node) { |
| 1208 // No-op ? | 1213 token(node.poundSign); |
| 1214 var components = node.components; |
| 1215 var size = components.length; |
| 1216 for (var component in components) { |
| 1217 // The '.' separator |
| 1218 if (component.previous.lexeme == '.') { |
| 1219 token(component.previous); |
| 1220 } |
| 1221 token(component); |
| 1222 } |
| 1209 } | 1223 } |
| 1210 | 1224 |
| 1211 visitThisExpression(ThisExpression node) { | 1225 visitThisExpression(ThisExpression node) { |
| 1212 token(node.keyword); | 1226 token(node.keyword); |
| 1213 } | 1227 } |
| 1214 | 1228 |
| 1215 visitThrowExpression(ThrowExpression node) { | 1229 visitThrowExpression(ThrowExpression node) { |
| 1216 token(node.keyword); | 1230 token(node.keyword); |
| 1217 space(); | 1231 space(); |
| 1218 visit(node.expression); | 1232 visit(node.expression); |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1654 var lastLine = | 1668 var lastLine = |
| 1655 lineInfo.getLocation(lastOffset).lineNumber; | 1669 lineInfo.getLocation(lastOffset).lineNumber; |
| 1656 var currentLine = | 1670 var currentLine = |
| 1657 lineInfo.getLocation(currentOffset).lineNumber; | 1671 lineInfo.getLocation(currentOffset).lineNumber; |
| 1658 return currentLine - lastLine; | 1672 return currentLine - lastLine; |
| 1659 } | 1673 } |
| 1660 | 1674 |
| 1661 String toString() => writer.toString(); | 1675 String toString() => writer.toString(); |
| 1662 | 1676 |
| 1663 } | 1677 } |
| OLD | NEW |