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

Side by Side Diff: pkg/analyzer/lib/src/string_source.dart

Issue 1718803002: Make StringSource fully implement Source (issue 25822) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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.string_source; 5 library analyzer.src.string_source;
6 6
7 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; 7 import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
8 import 'package:analyzer/src/generated/source.dart'; 8 import 'package:analyzer/src/generated/source.dart';
9 9
10 /** 10 /**
11 * An implementation of [Source] that's based on an in-memory Dart string. 11 * An implementation of [Source] that's based on an in-memory Dart string.
12 */ 12 */
13 class StringSource extends Source { 13 class StringSource extends Source {
14 /** 14 /**
15 * The content of the source. 15 * The content of the source.
16 */ 16 */
17 final String _contents; 17 final String _contents;
18 18
19 @override 19 @override
20 final String fullName; 20 final String fullName;
21 21
22 @override 22 @override
23 final Uri uri;
24
25 @override
23 final int modificationStamp; 26 final int modificationStamp;
24 27
25 StringSource(this._contents, this.fullName) 28 StringSource(this._contents, String fullName)
26 : modificationStamp = new DateTime.now().millisecondsSinceEpoch; 29 : this.fullName = fullName,
30 uri = fullName == null ? null : new Uri.file(fullName),
31 modificationStamp = new DateTime.now().millisecondsSinceEpoch;
27 32
28 @override 33 @override
29 TimestampedData<String> get contents => 34 TimestampedData<String> get contents =>
30 new TimestampedData(modificationStamp, _contents); 35 new TimestampedData(modificationStamp, _contents);
31 36
32 @override 37 @override
33 String get encoding => 38 String get encoding => uri.toString();
34 throw new UnsupportedError("StringSource doesn't support encoding.");
35 39
36 @override 40 @override
37 int get hashCode => _contents.hashCode ^ fullName.hashCode; 41 int get hashCode => _contents.hashCode ^ fullName.hashCode;
38 42
39 @override 43 @override
40 bool get isInSystemLibrary => false; 44 bool get isInSystemLibrary => false;
41 45
42 @override 46 @override
43 String get shortName => fullName; 47 String get shortName => fullName;
44 48
45 @override 49 @override
46 Uri get uri => 50 UriKind get uriKind => UriKind.FILE_URI;
47 throw new UnsupportedError("StringSource doesn't support uri.");
48
49 UriKind get uriKind =>
50 throw new UnsupportedError("StringSource doesn't support uriKind.");
51 51
52 /** 52 /**
53 * Return `true` if the given [object] is a string source that is equal to 53 * Return `true` if the given [object] is a string source that is equal to
54 * this source. 54 * this source.
55 */ 55 */
56 bool operator ==(Object object) { 56 bool operator ==(Object object) {
57 return object is StringSource && 57 return object is StringSource &&
58 object._contents == _contents && 58 object._contents == _contents &&
59 object.fullName == fullName; 59 object.fullName == fullName;
60 } 60 }
61 61
62 @override 62 @override
63 bool exists() => true; 63 bool exists() => true;
64 64
65 @override 65 @override
66 Uri resolveRelativeUri(Uri relativeUri) => throw new UnsupportedError( 66 Uri resolveRelativeUri(Uri relativeUri) => uri.resolveUri(relativeUri);
67 "StringSource doesn't support resolveRelative.");
68 67
69 @override 68 @override
70 String toString() => 'StringSource ($fullName)'; 69 String toString() => 'StringSource ($fullName)';
71 } 70 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698