| 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 library analyzer.src.generated.java_core; | 5 library analyzer.src.generated.java_core; |
| 6 | 6 |
| 7 const int LONG_MAX_VALUE = 0x7fffffffffffffff; | |
| 8 | |
| 9 final Stopwatch nanoTimeStopwatch = new Stopwatch(); | 7 final Stopwatch nanoTimeStopwatch = new Stopwatch(); |
| 10 | 8 |
| 11 /** | 9 /** |
| 12 * Inserts the given arguments into [pattern]. | 10 * Inserts the given arguments into [pattern]. |
| 13 * | 11 * |
| 14 * format('Hello, {0}!', 'John') = 'Hello, John!' | 12 * format('Hello, {0}!', 'John') = 'Hello, John!' |
| 15 * format('{0} are you {1}ing?', 'How', 'do') = 'How are you doing?' | 13 * format('{0} are you {1}ing?', 'How', 'do') = 'How are you doing?' |
| 16 * format('{0} are you {1}ing?', 'What', 'read') = 'What are you reading?' | 14 * format('{0} are you {1}ing?', 'What', 'read') = 'What are you reading?' |
| 17 */ | 15 */ |
| 18 String format(String pattern, | 16 String format(String pattern, |
| 19 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7]) { | 17 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7]) { |
| 18 // TODO(rnystrom): This is not used by analyzer, but is called by |
| 19 // analysis_server. Move this code there and remove it from here. |
| 20 return formatList(pattern, [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7]); | 20 return formatList(pattern, [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7]); |
| 21 } | 21 } |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Inserts the given [args] into [pattern]. | 24 * Inserts the given [args] into [pattern]. |
| 25 * | 25 * |
| 26 * format('Hello, {0}!', ['John']) = 'Hello, John!' | 26 * format('Hello, {0}!', ['John']) = 'Hello, John!' |
| 27 * format('{0} are you {1}ing?', ['How', 'do']) = 'How are you doing?' | 27 * format('{0} are you {1}ing?', ['How', 'do']) = 'How are you doing?' |
| 28 * format('{0} are you {1}ing?', ['What', 'read']) = 'What are you reading?' | 28 * format('{0} are you {1}ing?', ['What', 'read']) = 'What are you reading?' |
| 29 */ | 29 */ |
| 30 String formatList(String pattern, List<Object> arguments) { | 30 String formatList(String pattern, List<Object> arguments) { |
| 31 if (arguments == null || arguments.isEmpty) { | 31 if (arguments == null || arguments.isEmpty) { |
| 32 assert(!pattern.contains(new RegExp(r'\{(\d+)\}'))); | 32 assert(!pattern.contains(new RegExp(r'\{(\d+)\}'))); |
| 33 return pattern; | 33 return pattern; |
| 34 } | 34 } |
| 35 return pattern.replaceAllMapped(new RegExp(r'\{(\d+)\}'), (match) { | 35 return pattern.replaceAllMapped(new RegExp(r'\{(\d+)\}'), (match) { |
| 36 String indexStr = match.group(1); | 36 String indexStr = match.group(1); |
| 37 int index = int.parse(indexStr); | 37 int index = int.parse(indexStr); |
| 38 Object arg = arguments[index]; | 38 Object arg = arguments[index]; |
| 39 assert(arg != null); | 39 assert(arg != null); |
| 40 return arg != null ? arg.toString() : null; | 40 return arg != null ? arg.toString() : null; |
| 41 }); | 41 }); |
| 42 } | 42 } |
| 43 | 43 |
| 44 bool javaCollectionContainsAll(Iterable list, Iterable c) { | |
| 45 return c.fold(true, (bool prev, e) => prev && list.contains(e)); | |
| 46 } | |
| 47 | |
| 48 javaListSet(List list, int index, newValue) { | |
| 49 var oldValue = list[index]; | |
| 50 list[index] = newValue; | |
| 51 return oldValue; | |
| 52 } | |
| 53 | |
| 54 bool javaSetEquals(Set a, Set b) { | |
| 55 return a.containsAll(b) && b.containsAll(a); | |
| 56 } | |
| 57 | |
| 58 bool javaStringEqualsIgnoreCase(String a, String b) { | |
| 59 return a.toLowerCase() == b.toLowerCase(); | |
| 60 } | |
| 61 | |
| 62 bool javaStringRegionMatches( | |
| 63 String t, int toffset, String o, int ooffset, int len) { | |
| 64 if (toffset < 0) return false; | |
| 65 if (ooffset < 0) return false; | |
| 66 var tend = toffset + len; | |
| 67 var oend = ooffset + len; | |
| 68 if (tend > t.length) return false; | |
| 69 if (oend > o.length) return false; | |
| 70 return t.substring(toffset, tend) == o.substring(ooffset, oend); | |
| 71 } | |
| 72 | |
| 73 /// Parses given string to [Uri], throws [URISyntaxException] if invalid. | 44 /// Parses given string to [Uri], throws [URISyntaxException] if invalid. |
| 74 Uri parseUriWithException(String str) { | 45 Uri parseUriWithException(String str) { |
| 75 Uri uri; | 46 Uri uri; |
| 76 try { | 47 try { |
| 77 uri = Uri.parse(str); | 48 uri = Uri.parse(str); |
| 78 } on FormatException catch (e) { | 49 } on FormatException catch (e) { |
| 79 throw new URISyntaxException(e.toString()); | 50 throw new URISyntaxException(e.toString()); |
| 80 } | 51 } |
| 81 if (uri.path.isEmpty) { | 52 if (uri.path.isEmpty) { |
| 82 throw new URISyntaxException('empty path'); | 53 throw new URISyntaxException('empty path'); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 94 } |
| 124 return sb.toString(); | 95 return sb.toString(); |
| 125 } | 96 } |
| 126 | 97 |
| 127 class Character { | 98 class Character { |
| 128 static const int MAX_VALUE = 0xffff; | 99 static const int MAX_VALUE = 0xffff; |
| 129 static const int MAX_CODE_POINT = 0x10ffff; | 100 static const int MAX_CODE_POINT = 0x10ffff; |
| 130 static const int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000; | 101 static const int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000; |
| 131 static const int MIN_LOW_SURROGATE = 0xDC00; | 102 static const int MIN_LOW_SURROGATE = 0xDC00; |
| 132 static const int MIN_HIGH_SURROGATE = 0xD800; | 103 static const int MIN_HIGH_SURROGATE = 0xD800; |
| 104 |
| 133 static int digit(int codePoint, int radix) { | 105 static int digit(int codePoint, int radix) { |
| 134 if (radix != 16) { | 106 if (radix != 16) { |
| 135 throw new ArgumentError("only radix == 16 is supported"); | 107 throw new ArgumentError("only radix == 16 is supported"); |
| 136 } | 108 } |
| 137 if (0x30 <= codePoint && codePoint <= 0x39) { | 109 if (0x30 <= codePoint && codePoint <= 0x39) { |
| 138 return codePoint - 0x30; | 110 return codePoint - 0x30; |
| 139 } | 111 } |
| 140 if (0x41 <= codePoint && codePoint <= 0x46) { | 112 if (0x41 <= codePoint && codePoint <= 0x46) { |
| 141 return 0xA + (codePoint - 0x41); | 113 return 0xA + (codePoint - 0x41); |
| 142 } | 114 } |
| 143 if (0x61 <= codePoint && codePoint <= 0x66) { | 115 if (0x61 <= codePoint && codePoint <= 0x66) { |
| 144 return 0xA + (codePoint - 0x61); | 116 return 0xA + (codePoint - 0x61); |
| 145 } | 117 } |
| 146 return -1; | 118 return -1; |
| 147 } | 119 } |
| 148 | 120 |
| 149 static bool isDigit(int c) { | 121 static bool isDigit(int c) => c >= 0x30 && c <= 0x39; |
| 150 return c >= 0x30 && c <= 0x39; | |
| 151 } | |
| 152 | 122 |
| 153 static bool isLetter(int c) { | 123 static bool isLetter(int c) => |
| 154 return c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A; | 124 c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A; |
| 155 } | |
| 156 | 125 |
| 157 static bool isLetterOrDigit(int c) { | 126 static bool isLetterOrDigit(int c) => isLetter(c) || isDigit(c); |
| 158 return isLetter(c) || isDigit(c); | |
| 159 } | |
| 160 | 127 |
| 161 static bool isLowerCase(int c) { | 128 static bool isWhitespace(int c) => |
| 162 return c >= 0x61 && c <= 0x7A; | 129 c == 0x09 || c == 0x20 || c == 0x0A || c == 0x0D; |
| 163 } | |
| 164 | |
| 165 static bool isUpperCase(int c) { | |
| 166 return c >= 0x41 && c <= 0x5A; | |
| 167 } | |
| 168 | |
| 169 static bool isWhitespace(int c) { | |
| 170 return c == 0x09 || c == 0x20 || c == 0x0A || c == 0x0D; | |
| 171 } | |
| 172 | 130 |
| 173 static String toChars(int codePoint) { | 131 static String toChars(int codePoint) { |
| 174 if (codePoint < 0 || codePoint > MAX_CODE_POINT) { | 132 if (codePoint < 0 || codePoint > MAX_CODE_POINT) { |
| 175 throw new IllegalArgumentException(); | 133 throw new IllegalArgumentException(); |
| 176 } | 134 } |
| 177 if (codePoint < MIN_SUPPLEMENTARY_CODE_POINT) { | 135 if (codePoint < MIN_SUPPLEMENTARY_CODE_POINT) { |
| 178 return new String.fromCharCode(codePoint); | 136 return new String.fromCharCode(codePoint); |
| 179 } | 137 } |
| 180 int offset = codePoint - MIN_SUPPLEMENTARY_CODE_POINT; | 138 int offset = codePoint - MIN_SUPPLEMENTARY_CODE_POINT; |
| 181 int c0 = ((offset & 0x7FFFFFFF) >> 10) + MIN_HIGH_SURROGATE; | 139 int c0 = ((offset & 0x7FFFFFFF) >> 10) + MIN_HIGH_SURROGATE; |
| 182 int c1 = (offset & 0x3ff) + MIN_LOW_SURROGATE; | 140 int c1 = (offset & 0x3ff) + MIN_LOW_SURROGATE; |
| 183 return new String.fromCharCodes([c0, c1]); | 141 return new String.fromCharCodes([c0, c1]); |
| 184 } | 142 } |
| 185 | |
| 186 static int toLowerCase(int c) { | |
| 187 if (c >= 0x41 && c <= 0x5A) { | |
| 188 return 0x61 + (c - 0x41); | |
| 189 } | |
| 190 return c; | |
| 191 } | |
| 192 | |
| 193 static int toUpperCase(int c) { | |
| 194 if (c >= 0x61 && c <= 0x7A) { | |
| 195 return 0x41 + (c - 0x61); | |
| 196 } | |
| 197 return c; | |
| 198 } | |
| 199 } | 143 } |
| 200 | 144 |
| 201 abstract class Enum<E extends Enum> implements Comparable<E> { | 145 abstract class Enum<E extends Enum> implements Comparable<E> { |
| 202 /// The name of this enum constant, as declared in the enum declaration. | 146 /// The name of this enum constant, as declared in the enum declaration. |
| 203 final String name; | 147 final String name; |
| 204 | 148 |
| 205 /// The position in the enum declaration. | 149 /// The position in the enum declaration. |
| 206 final int ordinal; | 150 final int ordinal; |
| 207 const Enum(this.name, this.ordinal); | 151 const Enum(this.name, this.ordinal); |
| 208 int get hashCode => ordinal; | 152 int get hashCode => ordinal; |
| 209 int compareTo(E other) => ordinal - other.ordinal; | 153 int compareTo(E other) => ordinal - other.ordinal; |
| 210 String toString() => name; | 154 String toString() => name; |
| 211 } | 155 } |
| 212 | 156 |
| 213 class IllegalArgumentException extends JavaException { | 157 class IllegalArgumentException extends JavaException { |
| 214 IllegalArgumentException([message = "", cause = null]) | 158 IllegalArgumentException([message = "", cause = null]) |
| 215 : super(message, cause); | 159 : super(message, cause); |
| 216 } | 160 } |
| 217 | 161 |
| 218 class IllegalStateException extends JavaException { | 162 class IllegalStateException extends JavaException { |
| 219 IllegalStateException([message = ""]) : super(message); | 163 IllegalStateException([message = ""]) : super(message); |
| 220 } | 164 } |
| 221 | 165 |
| 222 class JavaArrays { | 166 class JavaArrays { |
| 223 static bool equals(List a, List b) { | |
| 224 if (identical(a, b)) { | |
| 225 return true; | |
| 226 } | |
| 227 if (a.length != b.length) { | |
| 228 return false; | |
| 229 } | |
| 230 var len = a.length; | |
| 231 for (int i = 0; i < len; i++) { | |
| 232 if (a[i] != b[i]) { | |
| 233 return false; | |
| 234 } | |
| 235 } | |
| 236 return true; | |
| 237 } | |
| 238 | |
| 239 static int makeHashCode(List a) { | 167 static int makeHashCode(List a) { |
| 168 // TODO(rnystrom): This is not used by analyzer, but is called by |
| 169 // analysis_server. Move this code there and remove it from here. |
| 240 if (a == null) { | 170 if (a == null) { |
| 241 return 0; | 171 return 0; |
| 242 } | 172 } |
| 243 int result = 1; | 173 int result = 1; |
| 244 for (var element in a) { | 174 for (var element in a) { |
| 245 result = 31 * result + (element == null ? 0 : element.hashCode); | 175 result = 31 * result + (element == null ? 0 : element.hashCode); |
| 246 } | 176 } |
| 247 return result; | 177 return result; |
| 248 } | 178 } |
| 249 } | 179 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 if (fromIndex > target.length) return -1; | 215 if (fromIndex > target.length) return -1; |
| 286 if (fromIndex < 0) fromIndex = 0; | 216 if (fromIndex < 0) fromIndex = 0; |
| 287 return target.indexOf(str, fromIndex); | 217 return target.indexOf(str, fromIndex); |
| 288 } | 218 } |
| 289 | 219 |
| 290 static int lastIndexOf(String target, String str, int fromIndex) { | 220 static int lastIndexOf(String target, String str, int fromIndex) { |
| 291 if (fromIndex > target.length) return -1; | 221 if (fromIndex > target.length) return -1; |
| 292 if (fromIndex < 0) fromIndex = 0; | 222 if (fromIndex < 0) fromIndex = 0; |
| 293 return target.lastIndexOf(str, fromIndex); | 223 return target.lastIndexOf(str, fromIndex); |
| 294 } | 224 } |
| 295 | |
| 296 static bool startsWithBefore(String s, String other, int start) { | |
| 297 return s.indexOf(other, start) != -1; | |
| 298 } | |
| 299 } | 225 } |
| 300 | 226 |
| 301 class JavaSystem { | 227 class JavaSystem { |
| 302 static int currentTimeMillis() { | 228 static int currentTimeMillis() { |
| 303 return (new DateTime.now()).millisecondsSinceEpoch; | 229 return (new DateTime.now()).millisecondsSinceEpoch; |
| 304 } | 230 } |
| 305 | 231 |
| 306 static int nanoTime() { | 232 static int nanoTime() { |
| 307 if (!nanoTimeStopwatch.isRunning) { | 233 if (!nanoTimeStopwatch.isRunning) { |
| 308 nanoTimeStopwatch.start(); | 234 nanoTimeStopwatch.start(); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 367 |
| 442 class UnsupportedOperationException extends JavaException { | 368 class UnsupportedOperationException extends JavaException { |
| 443 UnsupportedOperationException([message = ""]) : super(message); | 369 UnsupportedOperationException([message = ""]) : super(message); |
| 444 } | 370 } |
| 445 | 371 |
| 446 class URISyntaxException implements Exception { | 372 class URISyntaxException implements Exception { |
| 447 final String message; | 373 final String message; |
| 448 URISyntaxException(this.message); | 374 URISyntaxException(this.message); |
| 449 String toString() => "URISyntaxException: $message"; | 375 String toString() => "URISyntaxException: $message"; |
| 450 } | 376 } |
| OLD | NEW |