| 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/file_system/file_system.dart'; |
| 11 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
| 11 import 'package:analyzer/src/generated/element.dart'; | 13 import 'package:analyzer/src/generated/element.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; | 15 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; |
| 14 import 'package:analyzer/src/generated/resolver.dart'; | 16 import 'package:analyzer/src/generated/resolver.dart'; |
| 15 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; | 17 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; |
| 16 import 'package:analyzer/src/generated/source.dart' show DartUriResolver; | 18 import 'package:analyzer/src/generated/source.dart' show DartUriResolver; |
| 17 import 'package:analyzer/src/generated/source.dart' show Source; | 19 import 'package:analyzer/src/generated/source.dart' show Source; |
| 18 import 'package:analyzer/src/generated/source_io.dart'; | 20 import 'package:analyzer/src/generated/source_io.dart'; |
| 19 import 'package:analyzer/src/generated/static_type_analyzer.dart'; | 21 import 'package:analyzer/src/generated/static_type_analyzer.dart'; |
| 20 import 'package:analyzer/src/generated/utilities_collection.dart' | 22 import 'package:analyzer/src/generated/utilities_collection.dart' |
| 21 show DirectedGraph; | 23 show DirectedGraph; |
| 22 import 'package:logging/logging.dart' as logger; | 24 import 'package:logging/logging.dart' as logger; |
| 23 import 'package:path/path.dart' as path; | 25 import 'package:path/path.dart' as path; |
| 24 | 26 |
| 25 import 'package:dev_compiler/src/in_memory.dart'; | |
| 26 import 'package:dev_compiler/src/options.dart'; | 27 import 'package:dev_compiler/src/options.dart'; |
| 27 import 'package:dev_compiler/src/utils.dart'; | 28 import 'package:dev_compiler/src/utils.dart'; |
| 28 import 'dart_sdk.dart'; | 29 import 'dart_sdk.dart'; |
| 29 import 'multi_package_resolver.dart'; | 30 import 'multi_package_resolver.dart'; |
| 30 | 31 |
| 31 final _log = new logger.Logger('dev_compiler.src.resolver'); | 32 final _log = new logger.Logger('dev_compiler.src.resolver'); |
| 32 | 33 |
| 33 String _implicitEntryHtml(String src) => ''' | 34 String _implicitEntryHtml(String src) => ''' |
| 34 <html> | 35 <html> |
| 35 <body> | 36 <body> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 TypeResolver.fromDir(String sdkPath, ResolverOptions options, | 74 TypeResolver.fromDir(String sdkPath, ResolverOptions options, |
| 74 {UriResolver entryResolver, List otherResolvers}) | 75 {UriResolver entryResolver, List otherResolvers}) |
| 75 : this( | 76 : this( |
| 76 new DartUriResolver(new DirectoryBasedDartSdk(new JavaFile(sdkPath))), | 77 new DartUriResolver(new DirectoryBasedDartSdk(new JavaFile(sdkPath))), |
| 77 options, otherResolvers: otherResolvers); | 78 options, otherResolvers: otherResolvers); |
| 78 } | 79 } |
| 79 | 80 |
| 80 UriResolver _createImplicitEntryResolver(ResolverOptions options) { | 81 UriResolver _createImplicitEntryResolver(ResolverOptions options) { |
| 81 var entry = path.absolute(ResolverOptions.implicitHtmlFile); | 82 var entry = path.absolute(ResolverOptions.implicitHtmlFile); |
| 82 var src = path.absolute(options.entryPointFile); | 83 var src = path.absolute(options.entryPointFile); |
| 83 var index = <String, String>{'$entry': _implicitEntryHtml(src)}; | 84 var provider = new MemoryResourceProvider(); |
| 84 return new InMemoryUriResolver(index, representNonExistingFiles: false); | 85 provider.newFile(entry, _implicitEntryHtml(src)); |
| 86 return new ResourceUriResolver(provider); |
| 85 } | 87 } |
| 86 | 88 |
| 87 /// Creates an analysis context that contains our restricted typing rules. | 89 /// Creates an analysis context that contains our restricted typing rules. |
| 88 InternalAnalysisContext _initContext(ResolverOptions options) { | 90 InternalAnalysisContext _initContext(ResolverOptions options) { |
| 89 var analysisOptions = new AnalysisOptionsImpl()..cacheSize = 512; | 91 var analysisOptions = new AnalysisOptionsImpl()..cacheSize = 512; |
| 90 AnalysisContextImpl res = AnalysisEngine.instance.createAnalysisContext(); | 92 AnalysisContextImpl res = AnalysisEngine.instance.createAnalysisContext(); |
| 91 res.analysisOptions = analysisOptions; | 93 res.analysisOptions = analysisOptions; |
| 92 res.libraryResolverFactory = | 94 res.libraryResolverFactory = |
| 93 (context) => new LibraryResolverWithInference(context, options); | 95 (context) => new LibraryResolverWithInference(context, options); |
| 94 return res; | 96 return res; |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 } | 752 } |
| 751 } | 753 } |
| 752 | 754 |
| 753 // Review note: no longer need to override visitFunctionExpression, this is | 755 // Review note: no longer need to override visitFunctionExpression, this is |
| 754 // handled by the analyzer internally. | 756 // handled by the analyzer internally. |
| 755 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? | 757 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? |
| 756 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression | 758 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression |
| 757 // type in a (...) => expr or just the written type? | 759 // type in a (...) => expr or just the written type? |
| 758 | 760 |
| 759 } | 761 } |
| OLD | NEW |