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

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/session.dart

Issue 2954153002: Add AnalysisSession to analyzer (Closed)
Patch Set: Created 3 years, 5 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
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'dart:async';
6
7 import 'package:analyzer/dart/analysis/results.dart';
8 import 'package:analyzer/dart/analysis/session.dart';
9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/dart/analysis/driver.dart' as driver;
11 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart';
12 import 'package:analyzer/src/generated/resolver.dart';
13 import 'package:analyzer/src/generated/source.dart';
14
15 /**
16 * A consistent view of the results of analyzing one or more files.
17 *
18 * The methods in this class that return analysis results will throw an
19 * 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
20 * inconsistent with any previously returned results.
21 */
22 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
23 /**
24 * The analysis driver performing analysis for this session.
25 */
26 final driver.AnalysisDriver _driver;
27
28 /**
29 * The type provider being used by the analysis driver.
30 */
31 TypeProvider _typeProvider;
32
33 /**
34 * The type system being used by the analysis driver.
35 */
36 TypeSystem _typeSystem;
37
38 /**
39 * Initialize a newly created analysis session.
40 */
41 DriverBasedAnalysisSession(this._driver);
42
43 @override
44 Future<TypeProvider> get typeProvider async {
45 _checkConsistency();
46 if (_typeProvider == null) {
47 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
48 LibraryElement asyncLibrary = await _driver.getLibraryByUri('dart:async');
49 _typeProvider = new TypeProviderImpl(coreLibrary, asyncLibrary);
50 }
51 return _typeProvider;
52 }
53
54 @override
55 Future<TypeSystem> get typeSystem async {
56 _checkConsistency();
57 if (_typeSystem == null) {
58 if (_driver.analysisOptions.strongMode) {
59 _typeSystem = new StrongTypeSystemImpl(await typeProvider);
60 } else {
61 _typeSystem = new TypeSystemImpl(await typeProvider);
62 }
63 }
64 return _typeSystem;
65 }
66
67 @override
68 Future<ErrorsResult> getErrors(String path) {
69 _checkConsistency();
70 return _driver.getErrors(path);
71 }
72
73 @override
74 Future<LibraryElement> getLibraryByUri(String uri) {
75 _checkConsistency();
76 return _driver.getLibraryByUri(uri);
77 }
78
79 @override
80 Future<ParseResult> getParsedAst(String path) {
81 _checkConsistency();
82 return _driver.parseFile(path);
83 }
84
85 @override
86 Future<ResolveResult> getResolvedAst(String path) {
87 _checkConsistency();
88 return _driver.getResult(path);
89 }
90
91 @override
92 Future<SourceKind> getSourceKind(String path) {
93 _checkConsistency();
94 return _driver.getSourceKind(path);
95 }
96
97 @override
98 Future<List<TopLevelDeclarationInSource>> getTopLevelDeclarations(
99 String name) {
100 _checkConsistency();
101 return _driver.getTopLevelNameDeclarations(name);
102 }
103
104 @override
105 Future<UnitElementResult> getUnitElement(String path) {
106 _checkConsistency();
107 return _driver.getUnitElement(path);
108 }
109
110 @override
111 Future<String> getUnitElementSignature(String path) {
112 _checkConsistency();
113 return _driver.getUnitElementSignature(path);
114 }
115
116 /**
117 * 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
118 * [InconsistentAnalysisException] if they might not be.
119 */
120 void _checkConsistency() {
121 if (_driver.currentSession != this) {
122 throw new InconsistentAnalysisException();
123 }
124 }
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698