| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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 import 'package:analyzer/context/declared_variables.dart'; | 5 import 'package:analyzer/context/declared_variables.dart'; |
| 6 import 'package:analyzer/dart/ast/ast.dart'; | 6 import 'package:analyzer/dart/ast/ast.dart'; |
| 7 import 'package:analyzer/dart/ast/token.dart'; | 7 import 'package:analyzer/dart/ast/token.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/error/error.dart'; | 9 import 'package:analyzer/error/error.dart'; |
| 10 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
| 11 import 'package:analyzer/src/context/context.dart'; | 11 import 'package:analyzer/src/context/context.dart'; |
| 12 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 12 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 13 import 'package:analyzer/src/dart/ast/ast.dart'; | 13 import 'package:analyzer/src/dart/ast/ast.dart'; |
| 14 import 'package:analyzer/src/dart/constant/evaluation.dart'; | 14 import 'package:analyzer/src/dart/constant/evaluation.dart'; |
| 15 import 'package:analyzer/src/dart/constant/utilities.dart'; | 15 import 'package:analyzer/src/dart/constant/utilities.dart'; |
| 16 import 'package:analyzer/src/dart/element/element.dart'; | |
| 17 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 16 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 18 import 'package:analyzer/src/error/codes.dart'; | 17 import 'package:analyzer/src/error/codes.dart'; |
| 19 import 'package:analyzer/src/error/pending_error.dart'; | 18 import 'package:analyzer/src/error/pending_error.dart'; |
| 20 import 'package:analyzer/src/generated/declaration_resolver.dart'; | 19 import 'package:analyzer/src/generated/declaration_resolver.dart'; |
| 21 import 'package:analyzer/src/generated/engine.dart'; | 20 import 'package:analyzer/src/generated/engine.dart'; |
| 22 import 'package:analyzer/src/generated/error_verifier.dart'; | 21 import 'package:analyzer/src/generated/error_verifier.dart'; |
| 23 import 'package:analyzer/src/generated/parser.dart'; | 22 import 'package:analyzer/src/generated/parser.dart'; |
| 24 import 'package:analyzer/src/generated/resolver.dart'; | 23 import 'package:analyzer/src/generated/resolver.dart'; |
| 25 import 'package:analyzer/src/generated/source.dart'; | 24 import 'package:analyzer/src/generated/source.dart'; |
| 26 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 25 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 38 final AnalysisOptions _analysisOptions; | 37 final AnalysisOptions _analysisOptions; |
| 39 final DeclaredVariables _declaredVariables; | 38 final DeclaredVariables _declaredVariables; |
| 40 final SourceFactory _sourceFactory; | 39 final SourceFactory _sourceFactory; |
| 41 final FileSystemState _fsState; | 40 final FileSystemState _fsState; |
| 42 final SummaryDataStore _store; | 41 final SummaryDataStore _store; |
| 43 final FileState _library; | 42 final FileState _library; |
| 44 | 43 |
| 45 TypeProvider _typeProvider; | 44 TypeProvider _typeProvider; |
| 46 AnalysisContextImpl _context; | 45 AnalysisContextImpl _context; |
| 47 StoreBasedSummaryResynthesizer _resynthesizer; | 46 StoreBasedSummaryResynthesizer _resynthesizer; |
| 47 LibraryElement _libraryElement; |
| 48 | 48 |
| 49 final Map<FileState, RecordingErrorListener> _errorListeners = {}; | 49 final Map<FileState, RecordingErrorListener> _errorListeners = {}; |
| 50 final Map<FileState, ErrorReporter> _errorReporters = {}; | 50 final Map<FileState, ErrorReporter> _errorReporters = {}; |
| 51 final List<UsedImportedElements> _usedImportedElementsList = []; | 51 final List<UsedImportedElements> _usedImportedElementsList = []; |
| 52 final List<UsedLocalElements> _usedLocalElementsList = []; | 52 final List<UsedLocalElements> _usedLocalElementsList = []; |
| 53 final List<ConstantEvaluationTarget> _constants = []; | 53 final List<ConstantEvaluationTarget> _constants = []; |
| 54 | 54 |
| 55 AnalyzerImpl(this._analysisOptions, this._declaredVariables, | 55 AnalyzerImpl(this._analysisOptions, this._declaredVariables, |
| 56 this._sourceFactory, this._fsState, this._store, this._library); | 56 this._sourceFactory, this._fsState, this._store, this._library); |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * Compute analysis results for all units of the library. | 59 * Compute analysis results for all units of the library. |
| 60 */ | 60 */ |
| 61 Map<FileState, UnitAnalysisResult> analyze() { | 61 Map<FileState, UnitAnalysisResult> analyze() { |
| 62 Map<FileState, CompilationUnit> units = {}; | 62 Map<FileState, CompilationUnit> units = {}; |
| 63 | 63 |
| 64 // Parse all files. | 64 // Parse all files. |
| 65 units[_library] = _parse(_library); | 65 units[_library] = _parse(_library); |
| 66 for (FileState part in _library.partedFiles) { | 66 for (FileState part in _library.partedFiles) { |
| 67 units[part] = _parse(part); | 67 units[part] = _parse(part); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Resolve directives. | 70 // Resolve URIs in directives to corresponding sources. |
| 71 units.forEach((file, unit) { | 71 units.forEach((file, unit) { |
| 72 _resolveUriBasedDirectives(file, unit); | 72 _resolveUriBasedDirectives(file, unit); |
| 73 }); | 73 }); |
| 74 | 74 |
| 75 _createAnalysisContext(); | 75 _createAnalysisContext(); |
| 76 | 76 |
| 77 try { | 77 try { |
| 78 _resynthesizer = new StoreBasedSummaryResynthesizer( | 78 _resynthesizer = new StoreBasedSummaryResynthesizer( |
| 79 _context, _sourceFactory, _analysisOptions.strongMode, _store); | 79 _context, _sourceFactory, _analysisOptions.strongMode, _store); |
| 80 _typeProvider = _resynthesizer.typeProvider; | 80 _typeProvider = _resynthesizer.typeProvider; |
| 81 _context.typeProvider = _typeProvider; | 81 _context.typeProvider = _typeProvider; |
| 82 | 82 |
| 83 _libraryElement = _resynthesizer.getLibraryElement(_library.uriStr); |
| 84 |
| 85 _resolveDirectives(units); |
| 86 |
| 83 units.forEach((file, unit) { | 87 units.forEach((file, unit) { |
| 84 _resolveFile(file, unit); | 88 _resolveFile(file, unit); |
| 85 }); | 89 }); |
| 86 | 90 |
| 87 _computeConstants(); | 91 _computeConstants(); |
| 88 | 92 |
| 89 units.forEach((file, unit) { | 93 units.forEach((file, unit) { |
| 90 LibraryElement libraryElement = unit.element.library; | |
| 91 { | 94 { |
| 92 var visitor = new GatherUsedLocalElementsVisitor(libraryElement); | 95 var visitor = new GatherUsedLocalElementsVisitor(_libraryElement); |
| 93 unit.accept(visitor); | 96 unit.accept(visitor); |
| 94 _usedLocalElementsList.add(visitor.usedElements); | 97 _usedLocalElementsList.add(visitor.usedElements); |
| 95 } | 98 } |
| 96 { | 99 { |
| 97 var visitor = new GatherUsedImportedElementsVisitor(libraryElement); | 100 var visitor = new GatherUsedImportedElementsVisitor(_libraryElement); |
| 98 unit.accept(visitor); | 101 unit.accept(visitor); |
| 99 _usedImportedElementsList.add(visitor.usedElements); | 102 _usedImportedElementsList.add(visitor.usedElements); |
| 100 } | 103 } |
| 101 }); | 104 }); |
| 102 | 105 |
| 103 units.forEach((file, unit) { | 106 units.forEach((file, unit) { |
| 104 _computeVerifyErrorsAndHints(file, unit); | 107 _computeVerifyErrorsAndHints(file, unit); |
| 105 }); | 108 }); |
| 106 } finally { | 109 } finally { |
| 107 _context.dispose(); | 110 _context.dispose(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 135 for (_ConstantNode node in nodes) { | 138 for (_ConstantNode node in nodes) { |
| 136 if (!node.isEvaluated) { | 139 if (!node.isEvaluated) { |
| 137 new _ConstantWalker(evaluationEngine).walk(node); | 140 new _ConstantWalker(evaluationEngine).walk(node); |
| 138 } | 141 } |
| 139 } | 142 } |
| 140 } | 143 } |
| 141 | 144 |
| 142 void _computeVerifyErrorsAndHints(FileState file, CompilationUnit unit) { | 145 void _computeVerifyErrorsAndHints(FileState file, CompilationUnit unit) { |
| 143 RecordingErrorListener errorListener = _getErrorListener(file); | 146 RecordingErrorListener errorListener = _getErrorListener(file); |
| 144 CompilationUnitElement unitElement = unit.element; | 147 CompilationUnitElement unitElement = unit.element; |
| 145 LibraryElement libraryElement = unitElement.library; | |
| 146 | 148 |
| 147 // | 149 // |
| 148 // Use the ErrorVerifier to compute errors. | 150 // Use the ErrorVerifier to compute errors. |
| 149 // | 151 // |
| 150 List<PendingError> pendingErrors; | 152 List<PendingError> pendingErrors; |
| 151 { | 153 { |
| 152 RequiredConstantsComputer computer = | 154 RequiredConstantsComputer computer = |
| 153 new RequiredConstantsComputer(file.source); | 155 new RequiredConstantsComputer(file.source); |
| 154 unit.accept(computer); | 156 unit.accept(computer); |
| 155 pendingErrors = computer.pendingErrors; | 157 pendingErrors = computer.pendingErrors; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 173 | 175 |
| 174 // | 176 // |
| 175 // Validate the directives. | 177 // Validate the directives. |
| 176 // | 178 // |
| 177 _validateUriBasedDirectives(file, unit); | 179 _validateUriBasedDirectives(file, unit); |
| 178 | 180 |
| 179 // | 181 // |
| 180 // Use the ConstantVerifier to compute errors. | 182 // Use the ConstantVerifier to compute errors. |
| 181 // | 183 // |
| 182 ConstantVerifier constantVerifier = new ConstantVerifier( | 184 ConstantVerifier constantVerifier = new ConstantVerifier( |
| 183 errorReporter, libraryElement, _typeProvider, _declaredVariables); | 185 errorReporter, _libraryElement, _typeProvider, _declaredVariables); |
| 184 unit.accept(constantVerifier); | 186 unit.accept(constantVerifier); |
| 185 | 187 |
| 186 // | 188 // |
| 187 // Use the ErrorVerifier to compute errors. | 189 // Use the ErrorVerifier to compute errors. |
| 188 // | 190 // |
| 189 ErrorVerifier errorVerifier = new ErrorVerifier( | 191 ErrorVerifier errorVerifier = new ErrorVerifier( |
| 190 errorReporter, | 192 errorReporter, |
| 191 libraryElement, | 193 _libraryElement, |
| 192 _typeProvider, | 194 _typeProvider, |
| 193 new InheritanceManager(libraryElement), | 195 new InheritanceManager(_libraryElement), |
| 194 _analysisOptions.enableSuperMixins); | 196 _analysisOptions.enableSuperMixins); |
| 195 unit.accept(errorVerifier); | 197 unit.accept(errorVerifier); |
| 196 | 198 |
| 197 // | 199 // |
| 198 // Convert the pending errors into actual errors. | 200 // Convert the pending errors into actual errors. |
| 199 // | 201 // |
| 200 for (PendingError pendingError in pendingErrors) { | 202 for (PendingError pendingError in pendingErrors) { |
| 201 errorListener.onError(pendingError.toAnalysisError()); | 203 errorListener.onError(pendingError.toAnalysisError()); |
| 202 } | 204 } |
| 203 | 205 |
| 204 // | 206 // |
| 205 // Find dead code. | 207 // Find dead code. |
| 206 // | 208 // |
| 207 unit.accept( | 209 unit.accept( |
| 208 new DeadCodeVerifier(errorReporter, typeSystem: _context.typeSystem)); | 210 new DeadCodeVerifier(errorReporter, typeSystem: _context.typeSystem)); |
| 209 | 211 |
| 210 // Dart2js analysis. | 212 // Dart2js analysis. |
| 211 if (_analysisOptions.dart2jsHint) { | 213 if (_analysisOptions.dart2jsHint) { |
| 212 unit.accept(new Dart2JSVerifier(errorReporter)); | 214 unit.accept(new Dart2JSVerifier(errorReporter)); |
| 213 } | 215 } |
| 214 | 216 |
| 215 InheritanceManager inheritanceManager = new InheritanceManager( | 217 InheritanceManager inheritanceManager = new InheritanceManager( |
| 216 libraryElement, | 218 _libraryElement, |
| 217 includeAbstractFromSuperclasses: true); | 219 includeAbstractFromSuperclasses: true); |
| 218 | 220 |
| 219 unit.accept(new BestPracticesVerifier( | 221 unit.accept(new BestPracticesVerifier( |
| 220 errorReporter, _typeProvider, libraryElement, inheritanceManager, | 222 errorReporter, _typeProvider, _libraryElement, inheritanceManager, |
| 221 typeSystem: _context.typeSystem)); | 223 typeSystem: _context.typeSystem)); |
| 222 | 224 |
| 223 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager)); | 225 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager)); |
| 224 | 226 |
| 225 new ToDoFinder(errorReporter).findIn(unit); | 227 new ToDoFinder(errorReporter).findIn(unit); |
| 226 | 228 |
| 227 // Verify imports. | 229 // Verify imports. |
| 228 { | 230 { |
| 229 ImportsVerifier verifier = new ImportsVerifier(); | 231 ImportsVerifier verifier = new ImportsVerifier(); |
| 230 verifier.addImports(unit); | 232 verifier.addImports(unit); |
| 231 _usedImportedElementsList.forEach(verifier.removeUsedElements); | 233 _usedImportedElementsList.forEach(verifier.removeUsedElements); |
| 232 ErrorReporter errorReporter = _getErrorReporter(file); | 234 ErrorReporter errorReporter = _getErrorReporter(file); |
| 233 verifier.generateDuplicateImportHints(errorReporter); | 235 verifier.generateDuplicateImportHints(errorReporter); |
| 234 verifier.generateUnusedImportHints(errorReporter); | 236 verifier.generateUnusedImportHints(errorReporter); |
| 235 verifier.generateUnusedShownNameHints(errorReporter); | 237 verifier.generateUnusedShownNameHints(errorReporter); |
| 236 } | 238 } |
| 237 | 239 |
| 238 { | 240 { |
| 239 GatherUsedLocalElementsVisitor visitor = | 241 GatherUsedLocalElementsVisitor visitor = |
| 240 new GatherUsedLocalElementsVisitor(libraryElement); | 242 new GatherUsedLocalElementsVisitor(_libraryElement); |
| 241 unit.accept(visitor); | 243 unit.accept(visitor); |
| 242 } | 244 } |
| 243 | 245 |
| 244 // Unused local elements. | 246 // Unused local elements. |
| 245 { | 247 { |
| 246 UsedLocalElements usedElements = | 248 UsedLocalElements usedElements = |
| 247 new UsedLocalElements.merge(_usedLocalElementsList); | 249 new UsedLocalElements.merge(_usedLocalElementsList); |
| 248 UnusedLocalElementsVerifier visitor = | 250 UnusedLocalElementsVerifier visitor = |
| 249 new UnusedLocalElementsVerifier(errorListener, usedElements); | 251 new UnusedLocalElementsVerifier(errorListener, usedElements); |
| 250 unitElement.accept(visitor); | 252 unitElement.accept(visitor); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 265 _errorListeners.putIfAbsent(file, () => new RecordingErrorListener()); | 267 _errorListeners.putIfAbsent(file, () => new RecordingErrorListener()); |
| 266 | 268 |
| 267 ErrorReporter _getErrorReporter(FileState file) { | 269 ErrorReporter _getErrorReporter(FileState file) { |
| 268 return _errorReporters.putIfAbsent(file, () { | 270 return _errorReporters.putIfAbsent(file, () { |
| 269 RecordingErrorListener listener = _getErrorListener(file); | 271 RecordingErrorListener listener = _getErrorListener(file); |
| 270 return new ErrorReporter(listener, file.source); | 272 return new ErrorReporter(listener, file.source); |
| 271 }); | 273 }); |
| 272 } | 274 } |
| 273 | 275 |
| 274 /** | 276 /** |
| 277 * Return the name of the library that the given part is declared to be a |
| 278 * part of, or `null` if the part does not contain a part-of directive. |
| 279 */ |
| 280 _NameOrSource _getPartLibraryNameOrUri(Source partSource, |
| 281 CompilationUnit partUnit, List<Directive> directivesToResolve) { |
| 282 for (Directive directive in partUnit.directives) { |
| 283 if (directive is PartOfDirective) { |
| 284 directivesToResolve.add(directive); |
| 285 LibraryIdentifier libraryName = directive.libraryName; |
| 286 if (libraryName != null) { |
| 287 return new _NameOrSource(libraryName.name, null); |
| 288 } |
| 289 String uri = directive.uri?.stringValue; |
| 290 if (uri != null) { |
| 291 Source librarySource = _sourceFactory.resolveUri(partSource, uri); |
| 292 if (librarySource != null) { |
| 293 return new _NameOrSource(null, librarySource); |
| 294 } |
| 295 } |
| 296 } |
| 297 } |
| 298 return null; |
| 299 } |
| 300 |
| 301 /** |
| 275 * Return a new parsed unresolved [CompilationUnit]. | 302 * Return a new parsed unresolved [CompilationUnit]. |
| 276 */ | 303 */ |
| 277 CompilationUnit _parse(FileState file) { | 304 CompilationUnit _parse(FileState file) { |
| 278 RecordingErrorListener errorListener = _getErrorListener(file); | 305 RecordingErrorListener errorListener = _getErrorListener(file); |
| 279 | 306 |
| 280 CharSequenceReader reader = new CharSequenceReader(file.content); | 307 CharSequenceReader reader = new CharSequenceReader(file.content); |
| 281 Scanner scanner = new Scanner(file.source, reader, errorListener); | 308 Scanner scanner = new Scanner(file.source, reader, errorListener); |
| 282 scanner.scanGenericMethodComments = _analysisOptions.strongMode; | 309 scanner.scanGenericMethodComments = _analysisOptions.strongMode; |
| 283 Token token = scanner.tokenize(); | 310 Token token = scanner.tokenize(); |
| 284 LineInfo lineInfo = new LineInfo(scanner.lineStarts); | 311 LineInfo lineInfo = new LineInfo(scanner.lineStarts); |
| 285 | 312 |
| 286 Parser parser = new Parser(file.source, errorListener); | 313 Parser parser = new Parser(file.source, errorListener); |
| 287 parser.parseGenericMethodComments = _analysisOptions.strongMode; | 314 parser.parseGenericMethodComments = _analysisOptions.strongMode; |
| 315 parser.enableUriInPartOf = _analysisOptions.enableUriInPartOf; |
| 288 CompilationUnit unit = parser.parseCompilationUnit(token); | 316 CompilationUnit unit = parser.parseCompilationUnit(token); |
| 289 unit.lineInfo = lineInfo; | 317 unit.lineInfo = lineInfo; |
| 290 return unit; | 318 return unit; |
| 291 } | 319 } |
| 292 | 320 |
| 321 void _resolveDirectives(Map<FileState, CompilationUnit> units) { |
| 322 CompilationUnit definingCompilationUnit = units[_library]; |
| 323 |
| 324 var uriToElement = <Uri, CompilationUnitElement>{}; |
| 325 for (CompilationUnitElement partElement in _libraryElement.units) { |
| 326 uriToElement[partElement.source.uri] = partElement; |
| 327 } |
| 328 |
| 329 var sourceToUnit = <Source, CompilationUnit>{}; |
| 330 units.forEach((file, unit) { |
| 331 Source source = file.source; |
| 332 unit.element = uriToElement[source.uri]; |
| 333 sourceToUnit[source] = unit; |
| 334 }); |
| 335 |
| 336 ErrorReporter libraryErrorReporter = _getErrorReporter(_library); |
| 337 LibraryIdentifier libraryNameNode = null; |
| 338 bool hasPartDirective = false; |
| 339 var seenPartSources = new Set<Source>(); |
| 340 var directivesToResolve = <Directive>[]; |
| 341 for (Directive directive in definingCompilationUnit.directives) { |
| 342 if (directive is LibraryDirective) { |
| 343 libraryNameNode = directive.name; |
| 344 directivesToResolve.add(directive); |
| 345 } else if (directive is PartDirective) { |
| 346 hasPartDirective = true; |
| 347 StringLiteral partUri = directive.uri; |
| 348 Source partSource = directive.uriSource; |
| 349 CompilationUnit partUnit = sourceToUnit[partSource]; |
| 350 if (partUnit != null) { |
| 351 directive.element = partUnit.element; |
| 352 // |
| 353 // Validate that the part source is unique in the library. |
| 354 // |
| 355 if (!seenPartSources.add(partSource)) { |
| 356 libraryErrorReporter.reportErrorForNode( |
| 357 CompileTimeErrorCode.DUPLICATE_PART, partUri, [partSource.uri]); |
| 358 } |
| 359 // |
| 360 // Validate that the part contains a part-of directive with the same |
| 361 // name as the library. |
| 362 // |
| 363 if (_context.exists(partSource)) { |
| 364 _NameOrSource nameOrSource = _getPartLibraryNameOrUri( |
| 365 partSource, partUnit, directivesToResolve); |
| 366 if (nameOrSource == null) { |
| 367 libraryErrorReporter.reportErrorForNode( |
| 368 CompileTimeErrorCode.PART_OF_NON_PART, |
| 369 partUri, |
| 370 [partUri.toSource()]); |
| 371 } else { |
| 372 String name = nameOrSource.name; |
| 373 if (name != null) { |
| 374 if (libraryNameNode != null && libraryNameNode.name != name) { |
| 375 libraryErrorReporter.reportErrorForNode( |
| 376 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, |
| 377 partUri, |
| 378 [libraryNameNode.name, name]); |
| 379 } |
| 380 } else { |
| 381 Source source = nameOrSource.source; |
| 382 if (source != _library.source) { |
| 383 libraryErrorReporter.reportErrorForNode( |
| 384 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, |
| 385 partUri, |
| 386 [_library.uriStr, source.uri]); |
| 387 } |
| 388 } |
| 389 } |
| 390 } |
| 391 } |
| 392 } |
| 393 } |
| 394 |
| 395 if (hasPartDirective && libraryNameNode == null) { |
| 396 libraryErrorReporter.reportErrorForOffset( |
| 397 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART, 0, 0); |
| 398 } |
| 399 |
| 400 // |
| 401 // Resolve the relevant directives to the library element. |
| 402 // |
| 403 for (Directive directive in directivesToResolve) { |
| 404 directive.element = _libraryElement; |
| 405 } |
| 406 |
| 407 { |
| 408 // TODO(scheglov) fill these maps? |
| 409 DirectiveResolver resolver = new DirectiveResolver({}, {}, {}); |
| 410 definingCompilationUnit.accept(resolver); |
| 411 } |
| 412 } |
| 413 |
| 293 void _resolveFile(FileState file, CompilationUnit unit) { | 414 void _resolveFile(FileState file, CompilationUnit unit) { |
| 294 RecordingErrorListener errorListener = _getErrorListener(file); | 415 RecordingErrorListener errorListener = _getErrorListener(file); |
| 295 | 416 |
| 296 String libraryUri = _library.uri.toString(); | 417 CompilationUnitElement unitElement = unit.element; |
| 297 String unitUri = file.uri.toString(); | 418 Source source = file.source; |
| 298 CompilationUnitElement unitElement = _resynthesizer.getElement( | |
| 299 new ElementLocationImpl.con3(<String>[libraryUri, unitUri])); | |
| 300 LibraryElement libraryElement = unitElement.library; | |
| 301 | 419 |
| 302 // TODO(scheglov) Hack: set types for top-level variables | 420 // TODO(scheglov) Hack: set types for top-level variables |
| 303 // Otherwise TypeResolverVisitor will set declared types, and because we | 421 // Otherwise TypeResolverVisitor will set declared types, and because we |
| 304 // don't run InferStaticVariableTypeTask, we will stuck with these declared | 422 // don't run InferStaticVariableTypeTask, we will stuck with these declared |
| 305 // types. And we don't need to run this task - resynthesized elements have | 423 // types. And we don't need to run this task - resynthesized elements have |
| 306 // inferred types. | 424 // inferred types. |
| 307 for (var e in unitElement.topLevelVariables) { | 425 for (var e in unitElement.topLevelVariables) { |
| 308 if (!e.isSynthetic) { | 426 if (!e.isSynthetic) { |
| 309 e.type; | 427 e.type; |
| 310 } | 428 } |
| 311 } | 429 } |
| 312 | 430 |
| 313 new DeclarationResolver().resolve(unit, unitElement); | 431 new DeclarationResolver().resolve(unit, unitElement); |
| 314 | 432 |
| 315 if (file == _library) { | |
| 316 // TODO(scheglov) fill these maps? | |
| 317 DirectiveResolver resolver = new DirectiveResolver({}, {}, {}); | |
| 318 unit.accept(resolver); | |
| 319 } | |
| 320 | |
| 321 // TODO(scheglov) remove EnumMemberBuilder class | 433 // TODO(scheglov) remove EnumMemberBuilder class |
| 322 | 434 |
| 323 new TypeParameterBoundsResolver( | 435 new TypeParameterBoundsResolver( |
| 324 _typeProvider, libraryElement, unitElement.source, errorListener) | 436 _typeProvider, _libraryElement, source, errorListener) |
| 325 .resolveTypeBounds(unit); | 437 .resolveTypeBounds(unit); |
| 326 | 438 |
| 327 unit.accept(new TypeResolverVisitor( | 439 unit.accept(new TypeResolverVisitor( |
| 328 libraryElement, unitElement.source, _typeProvider, errorListener)); | 440 _libraryElement, source, _typeProvider, errorListener)); |
| 329 | 441 |
| 330 LibraryScope libraryScope = new LibraryScope(libraryElement); | 442 LibraryScope libraryScope = new LibraryScope(_libraryElement); |
| 331 unit.accept(new VariableResolverVisitor( | 443 unit.accept(new VariableResolverVisitor( |
| 332 libraryElement, unitElement.source, _typeProvider, errorListener, | 444 _libraryElement, source, _typeProvider, errorListener, |
| 333 nameScope: libraryScope)); | 445 nameScope: libraryScope)); |
| 334 | 446 |
| 335 unit.accept(new PartialResolverVisitor(libraryElement, unitElement.source, | 447 unit.accept(new PartialResolverVisitor(_libraryElement, source, |
| 336 _typeProvider, AnalysisErrorListener.NULL_LISTENER)); | 448 _typeProvider, AnalysisErrorListener.NULL_LISTENER)); |
| 337 | 449 |
| 338 // Nothing for RESOLVED_UNIT8? | 450 // Nothing for RESOLVED_UNIT8? |
| 339 // Nothing for RESOLVED_UNIT9? | 451 // Nothing for RESOLVED_UNIT9? |
| 340 // Nothing for RESOLVED_UNIT10? | 452 // Nothing for RESOLVED_UNIT10? |
| 341 | 453 |
| 342 unit.accept(new ResolverVisitor( | 454 unit.accept(new ResolverVisitor( |
| 343 libraryElement, unitElement.source, _typeProvider, errorListener)); | 455 _libraryElement, source, _typeProvider, errorListener)); |
| 344 | 456 |
| 345 // | 457 // |
| 346 // Find constants to compute. | 458 // Find constants to compute. |
| 347 // | 459 // |
| 348 { | 460 { |
| 349 ConstantFinder constantFinder = new ConstantFinder(); | 461 ConstantFinder constantFinder = new ConstantFinder(); |
| 350 unit.accept(constantFinder); | 462 unit.accept(constantFinder); |
| 351 _constants.addAll(constantFinder.constantsToCompute); | 463 _constants.addAll(constantFinder.constantsToCompute); |
| 352 } | 464 } |
| 353 } | 465 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 @override | 668 @override |
| 557 String setContents(Source source, String contents) { | 669 String setContents(Source source, String contents) { |
| 558 throw new UnimplementedError(); | 670 throw new UnimplementedError(); |
| 559 } | 671 } |
| 560 | 672 |
| 561 FileState _getFileForSource(Source source) { | 673 FileState _getFileForSource(Source source) { |
| 562 String path = source.fullName; | 674 String path = source.fullName; |
| 563 return fsState.getFileForPath(path); | 675 return fsState.getFileForPath(path); |
| 564 } | 676 } |
| 565 } | 677 } |
| 678 |
| 679 /** |
| 680 * Either the name or the source associated with a part-of directive. |
| 681 */ |
| 682 class _NameOrSource { |
| 683 final String name; |
| 684 final Source source; |
| 685 _NameOrSource(this.name, this.source); |
| 686 } |
| OLD | NEW |