Chromium Code Reviews| Index: pkg/analyzer/lib/src/dart/analysis/session.dart |
| diff --git a/pkg/analyzer/lib/src/dart/analysis/session.dart b/pkg/analyzer/lib/src/dart/analysis/session.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5c86039e1c79c5b05871320740c7558996acc31b |
| --- /dev/null |
| +++ b/pkg/analyzer/lib/src/dart/analysis/session.dart |
| @@ -0,0 +1,125 @@ |
| +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import 'dart:async'; |
| + |
| +import 'package:analyzer/dart/analysis/results.dart'; |
| +import 'package:analyzer/dart/analysis/session.dart'; |
| +import 'package:analyzer/dart/element/element.dart'; |
| +import 'package:analyzer/src/dart/analysis/driver.dart' as driver; |
| +import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; |
| +import 'package:analyzer/src/generated/resolver.dart'; |
| +import 'package:analyzer/src/generated/source.dart'; |
| + |
| +/** |
| + * A consistent view of the results of analyzing one or more files. |
| + * |
| + * The methods in this class that return analysis results will throw an |
| + * InconsistentAnalysisException if the result to be returned might be |
|
scheglov
2017/06/26 15:30:03
Unless we add something new about details of imple
Brian Wilkerson
2017/06/26 16:06:19
Done
|
| + * inconsistent with any previously returned results. |
| + */ |
| +class DriverBasedAnalysisSession implements AnalysisSession { |
|
scheglov
2017/06/26 15:30:03
It sounds like we might have different implementat
Brian Wilkerson
2017/06/26 16:06:19
Done
|
| + /** |
| + * The analysis driver performing analysis for this session. |
| + */ |
| + final driver.AnalysisDriver _driver; |
| + |
| + /** |
| + * The type provider being used by the analysis driver. |
| + */ |
| + TypeProvider _typeProvider; |
| + |
| + /** |
| + * The type system being used by the analysis driver. |
| + */ |
| + TypeSystem _typeSystem; |
| + |
| + /** |
| + * Initialize a newly created analysis session. |
| + */ |
| + DriverBasedAnalysisSession(this._driver); |
| + |
| + @override |
| + Future<TypeProvider> get typeProvider async { |
| + _checkConsistency(); |
| + if (_typeProvider == null) { |
| + LibraryElement coreLibrary = await _driver.getLibraryByUri('dart:core'); |
|
scheglov
2017/06/26 15:30:03
This is a bit suboptimal - we will resynthesize th
Brian Wilkerson
2017/06/26 16:06:19
I would love to see this improved, but as it is cu
|
| + LibraryElement asyncLibrary = await _driver.getLibraryByUri('dart:async'); |
| + _typeProvider = new TypeProviderImpl(coreLibrary, asyncLibrary); |
| + } |
| + return _typeProvider; |
| + } |
| + |
| + @override |
| + Future<TypeSystem> get typeSystem async { |
| + _checkConsistency(); |
| + if (_typeSystem == null) { |
| + if (_driver.analysisOptions.strongMode) { |
| + _typeSystem = new StrongTypeSystemImpl(await typeProvider); |
| + } else { |
| + _typeSystem = new TypeSystemImpl(await typeProvider); |
| + } |
| + } |
| + return _typeSystem; |
| + } |
| + |
| + @override |
| + Future<ErrorsResult> getErrors(String path) { |
| + _checkConsistency(); |
| + return _driver.getErrors(path); |
| + } |
| + |
| + @override |
| + Future<LibraryElement> getLibraryByUri(String uri) { |
| + _checkConsistency(); |
| + return _driver.getLibraryByUri(uri); |
| + } |
| + |
| + @override |
| + Future<ParseResult> getParsedAst(String path) { |
| + _checkConsistency(); |
| + return _driver.parseFile(path); |
| + } |
| + |
| + @override |
| + Future<ResolveResult> getResolvedAst(String path) { |
| + _checkConsistency(); |
| + return _driver.getResult(path); |
| + } |
| + |
| + @override |
| + Future<SourceKind> getSourceKind(String path) { |
| + _checkConsistency(); |
| + return _driver.getSourceKind(path); |
| + } |
| + |
| + @override |
| + Future<List<TopLevelDeclarationInSource>> getTopLevelDeclarations( |
| + String name) { |
| + _checkConsistency(); |
| + return _driver.getTopLevelNameDeclarations(name); |
| + } |
| + |
| + @override |
| + Future<UnitElementResult> getUnitElement(String path) { |
| + _checkConsistency(); |
| + return _driver.getUnitElement(path); |
| + } |
| + |
| + @override |
| + Future<String> getUnitElementSignature(String path) { |
| + _checkConsistency(); |
| + return _driver.getUnitElementSignature(path); |
| + } |
| + |
| + /** |
| + * Check to see that results from this class will be consistent, and throw an |
|
scheglov
2017/06/26 15:30:03
class -> session
Brian Wilkerson
2017/06/26 16:06:19
Done
|
| + * [InconsistentAnalysisException] if they might not be. |
| + */ |
| + void _checkConsistency() { |
| + if (_driver.currentSession != this) { |
| + throw new InconsistentAnalysisException(); |
| + } |
| + } |
| +} |