| 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 /// 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'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 final _log = new logger.Logger('dev_compiler.src.resolver'); | 31 final _log = new logger.Logger('dev_compiler.src.resolver'); |
| 32 | 32 |
| 33 /// Encapsulates a resolver from the analyzer package. | 33 /// Encapsulates a resolver from the analyzer package. |
| 34 class TypeResolver { | 34 class TypeResolver { |
| 35 final InternalAnalysisContext context; | 35 final InternalAnalysisContext context; |
| 36 | 36 |
| 37 final Map<Uri, Source> _sources = <Uri, Source>{}; | 37 final Map<Uri, Source> _sources = <Uri, Source>{}; |
| 38 | 38 |
| 39 TypeResolver(DartUriResolver sdkResolver, ResolverOptions options, | 39 TypeResolver(DartUriResolver sdkResolver, ResolverOptions options, |
| 40 {List otherResolvers}) | 40 {UriResolver entryResolver, List otherResolvers}) |
| 41 : context = _initContext(options) { | 41 : context = _initContext(options) { |
| 42 var resolvers = [sdkResolver]; | 42 var resolvers = |
| 43 entryResolver == null ? [sdkResolver] : [entryResolver, sdkResolver]; |
| 43 if (otherResolvers == null) { | 44 if (otherResolvers == null) { |
| 44 resolvers.add(new FileUriResolver()); | 45 resolvers.add(new FileUriResolver()); |
| 45 resolvers.add(options.useMultiPackage | 46 resolvers.add(options.useMultiPackage |
| 46 ? new MultiPackageResolver(options.packagePaths) | 47 ? new MultiPackageResolver(options.packagePaths) |
| 47 : new PackageUriResolver([new JavaFile(options.packageRoot)])); | 48 : new PackageUriResolver([new JavaFile(options.packageRoot)])); |
| 48 } else { | 49 } else { |
| 49 resolvers.addAll(otherResolvers); | 50 resolvers.addAll(otherResolvers); |
| 50 } | 51 } |
| 51 context.sourceFactory = new SourceFactory(resolvers); | 52 context.sourceFactory = new SourceFactory(resolvers); |
| 52 } | 53 } |
| 53 | 54 |
| 54 /// Creates a [TypeResolver] that uses a mock 'dart:' library contents. | 55 /// Creates a [TypeResolver] that uses a mock 'dart:' library contents. |
| 55 TypeResolver.fromMock( | 56 TypeResolver.fromMock( |
| 56 Map<String, String> mockSources, ResolverOptions options, | 57 Map<String, String> mockSources, ResolverOptions options, |
| 57 {List otherResolvers}) | 58 {UriResolver entryResolver, List otherResolvers}) |
| 58 : this( | 59 : this( |
| 59 new MockDartSdk(mockSources, reportMissing: true).resolver, options, | 60 new MockDartSdk(mockSources, reportMissing: true).resolver, options, |
| 60 otherResolvers: otherResolvers); | 61 entryResolver: entryResolver, otherResolvers: otherResolvers); |
| 61 | 62 |
| 62 /// Creates a [TypeResolver] that uses the SDK at the given [sdkPath]. | 63 /// Creates a [TypeResolver] that uses the SDK at the given [sdkPath]. |
| 63 TypeResolver.fromDir(String sdkPath, ResolverOptions options, | 64 TypeResolver.fromDir(String sdkPath, ResolverOptions options, |
| 64 {List otherResolvers}) | 65 {UriResolver entryResolver, List otherResolvers}) |
| 65 : this( | 66 : this( |
| 66 new DartUriResolver(new DirectoryBasedDartSdk(new JavaFile(sdkPath))), | 67 new DartUriResolver(new DirectoryBasedDartSdk(new JavaFile(sdkPath))), |
| 67 options, otherResolvers: otherResolvers); | 68 options, |
| 69 entryResolver: entryResolver, otherResolvers: otherResolvers); |
| 68 | 70 |
| 69 /// Find the corresponding [Source] for [uri]. | 71 /// Find the corresponding [Source] for [uri]. |
| 70 Source findSource(Uri uri) { | 72 Source findSource(Uri uri) { |
| 71 var source = _sources[uri]; | 73 var source = _sources[uri]; |
| 72 if (source != null) return source; | 74 if (source != null) return source; |
| 73 return _sources[uri] = context.sourceFactory.forUri('$uri'); | 75 return _sources[uri] = context.sourceFactory.forUri('$uri'); |
| 74 } | 76 } |
| 75 | 77 |
| 76 /// Log any errors encountered when resolving [source] and return whether any | 78 /// Log any errors encountered when resolving [source] and return whether any |
| 77 /// errors were found. | 79 /// errors were found. |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 } | 771 } |
| 770 } | 772 } |
| 771 | 773 |
| 772 // Review note: no longer need to override visitFunctionExpression, this is | 774 // Review note: no longer need to override visitFunctionExpression, this is |
| 773 // handled by the analyzer internally. | 775 // handled by the analyzer internally. |
| 774 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? | 776 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? |
| 775 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression | 777 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression |
| 776 // type in a (...) => expr or just the written type? | 778 // type in a (...) => expr or just the written type? |
| 777 | 779 |
| 778 } | 780 } |
| OLD | NEW |