| 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.source; | 5 library analyzer.src.generated.source; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import "dart:math" as math; | 8 import "dart:math" as math; |
| 9 | 9 |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 */ | 35 */ |
| 36 HashMap<String, String> _contentMap = new HashMap<String, String>(); | 36 HashMap<String, String> _contentMap = new HashMap<String, String>(); |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * A table mapping the full path of sources to the modification stamps of | 39 * A table mapping the full path of sources to the modification stamps of |
| 40 * those sources. This is used when the default contents of a source has been | 40 * those sources. This is used when the default contents of a source has been |
| 41 * overridden. | 41 * overridden. |
| 42 */ | 42 */ |
| 43 HashMap<String, int> _stampMap = new HashMap<String, int>(); | 43 HashMap<String, int> _stampMap = new HashMap<String, int>(); |
| 44 | 44 |
| 45 int _nextStamp = 0; |
| 46 |
| 45 /** | 47 /** |
| 46 * Visit all entries of this cache. | 48 * Visit all entries of this cache. |
| 47 */ | 49 */ |
| 48 void accept(ContentCacheVisitor visitor) { | 50 void accept(ContentCacheVisitor visitor) { |
| 49 _contentMap.forEach((String fullPath, String contents) { | 51 _contentMap.forEach((String fullPath, String contents) { |
| 50 int stamp = _stampMap[fullPath]; | 52 int stamp = _stampMap[fullPath]; |
| 51 visitor(fullPath, stamp, contents); | 53 visitor(fullPath, stamp, contents); |
| 52 }); | 54 }); |
| 53 } | 55 } |
| 54 | 56 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 75 * the effect of overriding the default contents of the source. If the | 77 * the effect of overriding the default contents of the source. If the |
| 76 * contents are `null` the override is removed so that the default contents | 78 * contents are `null` the override is removed so that the default contents |
| 77 * will be returned. | 79 * will be returned. |
| 78 */ | 80 */ |
| 79 String setContents(Source source, String contents) { | 81 String setContents(Source source, String contents) { |
| 80 String fullName = source.fullName; | 82 String fullName = source.fullName; |
| 81 if (contents == null) { | 83 if (contents == null) { |
| 82 _stampMap.remove(fullName); | 84 _stampMap.remove(fullName); |
| 83 return _contentMap.remove(fullName); | 85 return _contentMap.remove(fullName); |
| 84 } else { | 86 } else { |
| 85 int newStamp = JavaSystem.currentTimeMillis(); | 87 int newStamp = _nextStamp++; |
| 86 int oldStamp = _stampMap[fullName]; | 88 int oldStamp = _stampMap[fullName]; |
| 87 _stampMap[fullName] = newStamp; | 89 _stampMap[fullName] = newStamp; |
| 88 // Occasionally, if this method is called in rapid succession, the | 90 // Occasionally, if this method is called in rapid succession, the |
| 89 // timestamps are equal. Guard against this by artificially incrementing | 91 // timestamps are equal. Guard against this by artificially incrementing |
| 90 // the new timestamp. | 92 // the new timestamp. |
| 91 if (newStamp == oldStamp) { | 93 if (newStamp == oldStamp) { |
| 92 _stampMap[fullName] = newStamp + 1; | 94 _stampMap[fullName] = newStamp + 1; |
| 93 } | 95 } |
| 94 String oldContent = _contentMap[fullName]; | 96 String oldContent = _contentMap[fullName]; |
| 95 _contentMap[fullName] = contents; | 97 _contentMap[fullName] = contents; |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 Source resolveAbsolute(Uri uri, [Uri actualUri]); | 932 Source resolveAbsolute(Uri uri, [Uri actualUri]); |
| 931 | 933 |
| 932 /** | 934 /** |
| 933 * Return an absolute URI that represents the given [source], or `null` if a | 935 * Return an absolute URI that represents the given [source], or `null` if a |
| 934 * valid URI cannot be computed. | 936 * valid URI cannot be computed. |
| 935 * | 937 * |
| 936 * The computation should be based solely on [source.fullName]. | 938 * The computation should be based solely on [source.fullName]. |
| 937 */ | 939 */ |
| 938 Uri restoreAbsolute(Source source) => null; | 940 Uri restoreAbsolute(Source source) => null; |
| 939 } | 941 } |
| OLD | NEW |