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

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

Issue 1355203002: Handle index expressions in the middle of call chains. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Handle chained indexes. Created 5 years, 3 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
« no previous file with comments | « lib/src/call_chain_visitor.dart ('k') | test/regression/other/analysis_server.unit » ('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) 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 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 1005
1006 visitIndexExpression(IndexExpression node) { 1006 visitIndexExpression(IndexExpression node) {
1007 builder.nestExpression(); 1007 builder.nestExpression();
1008 1008
1009 if (node.isCascaded) { 1009 if (node.isCascaded) {
1010 token(node.period); 1010 token(node.period);
1011 } else { 1011 } else {
1012 visit(node.target); 1012 visit(node.target);
1013 } 1013 }
1014 1014
1015 finishIndexExpression(node);
1016
1017 builder.unnest();
1018 }
1019
1020 /// Visit the index part of [node], excluding the target.
1021 ///
1022 /// Called by [CallChainVisitor] to handle index expressions in the middle of
1023 /// call chains.
1024 void finishIndexExpression(IndexExpression node) {
1015 if (node.target is IndexExpression) { 1025 if (node.target is IndexExpression) {
1016 // Corner case: On a chain of [] accesses, allow splitting between them. 1026 // Edge case: On a chain of [] accesses, allow splitting between them.
1017 // Produces nicer output in cases like: 1027 // Produces nicer output in cases like:
1018 // 1028 //
1019 // someJson['property']['property']['property']['property']... 1029 // someJson['property']['property']['property']['property']...
1020 soloZeroSplit(); 1030 soloZeroSplit();
1021 } 1031 }
1022 1032
1023 builder.startSpan(); 1033 builder.startSpan();
1024 token(node.leftBracket); 1034 token(node.leftBracket);
1025 soloZeroSplit(); 1035 soloZeroSplit();
1026 visit(node.index); 1036 visit(node.index);
1027 token(node.rightBracket); 1037 token(node.rightBracket);
1028 builder.endSpan(); 1038 builder.endSpan();
1029 builder.unnest();
1030 } 1039 }
1031 1040
1032 visitInstanceCreationExpression(InstanceCreationExpression node) { 1041 visitInstanceCreationExpression(InstanceCreationExpression node) {
1033 builder.startSpan(); 1042 builder.startSpan();
1034 token(node.keyword); 1043 token(node.keyword);
1035 space(); 1044 space();
1036 builder.startSpan(Cost.constructorName); 1045 builder.startSpan(Cost.constructorName);
1037 visit(node.constructorName); 1046 visit(node.constructorName);
1038 builder.endSpan(); 1047 builder.endSpan();
1039 visit(node.argumentList); 1048 visit(node.argumentList);
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after
2159 /// Gets the 1-based line number that the beginning of [token] lies on. 2168 /// Gets the 1-based line number that the beginning of [token] lies on.
2160 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber; 2169 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber;
2161 2170
2162 /// Gets the 1-based line number that the end of [token] lies on. 2171 /// Gets the 1-based line number that the end of [token] lies on.
2163 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber; 2172 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber;
2164 2173
2165 /// Gets the 1-based column number that the beginning of [token] lies on. 2174 /// Gets the 1-based column number that the beginning of [token] lies on.
2166 int _startColumn(Token token) => 2175 int _startColumn(Token token) =>
2167 _lineInfo.getLocation(token.offset).columnNumber; 2176 _lineInfo.getLocation(token.offset).columnNumber;
2168 } 2177 }
OLDNEW
« no previous file with comments | « lib/src/call_chain_visitor.dart ('k') | test/regression/other/analysis_server.unit » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698