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

Side by Side Diff: pkg/analyzer/lib/src/generated/source.dart

Issue 983183003: Convert content cache to use file paths (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/lib/src/get_handler.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.source; 8 library engine.source;
9 9
10 import "dart:math" as math; 10 import "dart:math" as math;
11 import 'dart:collection'; 11 import 'dart:collection';
12 12
13 import 'package:analyzer/file_system/file_system.dart'; 13 import 'package:analyzer/file_system/file_system.dart';
14 import 'package:analyzer/source/package_map_resolver.dart'; 14 import 'package:analyzer/source/package_map_resolver.dart';
15 import 'package:analyzer/task/model.dart'; 15 import 'package:analyzer/task/model.dart';
16 16
17 import 'engine.dart'; 17 import 'engine.dart';
18 import 'java_core.dart'; 18 import 'java_core.dart';
19 import 'java_engine.dart'; 19 import 'java_engine.dart';
20 import 'java_io.dart' show JavaFile; 20 import 'java_io.dart' show JavaFile;
21 import 'sdk.dart' show DartSdk; 21 import 'sdk.dart' show DartSdk;
22 import 'source_io.dart' show FileBasedSource; 22 import 'source_io.dart' show FileBasedSource;
23 23
24 /** 24 /**
25 * A function that is used to handle [ContentCache] entries. 25 * A function that is used to visit [ContentCache] entries.
26 */ 26 */
27 typedef void ContentCacheVisitor(Source source, int stamp, String contents); 27 typedef void ContentCacheVisitor(String fullPath, int stamp, String contents);
28 28
29 /** 29 /**
30 * Instances of class `ContentCache` hold content used to override the default c ontent of a 30 * A cache used to override the default content of a [Source].
31 * [Source].
32 */ 31 */
33 class ContentCache { 32 class ContentCache {
34 /** 33 /**
35 * A table mapping sources to the contents of those sources. This is used to o verride the default 34 * A table mapping the full path of sources to the contents of those sources.
36 * contents of a source. 35 * This is used to override the default contents of a source.
37 */ 36 */
38 HashMap<Source, String> _contentMap = new HashMap<Source, String>(); 37 HashMap<String, String> _contentMap = new HashMap<String, String>();
39 38
40 /** 39 /**
41 * A table mapping sources to the modification stamps of those sources. This i s used when the 40 * A table mapping the full path of sources to the modification stamps of
42 * default contents of a source has been overridden. 41 * those sources. This is used when the default contents of a source has been
42 * overridden.
43 */ 43 */
44 HashMap<Source, int> _stampMap = new HashMap<Source, int>(); 44 HashMap<String, int> _stampMap = new HashMap<String, int>();
45 45
46 /** 46 /**
47 * Visit all entries of this cache. 47 * Visit all entries of this cache.
48 */ 48 */
49 void accept(ContentCacheVisitor visitor) { 49 void accept(ContentCacheVisitor visitor) {
50 _contentMap.forEach((Source source, String contents) { 50 _contentMap.forEach((String fullPath, String contents) {
51 int stamp = _stampMap[source]; 51 int stamp = _stampMap[fullPath];
52 visitor(source, stamp, contents); 52 visitor(fullPath, stamp, contents);
53 }); 53 });
54 } 54 }
55 55
56 /** 56 /**
57 * Return the contents of the given source, or `null` if this cache does not o verride the 57 * Return the contents of the given [source], or `null` if this cache does not
58 * contents of the source. 58 * override the contents of the source.
59 * 59 *
60 * <b>Note:</b> This method is not intended to be used except by 60 * <b>Note:</b> This method is not intended to be used except by
61 * [AnalysisContext.getContents]. 61 * [AnalysisContext.getContents].
62 *
63 * @param source the source whose content is to be returned
64 * @return the contents of the given source
65 */ 62 */
66 String getContents(Source source) => _contentMap[source]; 63 String getContents(Source source) => _contentMap[source.fullName];
67 64
68 /** 65 /**
69 * Return the modification stamp of the given source, or `null` if this cache does not 66 * Return the modification stamp of the given [source], or `null` if this
70 * override the contents of the source. 67 * cache does not override the contents of the source.
71 * 68 *
72 * <b>Note:</b> This method is not intended to be used except by 69 * <b>Note:</b> This method is not intended to be used except by
73 * [AnalysisContext.getModificationStamp]. 70 * [AnalysisContext.getModificationStamp].
74 *
75 * @param source the source whose modification stamp is to be returned
76 * @return the modification stamp of the given source
77 */ 71 */
78 int getModificationStamp(Source source) => _stampMap[source]; 72 int getModificationStamp(Source source) => _stampMap[source.fullName];
79 73
80 /** 74 /**
81 * Set the contents of the given source to the given contents. This has the ef fect of overriding 75 * Set the contents of the given [source] to the given [contents]. This has
82 * the default contents of the source. If the contents are `null` the override is removed so 76 * the effect of overriding the default contents of the source. If the
83 * that the default contents will be returned. 77 * contents are `null` the override is removed so that the default contents
84 * 78 * will be returned.
85 * @param source the source whose contents are being overridden
86 * @param contents the new contents of the source
87 * @return the original cached contents or `null` if none
88 */ 79 */
89 String setContents(Source source, String contents) { 80 String setContents(Source source, String contents) {
81 String fullName = source.fullName;
90 if (contents == null) { 82 if (contents == null) {
91 _stampMap.remove(source); 83 _stampMap.remove(fullName);
92 return _contentMap.remove(source); 84 return _contentMap.remove(fullName);
93 } else { 85 } else {
94 int newStamp = JavaSystem.currentTimeMillis(); 86 int newStamp = JavaSystem.currentTimeMillis();
95 int oldStamp = _stampMap[source]; 87 int oldStamp = _stampMap[fullName];
96 _stampMap[source] = newStamp; 88 _stampMap[fullName] = newStamp;
97 // Occasionally, if this method is called in rapid succession, the 89 // Occasionally, if this method is called in rapid succession, the
98 // timestamps are equal. Guard against this by artificially incrementing 90 // timestamps are equal. Guard against this by artificially incrementing
99 // the new timestamp. 91 // the new timestamp.
100 if (newStamp == oldStamp) { 92 if (newStamp == oldStamp) {
101 _stampMap[source] = newStamp + 1; 93 _stampMap[fullName] = newStamp + 1;
102 } 94 }
103 String oldContent = _contentMap[source]; 95 String oldContent = _contentMap[fullName];
104 _contentMap[source] = contents; 96 _contentMap[fullName] = contents;
105 return oldContent; 97 return oldContent;
106 } 98 }
107 } 99 }
108 } 100 }
109 101
110 /** 102 /**
111 * Instances of the class `DartUriResolver` resolve `dart` URI's. 103 * Instances of the class `DartUriResolver` resolve `dart` URI's.
112 */ 104 */
113 class DartUriResolver extends UriResolver { 105 class DartUriResolver extends UriResolver {
114 /** 106 /**
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 995
1004 /** 996 /**
1005 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot 997 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot
1006 * be computed. 998 * be computed.
1007 * 999 *
1008 * @param source the source to get URI for 1000 * @param source the source to get URI for
1009 * @return the absolute URI representing the given source 1001 * @return the absolute URI representing the given source
1010 */ 1002 */
1011 Uri restoreAbsolute(Source source) => null; 1003 Uri restoreAbsolute(Source source) => null;
1012 } 1004 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/get_handler.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698