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

Side by Side Diff: packages/analyzer/lib/src/generated/java_core.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 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 unified diff | Download patch
OLDNEW
1 library java.core; 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
3 // BSD-style license that can be found in the LICENSE file.
2 4
3 const int LONG_MAX_VALUE = 0x7fffffffffffffff; 5 library analyzer.src.generated.java_core;
4
5 final Stopwatch nanoTimeStopwatch = new Stopwatch();
6 6
7 /** 7 /**
8 * Inserts the given arguments into [pattern]. 8 * Inserts the given arguments into [pattern].
9 * 9 *
10 * format('Hello, {0}!', 'John') = 'Hello, John!' 10 * format('Hello, {0}!', 'John') = 'Hello, John!'
11 * format('{0} are you {1}ing?', 'How', 'do') = 'How are you doing?' 11 * format('{0} are you {1}ing?', 'How', 'do') = 'How are you doing?'
12 * format('{0} are you {1}ing?', 'What', 'read') = 'What are you reading?' 12 * format('{0} are you {1}ing?', 'What', 'read') = 'What are you reading?'
13 */ 13 */
14 String format(String pattern, 14 String format(String pattern,
15 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7]) { 15 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7]) {
16 // TODO(rnystrom): This is not used by analyzer, but is called by
17 // analysis_server. Move this code there and remove it from here.
16 return formatList(pattern, [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7]); 18 return formatList(pattern, [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7]);
17 } 19 }
18 20
19 /** 21 /**
20 * Inserts the given [args] into [pattern]. 22 * Inserts the given [arguments] into [pattern].
21 * 23 *
22 * format('Hello, {0}!', ['John']) = 'Hello, John!' 24 * format('Hello, {0}!', ['John']) = 'Hello, John!'
23 * format('{0} are you {1}ing?', ['How', 'do']) = 'How are you doing?' 25 * format('{0} are you {1}ing?', ['How', 'do']) = 'How are you doing?'
24 * format('{0} are you {1}ing?', ['What', 'read']) = 'What are you reading?' 26 * format('{0} are you {1}ing?', ['What', 'read']) = 'What are you reading?'
25 */ 27 */
26 String formatList(String pattern, List<Object> arguments) { 28 String formatList(String pattern, List<Object> arguments) {
27 if (arguments == null || arguments.isEmpty) { 29 if (arguments == null || arguments.isEmpty) {
28 assert(!pattern.contains(new RegExp(r'\{(\d+)\}'))); 30 assert(!pattern.contains(new RegExp(r'\{(\d+)\}')));
29 return pattern; 31 return pattern;
30 } 32 }
31 return pattern.replaceAllMapped(new RegExp(r'\{(\d+)\}'), (match) { 33 return pattern.replaceAllMapped(new RegExp(r'\{(\d+)\}'), (match) {
32 String indexStr = match.group(1); 34 String indexStr = match.group(1);
33 int index = int.parse(indexStr); 35 int index = int.parse(indexStr);
34 Object arg = arguments[index]; 36 Object arg = arguments[index];
35 assert(arg != null); 37 assert(arg != null);
36 return arg != null ? arg.toString() : null; 38 return arg?.toString();
37 }); 39 });
38 } 40 }
39 41
40 bool javaCollectionContainsAll(Iterable list, Iterable c) {
41 return c.fold(true, (bool prev, e) => prev && list.contains(e));
42 }
43
44 javaListSet(List list, int index, newValue) {
45 var oldValue = list[index];
46 list[index] = newValue;
47 return oldValue;
48 }
49
50 bool javaSetEquals(Set a, Set b) {
51 return a.containsAll(b) && b.containsAll(a);
52 }
53
54 bool javaStringEqualsIgnoreCase(String a, String b) {
55 return a.toLowerCase() == b.toLowerCase();
56 }
57
58 bool javaStringRegionMatches(
59 String t, int toffset, String o, int ooffset, int len) {
60 if (toffset < 0) return false;
61 if (ooffset < 0) return false;
62 var tend = toffset + len;
63 var oend = ooffset + len;
64 if (tend > t.length) return false;
65 if (oend > o.length) return false;
66 return t.substring(toffset, tend) == o.substring(ooffset, oend);
67 }
68
69 /// Parses given string to [Uri], throws [URISyntaxException] if invalid.
70 Uri parseUriWithException(String str) {
71 Uri uri;
72 try {
73 uri = Uri.parse(str);
74 } on FormatException catch (e) {
75 throw new URISyntaxException(e.toString());
76 }
77 if (uri.path.isEmpty) {
78 throw new URISyntaxException('empty path');
79 }
80 return uri;
81 }
82
83 /** 42 /**
84 * Very limited printf implementation, supports only %s and %d. 43 * Very limited printf implementation, supports only %s and %d.
85 */ 44 */
86 String _printf(String fmt, List args) { 45 String _printf(String fmt, List args) {
87 StringBuffer sb = new StringBuffer(); 46 StringBuffer sb = new StringBuffer();
88 bool markFound = false; 47 bool markFound = false;
89 int argIndex = 0; 48 int argIndex = 0;
90 for (int i = 0; i < fmt.length; i++) { 49 for (int i = 0; i < fmt.length; i++) {
91 int c = fmt.codeUnitAt(i); 50 int c = fmt.codeUnitAt(i);
92 if (c == 0x25) { 51 if (c == 0x25) {
(...skipping 11 matching lines...) Expand all
104 if (c == 0x64) { 63 if (c == 0x64) {
105 sb.write(args[argIndex++]); 64 sb.write(args[argIndex++]);
106 continue; 65 continue;
107 } 66 }
108 // %s 67 // %s
109 if (c == 0x73) { 68 if (c == 0x73) {
110 sb.write(args[argIndex++]); 69 sb.write(args[argIndex++]);
111 continue; 70 continue;
112 } 71 }
113 // unknown 72 // unknown
114 throw new IllegalArgumentException( 73 throw new ArgumentError('[$fmt][$i] = 0x${c.toRadixString(16)}');
115 '[$fmt][$i] = 0x${c.toRadixString(16)}');
116 } else { 74 } else {
117 sb.writeCharCode(c); 75 sb.writeCharCode(c);
118 } 76 }
119 } 77 }
120 return sb.toString(); 78 return sb.toString();
121 } 79 }
122 80
123 class Character { 81 class Character {
124 static const int MAX_VALUE = 0xffff; 82 static const int MAX_VALUE = 0xffff;
125 static const int MAX_CODE_POINT = 0x10ffff; 83 static const int MAX_CODE_POINT = 0x10ffff;
126 static const int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000; 84 static const int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000;
127 static const int MIN_LOW_SURROGATE = 0xDC00; 85 static const int MIN_LOW_SURROGATE = 0xDC00;
128 static const int MIN_HIGH_SURROGATE = 0xD800; 86 static const int MIN_HIGH_SURROGATE = 0xD800;
87
129 static int digit(int codePoint, int radix) { 88 static int digit(int codePoint, int radix) {
130 if (radix != 16) { 89 if (radix != 16) {
131 throw new ArgumentError("only radix == 16 is supported"); 90 throw new ArgumentError("only radix == 16 is supported");
132 } 91 }
133 if (0x30 <= codePoint && codePoint <= 0x39) { 92 if (0x30 <= codePoint && codePoint <= 0x39) {
134 return codePoint - 0x30; 93 return codePoint - 0x30;
135 } 94 }
136 if (0x41 <= codePoint && codePoint <= 0x46) { 95 if (0x41 <= codePoint && codePoint <= 0x46) {
137 return 0xA + (codePoint - 0x41); 96 return 0xA + (codePoint - 0x41);
138 } 97 }
139 if (0x61 <= codePoint && codePoint <= 0x66) { 98 if (0x61 <= codePoint && codePoint <= 0x66) {
140 return 0xA + (codePoint - 0x61); 99 return 0xA + (codePoint - 0x61);
141 } 100 }
142 return -1; 101 return -1;
143 } 102 }
144 103
145 static bool isDigit(int c) { 104 static bool isDigit(int c) => c >= 0x30 && c <= 0x39;
146 return c >= 0x30 && c <= 0x39;
147 }
148 105
149 static bool isLetter(int c) { 106 static bool isLetter(int c) =>
150 return c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A; 107 c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A;
151 }
152 108
153 static bool isLetterOrDigit(int c) { 109 static bool isLetterOrDigit(int c) => isLetter(c) || isDigit(c);
154 return isLetter(c) || isDigit(c);
155 }
156 110
157 static bool isLowerCase(int c) { 111 static bool isWhitespace(int c) =>
158 return c >= 0x61 && c <= 0x7A; 112 c == 0x09 || c == 0x20 || c == 0x0A || c == 0x0D;
159 }
160
161 static bool isUpperCase(int c) {
162 return c >= 0x41 && c <= 0x5A;
163 }
164
165 static bool isWhitespace(int c) {
166 return c == 0x09 || c == 0x20 || c == 0x0A || c == 0x0D;
167 }
168 113
169 static String toChars(int codePoint) { 114 static String toChars(int codePoint) {
170 if (codePoint < 0 || codePoint > MAX_CODE_POINT) { 115 if (codePoint < 0 || codePoint > MAX_CODE_POINT) {
171 throw new IllegalArgumentException(); 116 throw new ArgumentError();
172 } 117 }
173 if (codePoint < MIN_SUPPLEMENTARY_CODE_POINT) { 118 if (codePoint < MIN_SUPPLEMENTARY_CODE_POINT) {
174 return new String.fromCharCode(codePoint); 119 return new String.fromCharCode(codePoint);
175 } 120 }
176 int offset = codePoint - MIN_SUPPLEMENTARY_CODE_POINT; 121 int offset = codePoint - MIN_SUPPLEMENTARY_CODE_POINT;
177 int c0 = ((offset & 0x7FFFFFFF) >> 10) + MIN_HIGH_SURROGATE; 122 int c0 = ((offset & 0x7FFFFFFF) >> 10) + MIN_HIGH_SURROGATE;
178 int c1 = (offset & 0x3ff) + MIN_LOW_SURROGATE; 123 int c1 = (offset & 0x3ff) + MIN_LOW_SURROGATE;
179 return new String.fromCharCodes([c0, c1]); 124 return new String.fromCharCodes([c0, c1]);
180 } 125 }
181
182 static int toLowerCase(int c) {
183 if (c >= 0x41 && c <= 0x5A) {
184 return 0x61 + (c - 0x41);
185 }
186 return c;
187 }
188
189 static int toUpperCase(int c) {
190 if (c >= 0x61 && c <= 0x7A) {
191 return 0x41 + (c - 0x61);
192 }
193 return c;
194 }
195 } 126 }
196 127
128 @deprecated
197 abstract class Enum<E extends Enum> implements Comparable<E> { 129 abstract class Enum<E extends Enum> implements Comparable<E> {
198 /// The name of this enum constant, as declared in the enum declaration. 130 /// The name of this enum constant, as declared in the enum declaration.
199 final String name; 131 final String name;
200 132
201 /// The position in the enum declaration. 133 /// The position in the enum declaration.
202 final int ordinal; 134 final int ordinal;
203 const Enum(this.name, this.ordinal); 135 const Enum(this.name, this.ordinal);
204 int get hashCode => ordinal; 136 int get hashCode => ordinal;
205 int compareTo(E other) => ordinal - other.ordinal; 137 int compareTo(E other) => ordinal - other.ordinal;
206 String toString() => name; 138 String toString() => name;
207 } 139 }
208 140
209 class IllegalArgumentException extends JavaException {
210 IllegalArgumentException([message = "", cause = null])
211 : super(message, cause);
212 }
213
214 class IllegalStateException extends JavaException {
215 IllegalStateException([message = ""]) : super(message);
216 }
217
218 class JavaArrays {
219 static bool equals(List a, List b) {
220 if (identical(a, b)) {
221 return true;
222 }
223 if (a.length != b.length) {
224 return false;
225 }
226 var len = a.length;
227 for (int i = 0; i < len; i++) {
228 if (a[i] != b[i]) {
229 return false;
230 }
231 }
232 return true;
233 }
234
235 static int makeHashCode(List a) {
236 if (a == null) {
237 return 0;
238 }
239 int result = 1;
240 for (var element in a) {
241 result = 31 * result + (element == null ? 0 : element.hashCode);
242 }
243 return result;
244 }
245 }
246
247 class JavaException implements Exception {
248 final String message;
249 final Exception cause;
250 JavaException([this.message = "", this.cause = null]);
251 JavaException.withCause(this.cause) : message = null;
252 String toString() => "$runtimeType: $message $cause";
253 }
254
255 class JavaIOException extends JavaException {
256 JavaIOException([message = "", cause = null]) : super(message, cause);
257 }
258
259 class JavaPatternMatcher {
260 Iterator<Match> _matches;
261 Match _match;
262 JavaPatternMatcher(RegExp re, String input) {
263 _matches = re.allMatches(input).iterator;
264 }
265 int end() => _match.end;
266 bool find() {
267 if (!_matches.moveNext()) {
268 return false;
269 }
270 _match = _matches.current;
271 return true;
272 }
273
274 String group(int i) => _match[i];
275 bool matches() => find();
276 int start() => _match.start;
277 }
278
279 class JavaString {
280 static int indexOf(String target, String str, int fromIndex) {
281 if (fromIndex > target.length) return -1;
282 if (fromIndex < 0) fromIndex = 0;
283 return target.indexOf(str, fromIndex);
284 }
285
286 static int lastIndexOf(String target, String str, int fromIndex) {
287 if (fromIndex > target.length) return -1;
288 if (fromIndex < 0) fromIndex = 0;
289 return target.lastIndexOf(str, fromIndex);
290 }
291
292 static bool startsWithBefore(String s, String other, int start) {
293 return s.indexOf(other, start) != -1;
294 }
295 }
296
297 class JavaSystem {
298 @deprecated
299 static void arraycopy(
300 List src, int srcPos, List dest, int destPos, int length) {
301 for (int i = 0; i < length; i++) {
302 dest[destPos + i] = src[srcPos + i];
303 }
304 }
305
306 static int currentTimeMillis() {
307 return (new DateTime.now()).millisecondsSinceEpoch;
308 }
309
310 static int nanoTime() {
311 if (!nanoTimeStopwatch.isRunning) {
312 nanoTimeStopwatch.start();
313 }
314 return nanoTimeStopwatch.elapsedMicroseconds * 1000;
315 }
316 }
317
318 class MissingFormatArgumentException implements Exception {
319 final String s;
320
321 MissingFormatArgumentException(this.s);
322
323 String toString() => "MissingFormatArgumentException: $s";
324 }
325
326 class NoSuchElementException extends JavaException {
327 String toString() => "NoSuchElementException";
328 }
329
330 class NotImplementedException extends JavaException {
331 NotImplementedException(message) : super(message);
332 }
333
334 class NumberFormatException extends JavaException {
335 String toString() => "NumberFormatException";
336 }
337
338 class PrintStringWriter extends PrintWriter { 141 class PrintStringWriter extends PrintWriter {
339 final StringBuffer _sb = new StringBuffer(); 142 final StringBuffer _sb = new StringBuffer();
340 143
341 void print(x) { 144 void print(x) {
342 _sb.write(x); 145 _sb.write(x);
343 } 146 }
344 147
345 String toString() => _sb.toString(); 148 String toString() => _sb.toString();
346 } 149 }
347 150
348 abstract class PrintWriter { 151 abstract class PrintWriter {
349 void newLine() { 152 void newLine() {
350 this.print('\n'); 153 this.print('\n');
351 } 154 }
352 155
353 void print(x); 156 void print(x);
354 157
355 void printf(String fmt, List args) { 158 void printf(String fmt, List args) {
356 this.print(_printf(fmt, args)); 159 this.print(_printf(fmt, args));
357 } 160 }
358 161
359 void println(String s) { 162 void println(String s) {
360 this.print(s); 163 this.print(s);
361 this.newLine(); 164 this.newLine();
362 } 165 }
363 } 166 }
364
365 class RuntimeException extends JavaException {
366 RuntimeException({String message: "", Exception cause: null})
367 : super(message, cause);
368 }
369
370 class StringIndexOutOfBoundsException extends JavaException {
371 StringIndexOutOfBoundsException(int index) : super('$index');
372 }
373
374 class StringUtils {
375 static String capitalize(String str) {
376 if (isEmpty(str)) {
377 return str;
378 }
379 return str.substring(0, 1).toUpperCase() + str.substring(1);
380 }
381
382 static bool equals(String cs1, String cs2) {
383 if (cs1 == cs2) {
384 return true;
385 }
386 if (cs1 == null || cs2 == null) {
387 return false;
388 }
389 return cs1 == cs2;
390 }
391
392 static bool isEmpty(String str) {
393 return str == null || str.isEmpty;
394 }
395
396 static String join(Iterable iter,
397 [String separator = ' ', int start = 0, int end = -1]) {
398 if (start != 0) {
399 iter = iter.skip(start);
400 }
401 if (end != -1) {
402 iter = iter.take(end - start);
403 }
404 return iter.join(separator);
405 }
406
407 static void printf(StringBuffer buffer, String fmt, List args) {
408 buffer.write(_printf(fmt, args));
409 }
410
411 static String remove(String str, String remove) {
412 if (isEmpty(str) || isEmpty(remove)) {
413 return str;
414 }
415 return str.replaceAll(remove, '');
416 }
417
418 static String removeStart(String str, String remove) {
419 if (isEmpty(str) || isEmpty(remove)) {
420 return str;
421 }
422 if (str.startsWith(remove)) {
423 return str.substring(remove.length);
424 }
425 return str;
426 }
427
428 static String repeat(String s, int n) {
429 StringBuffer sb = new StringBuffer();
430 for (int i = 0; i < n; i++) {
431 sb.write(s);
432 }
433 return sb.toString();
434 }
435
436 static List<String> split(String s, [String pattern = ' ']) {
437 return s.split(pattern);
438 }
439
440 static List<String> splitByWholeSeparatorPreserveAllTokens(
441 String s, String pattern) {
442 return s.split(pattern);
443 }
444 }
445
446 class UnsupportedOperationException extends JavaException {
447 UnsupportedOperationException([message = ""]) : super(message);
448 }
449
450 class URISyntaxException implements Exception {
451 final String message;
452 URISyntaxException(this.message);
453 String toString() => "URISyntaxException: $message";
454 }
OLDNEW
« no previous file with comments | « packages/analyzer/lib/src/generated/interner.dart ('k') | packages/analyzer/lib/src/generated/java_engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698