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

Unified Diff: pkg/analyzer_experimental/lib/src/services/formatter_impl.dart

Issue 26229004: Code formatter transform for empty constructor bodys (a la Style guide). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer_experimental/lib/src/services/formatter_impl.dart
===================================================================
--- pkg/analyzer_experimental/lib/src/services/formatter_impl.dart (revision 28369)
+++ pkg/analyzer_experimental/lib/src/services/formatter_impl.dart (working copy)
@@ -265,6 +265,14 @@
return true;
}
}
+ // Cons(){} => Cons();
+ if (isOPEN_CURLY_BRACKET(token1) && isCLOSE_CURLY_BRACKET(token1.next)) {
+ if (isSEMICOLON(token2)) {
+ token1 = token1.next;
+ advance();
+ return true;
+ }
+ }
// Advance past synthetic { } tokens
if (isOPEN_CURLY_BRACKET(token2) || isCLOSE_CURLY_BRACKET(token2)) {
token2 = token2.next;
@@ -311,12 +319,17 @@
bool isCLOSE_SQUARE_BRACKET(Token token) =>
tokenIs(token, TokenType.CLOSE_SQUARE_BRACKET);
+/// Test if this token is a SEMICOLON token.
+bool isSEMICOLON(Token token) =>
+ tokenIs(token, TokenType.SEMICOLON);
+
/// An AST visitor that drives formatting heuristics.
class SourceVisitor implements ASTVisitor {
static final OPEN_CURLY = syntheticToken(TokenType.OPEN_CURLY_BRACKET, '{');
static final CLOSE_CURLY = syntheticToken(TokenType.CLOSE_CURLY_BRACKET, '}');
+ static final SEMI_COLON = syntheticToken(TokenType.SEMICOLON, ';');
static const SYNTH_OFFSET = -13;
@@ -559,7 +572,16 @@
}
}
- visitPrefixedBody(space, node.body);
+ var body = node.body;
+ if (codeTransforms && body is BlockFunctionBody) {
+ if (body.block.statements.isEmpty) {
+ token(SEMI_COLON);
+ newlines();
+ return;
+ }
+ }
+
+ visitPrefixedBody(space, body);
}
visitConstructorInitializers(ConstructorDeclaration node) {
« no previous file with comments | « pkg/analyzer_experimental/bin/formatter.dart ('k') | pkg/analyzer_experimental/test/services/formatter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698