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

Side by Side Diff: lib/src/checker/resolver.dart

Issue 1130093007: Create html if needed in server mode (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Address comments Created 5 years, 7 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 | « lib/devc.dart ('k') | lib/src/in_memory.dart » ('j') | 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) 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 /// Encapsulates how to invoke the analyzer resolver and overrides how it 5 /// Encapsulates how to invoke the analyzer resolver and overrides how it
6 /// computes types on expressions to use our restricted set of types. 6 /// computes types on expressions to use our restricted set of types.
7 library dev_compiler.src.checker.resolver; 7 library dev_compiler.src.checker.resolver;
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
11 import 'package:analyzer/src/generated/element.dart'; 11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/error.dart' as analyzer; 13 import 'package:analyzer/src/generated/error.dart' as analyzer;
14 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; 14 import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
15 import 'package:analyzer/src/generated/resolver.dart'; 15 import 'package:analyzer/src/generated/resolver.dart';
16 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; 16 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
17 import 'package:analyzer/src/generated/source.dart' show DartUriResolver; 17 import 'package:analyzer/src/generated/source.dart' show DartUriResolver;
18 import 'package:analyzer/src/generated/source.dart' show Source; 18 import 'package:analyzer/src/generated/source.dart' show Source;
19 import 'package:analyzer/src/generated/source_io.dart'; 19 import 'package:analyzer/src/generated/source_io.dart';
20 import 'package:analyzer/src/generated/static_type_analyzer.dart'; 20 import 'package:analyzer/src/generated/static_type_analyzer.dart';
21 import 'package:analyzer/src/generated/utilities_collection.dart' 21 import 'package:analyzer/src/generated/utilities_collection.dart'
22 show DirectedGraph; 22 show DirectedGraph;
23 import 'package:logging/logging.dart' as logger; 23 import 'package:logging/logging.dart' as logger;
24 import 'package:path/path.dart' as path;
24 25
26 import 'package:dev_compiler/src/in_memory.dart';
25 import 'package:dev_compiler/src/options.dart'; 27 import 'package:dev_compiler/src/options.dart';
26 import 'package:dev_compiler/src/report.dart'; 28 import 'package:dev_compiler/src/report.dart';
27 import 'package:dev_compiler/src/utils.dart'; 29 import 'package:dev_compiler/src/utils.dart';
28 import 'dart_sdk.dart'; 30 import 'dart_sdk.dart';
29 import 'multi_package_resolver.dart'; 31 import 'multi_package_resolver.dart';
30 32
31 final _log = new logger.Logger('dev_compiler.src.resolver'); 33 final _log = new logger.Logger('dev_compiler.src.resolver');
32 34
35 String _implicitEntryHtml(String src) => '''
36 <html>
37 <body>
38 <script type="application/dart" src="$src"></script>
39 </body>
40 </html>
41 ''';
42
33 /// Encapsulates a resolver from the analyzer package. 43 /// Encapsulates a resolver from the analyzer package.
34 class TypeResolver { 44 class TypeResolver {
35 final InternalAnalysisContext context; 45 final InternalAnalysisContext context;
36 46
37 final Map<Uri, Source> _sources = <Uri, Source>{}; 47 final Map<Uri, Source> _sources = <Uri, Source>{};
38 48
39 TypeResolver(DartUriResolver sdkResolver, ResolverOptions options, 49 TypeResolver(DartUriResolver sdkResolver, ResolverOptions options,
40 {List otherResolvers}) 50 {List otherResolvers})
41 : context = _initContext(options) { 51 : context = _initContext(options) {
42 var resolvers = [sdkResolver]; 52 var resolvers = options.useImplicitHtml
53 ? [_createImplicitEntryResolver(options), sdkResolver]
54 : [sdkResolver];
43 if (otherResolvers == null) { 55 if (otherResolvers == null) {
44 resolvers.add(new FileUriResolver()); 56 resolvers.add(new FileUriResolver());
45 resolvers.add(options.useMultiPackage 57 resolvers.add(options.useMultiPackage
46 ? new MultiPackageResolver(options.packagePaths) 58 ? new MultiPackageResolver(options.packagePaths)
47 : new PackageUriResolver([new JavaFile(options.packageRoot)])); 59 : new PackageUriResolver([new JavaFile(options.packageRoot)]));
48 } else { 60 } else {
49 resolvers.addAll(otherResolvers); 61 resolvers.addAll(otherResolvers);
50 } 62 }
51 context.sourceFactory = new SourceFactory(resolvers); 63 context.sourceFactory = new SourceFactory(resolvers);
52 } 64 }
53 65
54 /// Creates a [TypeResolver] that uses a mock 'dart:' library contents. 66 /// Creates a [TypeResolver] that uses a mock 'dart:' library contents.
55 TypeResolver.fromMock( 67 TypeResolver.fromMock(
56 Map<String, String> mockSources, ResolverOptions options, 68 Map<String, String> mockSources, ResolverOptions options,
57 {List otherResolvers}) 69 {UriResolver entryResolver, List otherResolvers})
58 : this( 70 : this(
59 new MockDartSdk(mockSources, reportMissing: true).resolver, options, 71 new MockDartSdk(mockSources, reportMissing: true).resolver, options,
60 otherResolvers: otherResolvers); 72 otherResolvers: otherResolvers);
61 73
62 /// Creates a [TypeResolver] that uses the SDK at the given [sdkPath]. 74 /// Creates a [TypeResolver] that uses the SDK at the given [sdkPath].
63 TypeResolver.fromDir(String sdkPath, ResolverOptions options, 75 TypeResolver.fromDir(String sdkPath, ResolverOptions options,
64 {List otherResolvers}) 76 {UriResolver entryResolver, List otherResolvers})
65 : this( 77 : this(
66 new DartUriResolver(new DirectoryBasedDartSdk(new JavaFile(sdkPath))), 78 new DartUriResolver(new DirectoryBasedDartSdk(new JavaFile(sdkPath))),
67 options, otherResolvers: otherResolvers); 79 options, otherResolvers: otherResolvers);
68 80
81 UriResolver _createImplicitEntryResolver(ResolverOptions options) {
82 var entry = path.absolute(ResolverOptions.implicitHtmlFile);
83 var src = path.absolute(options.entryPointFile);
84 var index = <String, String>{'$entry': _implicitEntryHtml(src)};
85 return new InMemoryUriResolver(index, representNonExistingFiles: false);
86 }
87
69 /// Find the corresponding [Source] for [uri]. 88 /// Find the corresponding [Source] for [uri].
70 Source findSource(Uri uri) { 89 Source findSource(Uri uri) {
71 var source = _sources[uri]; 90 var source = _sources[uri];
72 if (source != null) return source; 91 if (source != null) return source;
73 return _sources[uri] = context.sourceFactory.forUri('$uri'); 92 return _sources[uri] = context.sourceFactory.forUri('$uri');
74 } 93 }
75 94
76 /// Log any errors encountered when resolving [source] and return whether any 95 /// Log any errors encountered when resolving [source] and return whether any
77 /// errors were found. 96 /// errors were found.
78 bool logErrors(Source source, CheckerReporter reporter) { 97 bool logErrors(Source source, CheckerReporter reporter) {
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 } 788 }
770 } 789 }
771 790
772 // Review note: no longer need to override visitFunctionExpression, this is 791 // Review note: no longer need to override visitFunctionExpression, this is
773 // handled by the analyzer internally. 792 // handled by the analyzer internally.
774 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? 793 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result?
775 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression 794 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression
776 // type in a (...) => expr or just the written type? 795 // type in a (...) => expr or just the written type?
777 796
778 } 797 }
OLDNEW
« no previous file with comments | « lib/devc.dart ('k') | lib/src/in_memory.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698