OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dev_compiler.src.analysis_context; | 5 library dev_compiler.src.analysis_context; |
6 | 6 |
7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
10 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; | 10 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 resolvers.addAll(fileResolvers); | 68 resolvers.addAll(fileResolvers); |
69 return new SourceFactory(resolvers); | 69 return new SourceFactory(resolvers); |
70 } | 70 } |
71 | 71 |
72 /// Creates a [DartUriResolver] that uses a mock 'dart:' library contents. | 72 /// Creates a [DartUriResolver] that uses a mock 'dart:' library contents. |
73 DartUriResolver createMockSdkResolver(Map<String, String> mockSources) => | 73 DartUriResolver createMockSdkResolver(Map<String, String> mockSources) => |
74 new MockDartSdk(mockSources, reportMissing: true).resolver; | 74 new MockDartSdk(mockSources, reportMissing: true).resolver; |
75 | 75 |
76 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. | 76 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. |
77 DartUriResolver createSdkPathResolver(String sdkPath) => | 77 DartUriResolver createSdkPathResolver(String sdkPath) => new DartUriResolver( |
78 new DartUriResolver(new DirectoryBasedDartSdk(new JavaFile(sdkPath))); | 78 new DirectoryBasedDartSdk( |
| 79 new JavaFile(sdkPath), /*useDart2jsPaths:*/ true)); |
79 | 80 |
80 UriResolver _createImplicitEntryResolver(SourceResolverOptions options) { | 81 UriResolver _createImplicitEntryResolver(SourceResolverOptions options) { |
81 var entry = path.absolute(SourceResolverOptions.implicitHtmlFile); | 82 var entry = path.absolute(SourceResolverOptions.implicitHtmlFile); |
82 var src = path.absolute(options.entryPointFile); | 83 var src = path.absolute(options.entryPointFile); |
83 var provider = new MemoryResourceProvider(); | 84 var provider = new MemoryResourceProvider(); |
84 provider.newFile( | 85 provider.newFile( |
85 entry, '<body><script type="application/dart" src="$src"></script>'); | 86 entry, '<body><script type="application/dart" src="$src"></script>'); |
86 return new ExistingSourceUriResolver(new ResourceUriResolver(provider)); | 87 return new ExistingSourceUriResolver(new ResourceUriResolver(provider)); |
87 } | 88 } |
88 | 89 |
89 /// A UriResolver that continues to the next one if it fails to find an existing | 90 /// A UriResolver that continues to the next one if it fails to find an existing |
90 /// source file. This is unlike normal URI resolvers, that always return | 91 /// source file. This is unlike normal URI resolvers, that always return |
91 /// something, even if it is a non-existing file. | 92 /// something, even if it is a non-existing file. |
92 class ExistingSourceUriResolver implements UriResolver { | 93 class ExistingSourceUriResolver implements UriResolver { |
93 final UriResolver resolver; | 94 final UriResolver resolver; |
94 ExistingSourceUriResolver(this.resolver); | 95 ExistingSourceUriResolver(this.resolver); |
95 | 96 |
96 Source resolveAbsolute(Uri uri) { | 97 Source resolveAbsolute(Uri uri) { |
97 var src = resolver.resolveAbsolute(uri); | 98 var src = resolver.resolveAbsolute(uri); |
98 return src.exists() ? src : null; | 99 return src.exists() ? src : null; |
99 } | 100 } |
100 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source); | 101 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source); |
101 } | 102 } |
OLD | NEW |