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

Unified Diff: packages/analyzer/lib/src/generated/utilities_general.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: packages/analyzer/lib/src/generated/utilities_general.dart
diff --git a/packages/analyzer/lib/src/generated/utilities_general.dart b/packages/analyzer/lib/src/generated/utilities_general.dart
index d120a81abdd6e0a9b12554d53bbb5c556f21071f..b9dca93c681bf8f7f9f51d12122a44e30e9ec685 100644
--- a/packages/analyzer/lib/src/generated/utilities_general.dart
+++ b/packages/analyzer/lib/src/generated/utilities_general.dart
@@ -2,10 +2,53 @@
// 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.
-library engine.utilities.general;
+library analyzer.src.generated.utilities_general;
+import 'dart:collection';
import 'dart:developer' show UserTag;
+/**
+ * Test if the given [value] is `false` or the string "false" (case-insensitive).
+ */
+bool isFalse(Object value) =>
+ value is bool ? !value : toLowerCase(value) == 'false';
+
+/**
+ * Test if the given [value] is `true` or the string "true" (case-insensitive).
+ */
+bool isTrue(Object value) =>
+ value is bool ? value : toLowerCase(value) == 'true';
+
+/**
+ * Safely convert the given [value] to a bool value, or return `null` if the
+ * value coult not be converted.
+ */
+bool toBool(Object value) {
+ if (value is bool) {
+ return value;
+ }
+ String string = toLowerCase(value);
+ if (string == 'true') {
+ return true;
+ }
+ if (string == 'false') {
+ return false;
+ }
+ return null;
+}
+
+/**
+ * Safely convert this [value] to lower case, returning `null` if [value] is
+ * null.
+ */
+String toLowerCase(Object value) => value?.toString()?.toLowerCase();
+
+/**
+ * Safely convert this [value] to upper case, returning `null` if [value] is
+ * null.
+ */
+String toUpperCase(Object value) => value?.toString()?.toUpperCase();
+
/**
* Jenkins hash function, optimized for small integers.
* Borrowed from sdk/lib/math/jenkins_smi_hash.dart.
@@ -31,6 +74,26 @@ class JenkinsSmiHash {
finish(combine(combine(combine(combine(0, a), b), c), d));
}
+/**
+ * A simple limited queue.
+ */
+class LimitedQueue<E> extends ListQueue<E> {
+ final int limit;
+
+ /**
+ * Create a queue with [limit] items.
+ */
+ LimitedQueue(this.limit);
+
+ @override
+ void add(E o) {
+ super.add(o);
+ while (length > limit) {
+ remove(first);
+ }
+ }
+}
+
/**
* Helper class for gathering performance statistics. This class is modeled on
* the UserTag class in dart:developer so that it can interoperate easily with
@@ -82,7 +145,7 @@ abstract class PerformanceTag {
* Make this the current tag for the isolate, run [f], and restore the
* previous tag. Returns the result of invoking [f].
*/
- makeCurrentWhile(f());
+ dynamic/*=E*/ makeCurrentWhile/*<E>*/(dynamic/*=E*/ f());
/**
* Reset the total time tracked by all [PerformanceTag]s to zero.
@@ -143,7 +206,7 @@ class _PerformanceTagImpl implements PerformanceTag {
return previous;
}
- makeCurrentWhile(f()) {
+ dynamic/*=E*/ makeCurrentWhile/*<E>*/(dynamic/*=E*/ f()) {
PerformanceTag prevTag = makeCurrent();
try {
return f();
« no previous file with comments | « packages/analyzer/lib/src/generated/utilities_dart.dart ('k') | packages/analyzer/lib/src/generated/visitors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698