Linter Demo Errors: 0Warnings: 27File: /home/fstrocco/Dart/dart/benchmark/compiler/lib/src/helpers/debug_collection.dart // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. part of dart2js.helpers; typedef void DebugCallback(String methodName, var arg1, var arg2); class DebugMap implements Map { final Map map; DebugCallback indexSetCallBack; DebugCallback putIfAbsentCallBack; DebugMap(this.map, {DebugCallback addCallback}) { if (addCallback != null) { this.addCallback = addCallback; } } void set addCallback(DebugCallback value) { indexSetCallBack = value; putIfAbsentCallBack = value; } bool containsValue(Object value) { return map.containsValue(value); } bool containsKey(Object key) => map.containsKey(key); V operator [](Object key) => map[key]; void operator []=(K key, V value) { if (indexSetCallBack != null) { indexSetCallBack('[]=', key, value); } map[key] = value; } V putIfAbsent(K key, V ifAbsent()) { return map.putIfAbsent(key, () { V v = ifAbsent(); if (putIfAbsentCallBack != null) { putIfAbsentCallBack('putIfAbsent', key, v); } return v; }); } void addAll(Map other) => map.addAll(other); V remove(Object key) => map.remove(key); void clear() => map.clear(); void forEach(void f(K key, V value)) => map.forEach(f); Iterable get keys => map.keys; Iterable get values => map.values; int get length => map.length; bool get isEmpty => map.isEmpty; bool get isNotEmpty => map.isNotEmpty; } class DebugIterable implements Iterable { final Iterable iterable; DebugIterable(this.iterable); Iterator get iterator => iterable.iterator; Iterable map(f(E element)) => iterable.map(f); Iterable where(bool test(E element)) => iterable.where(test); Iterable expand(Iterable f(E element)) => iterable.expand(f); bool contains(Object element) => iterable.contains(element); void forEach(void f(E element)) => iterable.forEach(f); E reduce(E combine(E value, E element)) => iterable.reduce(combine); dynamic fold(var initialValue, dynamic combine(var previousValue, E element)) { return iterable.fold(initialValue, combine); } bool every(bool test(E element)) => iterable.every(test); String join([String separator = ""]) => iterable.join(separator); bool any(bool test(E element)) => iterable.any(test); List toList({ bool growable: true }) { return iterable.toList(growable: growable); } Set toSet() => iterable.toSet(); int get length => iterable.length; bool get isEmpty => iterable.isEmpty; bool get isNotEmpty => iterable.isNotEmpty; Iterable take(int n) => iterable.take(n); Iterable takeWhile(bool test(E value)) => iterable.takeWhile(test); Iterable skip(int n) => iterable.skip(n); Iterable skipWhile(bool test(E value)) => iterable.skipWhile(test); E get first => iterable.first; E get last => iterable.last; E get single => iterable.single; E firstWhere(bool test(E element), { E orElse() }) { return iterable.firstWhere(test, orElse: orElse); } E lastWhere(bool test(E element), {E orElse()}) { return iterable.lastWhere(test, orElse: orElse); } E singleWhere(bool test(E element)) => iterable.singleWhere(test); E elementAt(int index) => iterable.elementAt(index); } class DebugList extends DebugIterable implements List { DebugCallback addCallback; DebugList(List list, {this.addCallback}) : super(list); List get list => iterable; E operator [](int index) => list[index]; void operator []=(int index, E value) { list[index] = value; } int get length => list.length; void set length(int newLength) { list.length = newLength; } void add(E value) { if (addCallback != null) { addCallback('add', value, null); } list.add(value); } void addAll(Iterable iterable) => list.addAll(iterable); Iterable get reversed => list.reversed; void sort([int compare(E a, E b)]) => list.sort(compare); void shuffle([random]) => list.shuffle(random); int indexOf(E element, [int start = 0]) => list.indexOf(element, start); int lastIndexOf(E element, [int start]) => list.lastIndexOf(element, start); void clear() => list.clear(); void insert(int index, E element) => list.insert(index, element); void insertAll(int index, Iterable iterable) { list.insertAll(index, iterable); } void setAll(int index, Iterable iterable) => list.setAll(index, iterable); bool remove(Object value) => list.remove(value); E removeAt(int index) => list.removeAt(index); E removeLast() => list.removeLast(); void removeWhere(bool test(E element)) => list.removeWhere(test); void retainWhere(bool test(E element)) => list.retainWhere(test); List sublist(int start, [int end]) => list.sublist(start, end); Iterable getRange(int start, int end) => list.getRange(start, end); void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { list.setRange(start, end, iterable, skipCount); } void removeRange(int start, int end) { list.removeRange(start, end); } void fillRange(int start, int end, [E fillValue]) { list.fillRange(start, end, fillValue); } void replaceRange(int start, int end, Iterable replacement) { list.replaceRange(start, end, replacement); } Map asMap() => list.asMap(); } class DebugSet extends DebugIterable implements Set { DebugCallback addCallback; DebugSet(Set set, {this.addCallback}) : super(set); Set get set => iterable; bool contains(Object value) => set.contains(value); bool add(E value) { if (addCallback != null) { addCallback('add', value, null); } return set.add(value); } void addAll(Iterable elements) => set.addAll(elements); bool remove(Object value) => set.remove(value); E lookup(Object object) => set.lookup(object); void removeAll(Iterable elements) => set.removeAll(elements); void retainAll(Iterable elements) => set.retainAll(elements); void removeWhere(bool test(E element)) => set.removeWhere(test); void retainWhere(bool test(E element)) => set.retainWhere(test); bool containsAll(Iterable other) => set.containsAll(other); Set intersection(Set other) => set.intersection(other); Set union(Set other) => set.union(other); Set difference(Set other) => set.difference(other); void clear() => set.clear(); Set toSet() => set.toSet(); } /// Throws an exception if the runtime type of [object] is not in /// [runtimeTypes]. /// /// Use this to gradually build the set of actual runtime values of [object] /// at the call site by running test programs and adding to [runtimeTypes] when /// new type are found. void assertType(String name, List runtimeTypes, var object, {bool showObjects: false}) { String runtimeType = '${object.runtimeType}'; if (runtimeTypes != null && runtimeTypes.contains(runtimeType)) return; throw '$name: $runtimeType' '${showObjects ? ' ($object)' : ''}'; } /// Callback for the [addCallback] of [DebugMap] that throws an exception if /// the runtime type of key/value pairs are not in [runtimeTypes]. /// /// Use this to gradually build the set of actual runtime values of key/value /// pairs of a map by running test programs and adding to [runtimeTypes] when /// new type are found. class MapTypeAsserter { final String name; final Map> runtimeTypes; final bool showObjects; const MapTypeAsserter(this.name, this.runtimeTypes, {bool this.showObjects: false}); void call(String methodName, var key, var value) { check(key, value, '$methodName: '); } void check(var key, var value, [String text = '']) { String keyType = '${key.runtimeType}'; String valueType = '${value.runtimeType}'; List valuesTypes = runtimeTypes[keyType]; if (valuesTypes != null && valuesTypes.contains(valueType)) return; throw '$name: $text$keyType => $valueType' '${showObjects ? ' ($key => $value)' : ''}'; } } /// Callback for the [addCallback] of [DebugSet] or [DebugList] that throws an /// exception if the runtime type of the elements are not in [runtimeTypes]. /// /// Use this to gradually build the set of actual runtime values of the elements /// of a collection by running test programs and adding to [runtimeTypes] when /// new type are found. class CollectionTypeAsserter { final String name; final List runtimeTypes; final bool showObjects; const CollectionTypeAsserter(this.name, this.runtimeTypes, {bool this.showObjects: false}); void call(String methodName, var element, _) { check(element, '$methodName: '); } void check(var element, [String text = '']) { String elementType = '${element.runtimeType}'; if (runtimeTypes.contains(elementType)) return; throw '$name: $text$elementType' '${showObjects ? ' ($element)' : ''}'; } }