| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.line_splitting.solve_state; | 5 library dart_style.src.line_splitting.solve_state; |
| 6 | 6 |
| 7 import '../debug.dart' as debug; | 7 import '../debug.dart' as debug; |
| 8 import '../rule/rule.dart'; | 8 import '../rule/rule.dart'; |
| 9 import 'line_splitter.dart'; | 9 import 'line_splitter.dart'; |
| 10 import 'rule_set.dart'; | 10 import 'rule_set.dart'; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 } | 211 } |
| 212 | 212 |
| 213 /// Returns `true` if [other] overlaps this state. | 213 /// Returns `true` if [other] overlaps this state. |
| 214 bool _isOverlapping(SolveState other) { | 214 bool _isOverlapping(SolveState other) { |
| 215 _ensureOverlapFields(); | 215 _ensureOverlapFields(); |
| 216 other._ensureOverlapFields(); | 216 other._ensureOverlapFields(); |
| 217 | 217 |
| 218 // Lines that contain both bound and unbound rules must have the same | 218 // Lines that contain both bound and unbound rules must have the same |
| 219 // bound values. | 219 // bound values. |
| 220 if (_boundRulesInUnboundLines.length != | 220 if (_boundRulesInUnboundLines.length != |
| 221 other._boundRulesInUnboundLines.length) { | 221 other._boundRulesInUnboundLines.length) { |
| 222 return false; | 222 return false; |
| 223 } | 223 } |
| 224 | 224 |
| 225 for (var rule in _boundRulesInUnboundLines) { | 225 for (var rule in _boundRulesInUnboundLines) { |
| 226 if (!other._boundRulesInUnboundLines.contains(rule)) return false; | 226 if (!other._boundRulesInUnboundLines.contains(rule)) return false; |
| 227 if (_ruleValues.getValue(rule) != other._ruleValues.getValue(rule)) { | 227 if (_ruleValues.getValue(rule) != other._ruleValues.getValue(rule)) { |
| 228 return false; | 228 return false; |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 | 231 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 } | 408 } |
| 409 } | 409 } |
| 410 | 410 |
| 411 void _calculateBoundRulesInUnboundLines() { | 411 void _calculateBoundRulesInUnboundLines() { |
| 412 _boundRulesInUnboundLines = new Set(); | 412 _boundRulesInUnboundLines = new Set(); |
| 413 | 413 |
| 414 var boundInLine = new Set(); | 414 var boundInLine = new Set(); |
| 415 var hasUnbound = false; | 415 var hasUnbound = false; |
| 416 | 416 |
| 417 for (var i = 0; i < _splitter.chunks.length - 1; i++) { | 417 for (var i = 0; i < _splitter.chunks.length - 1; i++) { |
| 418 | |
| 419 if (splits.shouldSplitAt(i)) { | 418 if (splits.shouldSplitAt(i)) { |
| 420 if (hasUnbound) _boundRulesInUnboundLines.addAll(boundInLine); | 419 if (hasUnbound) _boundRulesInUnboundLines.addAll(boundInLine); |
| 421 | 420 |
| 422 boundInLine.clear(); | 421 boundInLine.clear(); |
| 423 hasUnbound = false; | 422 hasUnbound = false; |
| 424 } | 423 } |
| 425 | 424 |
| 426 var rule = _splitter.chunks[i].rule; | 425 var rule = _splitter.chunks[i].rule; |
| 427 if (rule != null && rule is! HardSplitRule) { | 426 if (rule != null && rule is! HardSplitRule) { |
| 428 if (_ruleValues.contains(rule)) { | 427 if (_ruleValues.contains(rule)) { |
| 429 boundInLine.add(rule); | 428 boundInLine.add(rule); |
| 430 } else { | 429 } else { |
| 431 hasUnbound = true; | 430 hasUnbound = true; |
| 432 } | 431 } |
| 433 } | 432 } |
| 434 } | 433 } |
| 435 | 434 |
| 436 if (hasUnbound) _boundRulesInUnboundLines.addAll(boundInLine); | 435 if (hasUnbound) _boundRulesInUnboundLines.addAll(boundInLine); |
| 437 } | 436 } |
| 438 | 437 |
| 439 String toString() { | 438 String toString() { |
| 440 var buffer = new StringBuffer(); | 439 var buffer = new StringBuffer(); |
| 441 | 440 |
| 442 buffer.writeAll( | 441 buffer.writeAll(_splitter.rules.map((rule) { |
| 443 _splitter.rules.map((rule) { | 442 var valueLength = "${rule.fullySplitValue}".length; |
| 444 var valueLength = "${rule.fullySplitValue}".length; | |
| 445 | 443 |
| 446 var value = "?"; | 444 var value = "?"; |
| 447 if (_ruleValues.contains(rule)) { | 445 if (_ruleValues.contains(rule)) { |
| 448 value = "${_ruleValues.getValue(rule)}"; | 446 value = "${_ruleValues.getValue(rule)}"; |
| 449 } | 447 } |
| 450 | 448 |
| 451 value = value.padLeft(valueLength); | 449 value = value.padLeft(valueLength); |
| 452 if (_liveRules.contains(rule)) { | 450 if (_liveRules.contains(rule)) { |
| 453 value = debug.bold(value); | 451 value = debug.bold(value); |
| 454 } else { | 452 } else { |
| 455 value = debug.gray(value); | 453 value = debug.gray(value); |
| 456 } | 454 } |
| 457 | 455 |
| 458 return value; | 456 return value; |
| 459 }), | 457 }), " "); |
| 460 " "); | |
| 461 | 458 |
| 462 buffer.write(" \$${splits.cost}"); | 459 buffer.write(" \$${splits.cost}"); |
| 463 | 460 |
| 464 if (overflowChars > 0) buffer.write(" (${overflowChars} over)"); | 461 if (overflowChars > 0) buffer.write(" (${overflowChars} over)"); |
| 465 if (!_isComplete) buffer.write(" (incomplete)"); | 462 if (!_isComplete) buffer.write(" (incomplete)"); |
| 466 if (splits == null) buffer.write(" invalid"); | 463 if (splits == null) buffer.write(" invalid"); |
| 467 | 464 |
| 468 return buffer.toString(); | 465 return buffer.toString(); |
| 469 } | 466 } |
| 470 } | 467 } |
| OLD | NEW |