OLD | NEW |
| (Empty) |
1 // Copyright (c) 2016, 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. | |
4 | |
5 import 'package:analyzer/src/generated/engine.dart'; | |
6 import 'package:analyzer/src/generated/source.dart' show Source, UriKind; | |
7 import 'package:barback/barback.dart' show Asset, TimestampedData; | |
8 import 'package:path/path.dart' as path; | |
9 | |
10 class AssetSource implements Source { | |
11 final Uri uri; | |
12 final Asset asset; | |
13 final String contentString; | |
14 AssetSource(this.uri, this.asset, this.contentString); | |
15 | |
16 @override | |
17 toString() => 'AssetSource($uri, ${asset.id})'; | |
18 | |
19 @override | |
20 TimestampedData<String> get contents => | |
21 new TimestampedData(modificationStamp, contentString); | |
22 | |
23 @override | |
24 String get encoding => null; | |
25 | |
26 @override | |
27 bool exists() => true; | |
28 | |
29 @override | |
30 String get fullName => uri.toString(); | |
31 | |
32 @override | |
33 bool get isInSystemLibrary => uriKind == UriKind.DART_URI; | |
34 | |
35 @override | |
36 int get modificationStamp => 0; | |
37 | |
38 @override | |
39 Uri resolveRelativeUri(Uri relativeUri) { | |
40 var resolvedPath = path.join(path.dirname(uri.path), relativeUri.path); | |
41 return new Uri(scheme: uri.scheme, path: resolvedPath); | |
42 } | |
43 | |
44 @override | |
45 String get shortName => uri.toString(); | |
46 | |
47 @override | |
48 Source get source => this; | |
49 | |
50 @override | |
51 UriKind get uriKind { | |
52 switch (uri.scheme) { | |
53 case 'package': | |
54 return UriKind.PACKAGE_URI; | |
55 | |
56 case 'dart': | |
57 return UriKind.DART_URI; | |
58 | |
59 case 'file': | |
60 return UriKind.FILE_URI; | |
61 | |
62 default: | |
63 throw new StateError(uri.toString()); | |
64 } | |
65 } | |
66 } | |
OLD | NEW |