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

Side by Side Diff: lib/src/source_visitor.dart

Issue 834353002: camelCase constants. Down with ALL_CAPS! (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 5 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 dart_style.src.source_visitor; 5 library dart_style.src.source_visitor;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/src/generated/scanner.dart'; 8 import 'package:analyzer/src/generated/scanner.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 10
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 zeroSplit(); 177 zeroSplit();
178 visit(node.condition); 178 visit(node.condition);
179 token(node.rightParenthesis); 179 token(node.rightParenthesis);
180 }); 180 });
181 } 181 }
182 182
183 visitAssignmentExpression(AssignmentExpression node) { 183 visitAssignmentExpression(AssignmentExpression node) {
184 visit(node.leftHandSide); 184 visit(node.leftHandSide);
185 space(); 185 space();
186 token(node.operator); 186 token(node.operator);
187 split(Cost.ASSIGNMENT); 187 split(Cost.assignment);
188 _writer.startSpan(); 188 _writer.startSpan();
189 visit(node.rightHandSide); 189 visit(node.rightHandSide);
190 _writer.endSpan(); 190 _writer.endSpan();
191 } 191 }
192 192
193 visitAwaitExpression(AwaitExpression node) { 193 visitAwaitExpression(AwaitExpression node) {
194 token(node.awaitKeyword); 194 token(node.awaitKeyword);
195 space(); 195 space();
196 visit(node.expression); 196 visit(node.expression);
197 } 197 }
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 visitCommaSeparatedNodes(node.typeParameters); 1236 visitCommaSeparatedNodes(node.typeParameters);
1237 token(node.rightBracket); 1237 token(node.rightBracket);
1238 } 1238 }
1239 1239
1240 visitVariableDeclaration(VariableDeclaration node) { 1240 visitVariableDeclaration(VariableDeclaration node) {
1241 visit(node.name); 1241 visit(node.name);
1242 if (node.initializer == null) return; 1242 if (node.initializer == null) return;
1243 1243
1244 space(); 1244 space();
1245 token(node.equals); 1245 token(node.equals);
1246 split(Cost.ASSIGNMENT); 1246 split(Cost.assignment);
1247 _writer.startSpan(); 1247 _writer.startSpan();
1248 visit(node.initializer); 1248 visit(node.initializer);
1249 _writer.endSpan(); 1249 _writer.endSpan();
1250 } 1250 }
1251 1251
1252 visitVariableDeclarationList(VariableDeclarationList node) { 1252 visitVariableDeclarationList(VariableDeclarationList node) {
1253 visitDeclarationMetadata(node.metadata); 1253 visitDeclarationMetadata(node.metadata);
1254 modifier(node.keyword); 1254 modifier(node.keyword);
1255 visit(node.type, after: space); 1255 visit(node.type, after: space);
1256 1256
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 /// 1550 ///
1551 /// Splits multiline strings into separate chunks so that the line splitter 1551 /// Splits multiline strings into separate chunks so that the line splitter
1552 /// can handle them correctly. 1552 /// can handle them correctly.
1553 void _writeStringLiteral(String string) { 1553 void _writeStringLiteral(String string) {
1554 // Split each line of a multiline string into separate chunks. 1554 // Split each line of a multiline string into separate chunks.
1555 var lines = string.split("\n"); 1555 var lines = string.split("\n");
1556 1556
1557 _writer.write(lines.first); 1557 _writer.write(lines.first);
1558 1558
1559 for (var line in lines.skip(1)) { 1559 for (var line in lines.skip(1)) {
1560 _writer.writeWhitespace(Whitespace.NEWLINE_FLUSH_LEFT); 1560 _writer.writeWhitespace(Whitespace.newlineFlushLeft);
1561 _writer.write(line); 1561 _writer.write(line);
1562 } 1562 }
1563 } 1563 }
1564 1564
1565 /// Emit the given [modifier] if it's non null, followed by non-breaking 1565 /// Emit the given [modifier] if it's non null, followed by non-breaking
1566 /// whitespace. 1566 /// whitespace.
1567 void modifier(Token modifier) { 1567 void modifier(Token modifier) {
1568 token(modifier, after: space); 1568 token(modifier, after: space);
1569 } 1569 }
1570 1570
1571 /// Emit a non-breaking space. 1571 /// Emit a non-breaking space.
1572 void space() { 1572 void space() {
1573 _writer.writeWhitespace(Whitespace.SPACE); 1573 _writer.writeWhitespace(Whitespace.space);
1574 } 1574 }
1575 1575
1576 /// Emit a single mandatory newline. 1576 /// Emit a single mandatory newline.
1577 void newline() { 1577 void newline() {
1578 _writer.writeWhitespace(Whitespace.NEWLINE); 1578 _writer.writeWhitespace(Whitespace.newline);
1579 } 1579 }
1580 1580
1581 /// Emit a two mandatory newlines. 1581 /// Emit a two mandatory newlines.
1582 void twoNewlines() { 1582 void twoNewlines() {
1583 _writer.writeWhitespace(Whitespace.TWO_NEWLINES); 1583 _writer.writeWhitespace(Whitespace.twoNewlines);
1584 } 1584 }
1585 1585
1586 /// Allow either a single space or newline to be emitted before the next 1586 /// Allow either a single space or newline to be emitted before the next
1587 /// non-whitespace token based on whether a newline exists in the source 1587 /// non-whitespace token based on whether a newline exists in the source
1588 /// between the last token and the next one. 1588 /// between the last token and the next one.
1589 void spaceOrNewline() { 1589 void spaceOrNewline() {
1590 _writer.writeWhitespace(Whitespace.SPACE_OR_NEWLINE); 1590 _writer.writeWhitespace(Whitespace.spaceOrNewline);
1591 } 1591 }
1592 1592
1593 /// Allow either one or two newlines to be emitted before the next 1593 /// Allow either one or two newlines to be emitted before the next
1594 /// non-whitespace token based on whether more than one newline exists in the 1594 /// non-whitespace token based on whether more than one newline exists in the
1595 /// source between the last token and the next one. 1595 /// source between the last token and the next one.
1596 void oneOrTwoNewlines() { 1596 void oneOrTwoNewlines() {
1597 _writer.writeWhitespace(Whitespace.ONE_OR_TWO_NEWLINES); 1597 _writer.writeWhitespace(Whitespace.oneOrTwoNewlines);
1598 } 1598 }
1599 1599
1600 /// Writes a single-space split with the given [cost]. 1600 /// Writes a single-space split with the given [cost].
1601 /// 1601 ///
1602 /// If [cost] is omitted, defaults to [Cost.NORMAL]. Returns the newly created 1602 /// If [cost] is omitted, defaults to [Cost.normal]. Returns the newly created
1603 /// [SplitParam]. 1603 /// [SplitParam].
1604 SplitParam split([int cost]) => _writer.writeSplit(cost: cost, space: true); 1604 SplitParam split([int cost]) => _writer.writeSplit(cost: cost, space: true);
1605 1605
1606 /// Writes a split that is the empty string when unsplit. 1606 /// Writes a split that is the empty string when unsplit.
1607 /// 1607 ///
1608 /// Returns the newly created [SplitParam]. 1608 /// Returns the newly created [SplitParam].
1609 SplitParam zeroSplit() => _writer.writeSplit(); 1609 SplitParam zeroSplit() => _writer.writeSplit();
1610 1610
1611 /// Emit [token], along with any comments and formatted whitespace that comes 1611 /// Emit [token], along with any comments and formatted whitespace that comes
1612 /// before it. 1612 /// before it.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 /// Gets the 1-based line number that the beginning of [token] lies on. 1674 /// Gets the 1-based line number that the beginning of [token] lies on.
1675 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber; 1675 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber;
1676 1676
1677 /// Gets the 1-based line number that the end of [token] lies on. 1677 /// Gets the 1-based line number that the end of [token] lies on.
1678 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber; 1678 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber;
1679 1679
1680 /// Gets the 1-based column number that the beginning of [token] lies on. 1680 /// Gets the 1-based column number that the beginning of [token] lies on.
1681 int _startColumn(Token token) => 1681 int _startColumn(Token token) =>
1682 _lineInfo.getLocation(token.offset).columnNumber; 1682 _lineInfo.getLocation(token.offset).columnNumber;
1683 } 1683 }
OLDNEW
« example/format.dart ('K') | « lib/src/nesting.dart ('k') | lib/src/whitespace.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698