| OLD | NEW |
| 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 /// Internal debugging utilities. | 5 /// Internal debugging utilities. |
| 6 library dart_style.src.debug; | 6 library dart_style.src.debug; |
| 7 | 7 |
| 8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'chunk.dart'; | 10 import 'chunk.dart'; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 /// Wraps [message] in bold ANSI escape codes if enabled. | 64 /// Wraps [message] in bold ANSI escape codes if enabled. |
| 65 String bold(message) => "$_bold$message$_none"; | 65 String bold(message) => "$_bold$message$_none"; |
| 66 | 66 |
| 67 /// Prints [chunks] to stdout, one chunk per line, with detailed information | 67 /// Prints [chunks] to stdout, one chunk per line, with detailed information |
| 68 /// about each chunk. | 68 /// about each chunk. |
| 69 void dumpChunks(int start, List<Chunk> chunks) { | 69 void dumpChunks(int start, List<Chunk> chunks) { |
| 70 if (chunks.skip(start).isEmpty) return; | 70 if (chunks.skip(start).isEmpty) return; |
| 71 | 71 |
| 72 // Show the spans as vertical bands over their range (unless there are too | 72 // Show the spans as vertical bands over their range (unless there are too |
| 73 // many). | 73 // many). |
| 74 var spans = new Set(); | 74 var spanSet = new Set<Span>(); |
| 75 addSpans(chunks) { | 75 addSpans(List<Chunk> chunks) { |
| 76 for (var chunk in chunks) { | 76 for (var chunk in chunks) { |
| 77 spans.addAll(chunk.spans); | 77 spanSet.addAll(chunk.spans); |
| 78 | 78 |
| 79 if (chunk.isBlock) addSpans(chunk.block.chunks); | 79 if (chunk.isBlock) addSpans(chunk.block.chunks); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 addSpans(chunks); | 83 addSpans(chunks); |
| 84 | 84 |
| 85 spans = spans.toList(); | 85 var spans = spanSet.toList(); |
| 86 | |
| 87 var rules = | 86 var rules = |
| 88 chunks.map((chunk) => chunk.rule).where((rule) => rule != null).toSet(); | 87 chunks.map((chunk) => chunk.rule).where((rule) => rule != null).toSet(); |
| 89 | 88 |
| 90 var rows = []; | 89 var rows = <List<String>>[]; |
| 91 | 90 |
| 92 addChunk(List<Chunk> chunks, String prefix, int index) { | 91 addChunk(List<Chunk> chunks, String prefix, int index) { |
| 93 var row = []; | 92 var row = <String>[]; |
| 94 row.add("$prefix$index:"); | 93 row.add("$prefix$index:"); |
| 95 | 94 |
| 96 var chunk = chunks[index]; | 95 var chunk = chunks[index]; |
| 97 if (chunk.text.length > 70) { | 96 if (chunk.text.length > 70) { |
| 98 row.add(chunk.text.substring(0, 70)); | 97 row.add(chunk.text.substring(0, 70)); |
| 99 } else { | 98 } else { |
| 100 row.add(chunk.text); | 99 row.add(chunk.text); |
| 101 } | 100 } |
| 102 | 101 |
| 103 if (spans.length <= 20) { | 102 if (spans.length <= 20) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 253 |
| 255 if (chunk.spaceWhenUnsplit) buffer.write(" "); | 254 if (chunk.spaceWhenUnsplit) buffer.write(" "); |
| 256 } | 255 } |
| 257 } | 256 } |
| 258 | 257 |
| 259 buffer.write(chunks.last.text); | 258 buffer.write(chunks.last.text); |
| 260 log(buffer); | 259 log(buffer); |
| 261 } | 260 } |
| 262 | 261 |
| 263 String _color(String ansiEscape) => useAnsiColors ? ansiEscape : ""; | 262 String _color(String ansiEscape) => useAnsiColors ? ansiEscape : ""; |
| OLD | NEW |