| 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/dart/ast/ast.dart'; | 6 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/dart/ast/token.dart'; | 7 import 'package:analyzer/dart/ast/token.dart'; |
| 7 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/error/error.dart'; | 9 import 'package:analyzer/error/error.dart'; |
| 9 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
| 10 import 'package:analyzer/src/context/context.dart'; | 11 import 'package:analyzer/src/context/context.dart'; |
| 11 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 12 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 12 import 'package:analyzer/src/dart/ast/ast.dart'; | 13 import 'package:analyzer/src/dart/ast/ast.dart'; |
| 13 import 'package:analyzer/src/dart/constant/evaluation.dart'; | 14 import 'package:analyzer/src/dart/constant/evaluation.dart'; |
| 14 import 'package:analyzer/src/dart/constant/utilities.dart'; | 15 import 'package:analyzer/src/dart/constant/utilities.dart'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 27 import 'package:analyzer/src/task/strong/checker.dart'; | 28 import 'package:analyzer/src/task/strong/checker.dart'; |
| 28 import 'package:front_end/src/dependency_walker.dart'; | 29 import 'package:front_end/src/dependency_walker.dart'; |
| 29 import 'package:front_end/src/scanner/reader.dart'; | 30 import 'package:front_end/src/scanner/reader.dart'; |
| 30 | 31 |
| 31 /** | 32 /** |
| 32 * Analyzer of Dart files. | 33 * Analyzer of Dart files. |
| 33 * | 34 * |
| 34 * Work in progress, not ready to be used. | 35 * Work in progress, not ready to be used. |
| 35 */ | 36 */ |
| 36 class AnalyzerImpl { | 37 class AnalyzerImpl { |
| 37 final AnalysisOptions analysisOptions; | 38 final AnalysisOptions _analysisOptions; |
| 38 final SourceFactory sourceFactory; | 39 final DeclaredVariables _declaredVariables; |
| 39 final FileSystemState fsState; | 40 final SourceFactory _sourceFactory; |
| 40 final SummaryDataStore store; | 41 final FileSystemState _fsState; |
| 42 final SummaryDataStore _store; |
| 43 final FileState _library; |
| 41 | 44 |
| 42 AnalysisContextImpl analysisContext; | 45 TypeProvider _typeProvider; |
| 43 TypeProvider typeProvider; | 46 AnalysisContextImpl _context; |
| 44 StoreBasedSummaryResynthesizer resynthesizer; | 47 StoreBasedSummaryResynthesizer _resynthesizer; |
| 48 |
| 45 final Map<FileState, RecordingErrorListener> _errorListeners = {}; | 49 final Map<FileState, RecordingErrorListener> _errorListeners = {}; |
| 46 final Map<FileState, ErrorReporter> _errorReporters = {}; | 50 final Map<FileState, ErrorReporter> _errorReporters = {}; |
| 47 final List<UsedImportedElements> usedImportedElementsList = []; | 51 final List<UsedImportedElements> _usedImportedElementsList = []; |
| 48 final List<UsedLocalElements> usedLocalElementsList = []; | 52 final List<UsedLocalElements> _usedLocalElementsList = []; |
| 49 final List<ConstantEvaluationTarget> _constants = []; | 53 final List<ConstantEvaluationTarget> _constants = []; |
| 50 | 54 |
| 51 AnalyzerImpl( | 55 AnalyzerImpl(this._analysisOptions, this._declaredVariables, |
| 52 this.analysisOptions, this.sourceFactory, this.fsState, this.store); | 56 this._sourceFactory, this._fsState, this._store, this._library); |
| 53 | 57 |
| 54 /** | 58 /** |
| 55 * Compute analysis results for all units of the [library]. | 59 * Compute analysis results for all units of the library. |
| 56 */ | 60 */ |
| 57 Map<FileState, UnitAnalysisResult> analyze(FileState library) { | 61 Map<FileState, UnitAnalysisResult> analyze() { |
| 58 Map<FileState, CompilationUnit> units = {}; | 62 Map<FileState, CompilationUnit> units = {}; |
| 59 | 63 |
| 60 // Parse all files. | 64 // Parse all files. |
| 61 units[library] = _parse(library); | 65 units[_library] = _parse(_library); |
| 62 for (FileState part in library.partedFiles) { | 66 for (FileState part in _library.partedFiles) { |
| 63 units[part] = _parse(part); | 67 units[part] = _parse(part); |
| 64 } | 68 } |
| 65 | 69 |
| 66 // Resolve directives. | 70 // Resolve directives. |
| 67 units.forEach((file, unit) { | 71 units.forEach((file, unit) { |
| 68 _resolveUriBasedDirectives(file, unit); | 72 _resolveUriBasedDirectives(file, unit); |
| 69 }); | 73 }); |
| 70 | 74 |
| 71 _createAnalysisContext(); | 75 _createAnalysisContext(); |
| 72 | 76 |
| 73 try { | 77 try { |
| 74 resynthesizer = new StoreBasedSummaryResynthesizer( | 78 _resynthesizer = new StoreBasedSummaryResynthesizer( |
| 75 analysisContext, sourceFactory, analysisOptions.strongMode, store); | 79 _context, _sourceFactory, _analysisOptions.strongMode, _store); |
| 76 typeProvider = resynthesizer.typeProvider; | 80 _typeProvider = _resynthesizer.typeProvider; |
| 77 analysisContext.typeProvider = typeProvider; | 81 _context.typeProvider = _typeProvider; |
| 78 | 82 |
| 79 units.forEach((file, unit) { | 83 units.forEach((file, unit) { |
| 80 _resolveFile(analysisContext, library, file, unit); | 84 _resolveFile(file, unit); |
| 81 }); | 85 }); |
| 82 | 86 |
| 83 _computeConstants(); | 87 _computeConstants(); |
| 84 | 88 |
| 85 units.forEach((file, unit) { | 89 units.forEach((file, unit) { |
| 86 LibraryElement libraryElement = unit.element.library; | 90 LibraryElement libraryElement = unit.element.library; |
| 87 { | 91 { |
| 88 var visitor = new GatherUsedLocalElementsVisitor(libraryElement); | 92 var visitor = new GatherUsedLocalElementsVisitor(libraryElement); |
| 89 unit.accept(visitor); | 93 unit.accept(visitor); |
| 90 usedLocalElementsList.add(visitor.usedElements); | 94 _usedLocalElementsList.add(visitor.usedElements); |
| 91 } | 95 } |
| 92 { | 96 { |
| 93 var visitor = new GatherUsedImportedElementsVisitor(libraryElement); | 97 var visitor = new GatherUsedImportedElementsVisitor(libraryElement); |
| 94 unit.accept(visitor); | 98 unit.accept(visitor); |
| 95 usedImportedElementsList.add(visitor.usedElements); | 99 _usedImportedElementsList.add(visitor.usedElements); |
| 96 } | 100 } |
| 97 }); | 101 }); |
| 98 | 102 |
| 99 units.forEach((file, unit) { | 103 units.forEach((file, unit) { |
| 100 _computeVerifyErrorsAndHints(analysisContext, library, file, unit); | 104 _computeVerifyErrorsAndHints(file, unit); |
| 101 }); | 105 }); |
| 102 } finally { | 106 } finally { |
| 103 analysisContext.dispose(); | 107 _context.dispose(); |
| 104 } | 108 } |
| 105 | 109 |
| 106 // Return full results. | 110 // Return full results. |
| 107 Map<FileState, UnitAnalysisResult> results = {}; | 111 Map<FileState, UnitAnalysisResult> results = {}; |
| 108 units.forEach((file, unit) { | 112 units.forEach((file, unit) { |
| 109 List<AnalysisError> errors = _getErrorListener(file).errors; | 113 List<AnalysisError> errors = _getErrorListener(file).errors; |
| 110 results[file] = new UnitAnalysisResult(file, unit, errors); | 114 results[file] = new UnitAnalysisResult(file, unit, errors); |
| 111 }); | 115 }); |
| 112 return results; | 116 return results; |
| 113 } | 117 } |
| 114 | 118 |
| 115 /** | 119 /** |
| 116 * Compute [_constants] in all units. | 120 * Compute [_constants] in all units. |
| 117 */ | 121 */ |
| 118 void _computeConstants() { | 122 void _computeConstants() { |
| 119 ConstantEvaluationEngine evaluationEngine = new ConstantEvaluationEngine( | 123 ConstantEvaluationEngine evaluationEngine = new ConstantEvaluationEngine( |
| 120 analysisContext.typeProvider, analysisContext.declaredVariables, | 124 _typeProvider, _declaredVariables, |
| 121 typeSystem: analysisContext.typeSystem); | 125 typeSystem: _context.typeSystem); |
| 122 | 126 |
| 123 List<_ConstantNode> nodes = []; | 127 List<_ConstantNode> nodes = []; |
| 124 Map<ConstantEvaluationTarget, _ConstantNode> nodeMap = {}; | 128 Map<ConstantEvaluationTarget, _ConstantNode> nodeMap = {}; |
| 125 for (ConstantEvaluationTarget constant in _constants) { | 129 for (ConstantEvaluationTarget constant in _constants) { |
| 126 var node = new _ConstantNode(evaluationEngine, nodeMap, constant); | 130 var node = new _ConstantNode(evaluationEngine, nodeMap, constant); |
| 127 nodes.add(node); | 131 nodes.add(node); |
| 128 nodeMap[constant] = node; | 132 nodeMap[constant] = node; |
| 129 } | 133 } |
| 130 | 134 |
| 131 for (_ConstantNode node in nodes) { | 135 for (_ConstantNode node in nodes) { |
| 132 if (!node.isEvaluated) { | 136 if (!node.isEvaluated) { |
| 133 new _ConstantWalker(evaluationEngine).walk(node); | 137 new _ConstantWalker(evaluationEngine).walk(node); |
| 134 } | 138 } |
| 135 } | 139 } |
| 136 } | 140 } |
| 137 | 141 |
| 138 void _computeVerifyErrorsAndHints(AnalysisContext analysisContext, | 142 void _computeVerifyErrorsAndHints(FileState file, CompilationUnit unit) { |
| 139 FileState libraryFile, FileState file, CompilationUnit unit) { | |
| 140 RecordingErrorListener errorListener = _getErrorListener(file); | 143 RecordingErrorListener errorListener = _getErrorListener(file); |
| 141 CompilationUnitElement unitElement = unit.element; | 144 CompilationUnitElement unitElement = unit.element; |
| 142 LibraryElement libraryElement = unitElement.library; | 145 LibraryElement libraryElement = unitElement.library; |
| 143 | 146 |
| 144 // | 147 // |
| 145 // Use the ErrorVerifier to compute errors. | 148 // Use the ErrorVerifier to compute errors. |
| 146 // | 149 // |
| 147 List<PendingError> pendingErrors; | 150 List<PendingError> pendingErrors; |
| 148 { | 151 { |
| 149 RequiredConstantsComputer computer = | 152 RequiredConstantsComputer computer = |
| 150 new RequiredConstantsComputer(file.source); | 153 new RequiredConstantsComputer(file.source); |
| 151 unit.accept(computer); | 154 unit.accept(computer); |
| 152 pendingErrors = computer.pendingErrors; | 155 pendingErrors = computer.pendingErrors; |
| 153 List<ConstantEvaluationTarget> requiredConstants = | 156 List<ConstantEvaluationTarget> requiredConstants = |
| 154 computer.requiredConstants; | 157 computer.requiredConstants; |
| 155 } | 158 } |
| 156 | 159 |
| 157 if (analysisOptions.strongMode) { | 160 if (_analysisOptions.strongMode) { |
| 158 AnalysisOptionsImpl options = analysisOptions as AnalysisOptionsImpl; | 161 AnalysisOptionsImpl options = _analysisOptions as AnalysisOptionsImpl; |
| 159 CodeChecker checker = new CodeChecker( | 162 CodeChecker checker = new CodeChecker( |
| 160 typeProvider, | 163 _typeProvider, |
| 161 new StrongTypeSystemImpl(typeProvider, | 164 new StrongTypeSystemImpl(_typeProvider, |
| 162 implicitCasts: options.implicitCasts, | 165 implicitCasts: options.implicitCasts, |
| 163 nonnullableTypes: options.nonnullableTypes), | 166 nonnullableTypes: options.nonnullableTypes), |
| 164 errorListener, | 167 errorListener, |
| 165 options); | 168 options); |
| 166 checker.visitCompilationUnit(unit); | 169 checker.visitCompilationUnit(unit); |
| 167 } | 170 } |
| 168 | 171 |
| 169 var errorReporter = _getErrorReporter(file); | 172 var errorReporter = _getErrorReporter(file); |
| 170 | 173 |
| 171 // | 174 // |
| 172 // Validate the directives. | 175 // Validate the directives. |
| 173 // | 176 // |
| 174 _validateUriBasedDirectives(file, unit); | 177 _validateUriBasedDirectives(file, unit); |
| 175 | 178 |
| 176 // | 179 // |
| 177 // Use the ConstantVerifier to compute errors. | 180 // Use the ConstantVerifier to compute errors. |
| 178 // | 181 // |
| 179 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, | 182 ConstantVerifier constantVerifier = new ConstantVerifier( |
| 180 libraryElement, typeProvider, analysisContext.declaredVariables); | 183 errorReporter, libraryElement, _typeProvider, _declaredVariables); |
| 181 unit.accept(constantVerifier); | 184 unit.accept(constantVerifier); |
| 182 | 185 |
| 183 // | 186 // |
| 184 // Use the ErrorVerifier to compute errors. | 187 // Use the ErrorVerifier to compute errors. |
| 185 // | 188 // |
| 186 ErrorVerifier errorVerifier = new ErrorVerifier( | 189 ErrorVerifier errorVerifier = new ErrorVerifier( |
| 187 errorReporter, | 190 errorReporter, |
| 188 libraryElement, | 191 libraryElement, |
| 189 typeProvider, | 192 _typeProvider, |
| 190 new InheritanceManager(libraryElement), | 193 new InheritanceManager(libraryElement), |
| 191 analysisOptions.enableSuperMixins); | 194 _analysisOptions.enableSuperMixins); |
| 192 unit.accept(errorVerifier); | 195 unit.accept(errorVerifier); |
| 193 | 196 |
| 194 // | 197 // |
| 195 // Convert the pending errors into actual errors. | 198 // Convert the pending errors into actual errors. |
| 196 // | 199 // |
| 197 for (PendingError pendingError in pendingErrors) { | 200 for (PendingError pendingError in pendingErrors) { |
| 198 errorListener.onError(pendingError.toAnalysisError()); | 201 errorListener.onError(pendingError.toAnalysisError()); |
| 199 } | 202 } |
| 200 | 203 |
| 201 // | 204 // |
| 202 // Find dead code. | 205 // Find dead code. |
| 203 // | 206 // |
| 204 unit.accept(new DeadCodeVerifier(errorReporter, | 207 unit.accept( |
| 205 typeSystem: analysisContext.typeSystem)); | 208 new DeadCodeVerifier(errorReporter, typeSystem: _context.typeSystem)); |
| 206 | 209 |
| 207 // Dart2js analysis. | 210 // Dart2js analysis. |
| 208 if (analysisOptions.dart2jsHint) { | 211 if (_analysisOptions.dart2jsHint) { |
| 209 unit.accept(new Dart2JSVerifier(errorReporter)); | 212 unit.accept(new Dart2JSVerifier(errorReporter)); |
| 210 } | 213 } |
| 211 | 214 |
| 212 InheritanceManager inheritanceManager = new InheritanceManager( | 215 InheritanceManager inheritanceManager = new InheritanceManager( |
| 213 libraryElement, | 216 libraryElement, |
| 214 includeAbstractFromSuperclasses: true); | 217 includeAbstractFromSuperclasses: true); |
| 215 | 218 |
| 216 unit.accept(new BestPracticesVerifier( | 219 unit.accept(new BestPracticesVerifier( |
| 217 errorReporter, typeProvider, libraryElement, inheritanceManager, | 220 errorReporter, _typeProvider, libraryElement, inheritanceManager, |
| 218 typeSystem: analysisContext.typeSystem)); | 221 typeSystem: _context.typeSystem)); |
| 219 | 222 |
| 220 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager)); | 223 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager)); |
| 221 | 224 |
| 222 new ToDoFinder(errorReporter).findIn(unit); | 225 new ToDoFinder(errorReporter).findIn(unit); |
| 223 | 226 |
| 224 // Verify imports. | 227 // Verify imports. |
| 225 { | 228 { |
| 226 ImportsVerifier verifier = new ImportsVerifier(); | 229 ImportsVerifier verifier = new ImportsVerifier(); |
| 227 verifier.addImports(unit); | 230 verifier.addImports(unit); |
| 228 usedImportedElementsList.forEach(verifier.removeUsedElements); | 231 _usedImportedElementsList.forEach(verifier.removeUsedElements); |
| 229 ErrorReporter errorReporter = _getErrorReporter(file); | 232 ErrorReporter errorReporter = _getErrorReporter(file); |
| 230 verifier.generateDuplicateImportHints(errorReporter); | 233 verifier.generateDuplicateImportHints(errorReporter); |
| 231 verifier.generateUnusedImportHints(errorReporter); | 234 verifier.generateUnusedImportHints(errorReporter); |
| 232 verifier.generateUnusedShownNameHints(errorReporter); | 235 verifier.generateUnusedShownNameHints(errorReporter); |
| 233 } | 236 } |
| 234 | 237 |
| 235 { | 238 { |
| 236 GatherUsedLocalElementsVisitor visitor = | 239 GatherUsedLocalElementsVisitor visitor = |
| 237 new GatherUsedLocalElementsVisitor(libraryElement); | 240 new GatherUsedLocalElementsVisitor(libraryElement); |
| 238 unit.accept(visitor); | 241 unit.accept(visitor); |
| 239 } | 242 } |
| 240 | 243 |
| 241 // Unused local elements. | 244 // Unused local elements. |
| 242 { | 245 { |
| 243 UsedLocalElements usedElements = | 246 UsedLocalElements usedElements = |
| 244 new UsedLocalElements.merge(usedLocalElementsList); | 247 new UsedLocalElements.merge(_usedLocalElementsList); |
| 245 UnusedLocalElementsVerifier visitor = | 248 UnusedLocalElementsVerifier visitor = |
| 246 new UnusedLocalElementsVerifier(errorListener, usedElements); | 249 new UnusedLocalElementsVerifier(errorListener, usedElements); |
| 247 unitElement.accept(visitor); | 250 unitElement.accept(visitor); |
| 248 } | 251 } |
| 249 } | 252 } |
| 250 | 253 |
| 251 void _createAnalysisContext() { | 254 void _createAnalysisContext() { |
| 252 AnalysisContextImpl analysisContext = | 255 AnalysisContextImpl analysisContext = |
| 253 AnalysisEngine.instance.createAnalysisContext(); | 256 AnalysisEngine.instance.createAnalysisContext(); |
| 254 analysisContext.analysisOptions = analysisOptions; | 257 analysisContext.analysisOptions = _analysisOptions; |
| 255 analysisContext.sourceFactory = sourceFactory.clone(); | 258 analysisContext.declaredVariables.addAll(_declaredVariables); |
| 256 analysisContext.contentCache = new _ContentCacheWrapper(fsState); | 259 analysisContext.sourceFactory = _sourceFactory.clone(); |
| 257 this.analysisContext = analysisContext; | 260 analysisContext.contentCache = new _ContentCacheWrapper(_fsState); |
| 261 this._context = analysisContext; |
| 258 } | 262 } |
| 259 | 263 |
| 260 RecordingErrorListener _getErrorListener(FileState file) => | 264 RecordingErrorListener _getErrorListener(FileState file) => |
| 261 _errorListeners.putIfAbsent(file, () => new RecordingErrorListener()); | 265 _errorListeners.putIfAbsent(file, () => new RecordingErrorListener()); |
| 262 | 266 |
| 263 ErrorReporter _getErrorReporter(FileState file) { | 267 ErrorReporter _getErrorReporter(FileState file) { |
| 264 return _errorReporters.putIfAbsent(file, () { | 268 return _errorReporters.putIfAbsent(file, () { |
| 265 RecordingErrorListener listener = _getErrorListener(file); | 269 RecordingErrorListener listener = _getErrorListener(file); |
| 266 return new ErrorReporter(listener, file.source); | 270 return new ErrorReporter(listener, file.source); |
| 267 }); | 271 }); |
| 268 } | 272 } |
| 269 | 273 |
| 270 /** | 274 /** |
| 271 * Return a new parsed unresolved [CompilationUnit]. | 275 * Return a new parsed unresolved [CompilationUnit]. |
| 272 */ | 276 */ |
| 273 CompilationUnit _parse(FileState file) { | 277 CompilationUnit _parse(FileState file) { |
| 274 RecordingErrorListener errorListener = _getErrorListener(file); | 278 RecordingErrorListener errorListener = _getErrorListener(file); |
| 275 | 279 |
| 276 CharSequenceReader reader = new CharSequenceReader(file.content); | 280 CharSequenceReader reader = new CharSequenceReader(file.content); |
| 277 Scanner scanner = new Scanner(file.source, reader, errorListener); | 281 Scanner scanner = new Scanner(file.source, reader, errorListener); |
| 278 scanner.scanGenericMethodComments = analysisOptions.strongMode; | 282 scanner.scanGenericMethodComments = _analysisOptions.strongMode; |
| 279 Token token = scanner.tokenize(); | 283 Token token = scanner.tokenize(); |
| 280 LineInfo lineInfo = new LineInfo(scanner.lineStarts); | 284 LineInfo lineInfo = new LineInfo(scanner.lineStarts); |
| 281 | 285 |
| 282 Parser parser = new Parser(file.source, errorListener); | 286 Parser parser = new Parser(file.source, errorListener); |
| 283 parser.parseGenericMethodComments = analysisOptions.strongMode; | 287 parser.parseGenericMethodComments = _analysisOptions.strongMode; |
| 284 CompilationUnit unit = parser.parseCompilationUnit(token); | 288 CompilationUnit unit = parser.parseCompilationUnit(token); |
| 285 unit.lineInfo = lineInfo; | 289 unit.lineInfo = lineInfo; |
| 286 return unit; | 290 return unit; |
| 287 } | 291 } |
| 288 | 292 |
| 289 void _resolveFile(AnalysisContext analysisContext, FileState library, | 293 void _resolveFile(FileState file, CompilationUnit unit) { |
| 290 FileState file, CompilationUnit unit) { | |
| 291 if (!file.exists) { | 294 if (!file.exists) { |
| 292 Source source = file.source; | 295 Source source = file.source; |
| 293 var unitElement = new CompilationUnitElementImpl(source.shortName); | 296 var unitElement = new CompilationUnitElementImpl(source.shortName); |
| 294 var libraryElement = new LibraryElementImpl(analysisContext, null, -1, 0); | 297 var libraryElement = new LibraryElementImpl(_context, null, -1, 0); |
| 295 unitElement.source = source; | 298 unitElement.source = source; |
| 296 unitElement.librarySource = source; | 299 unitElement.librarySource = source; |
| 297 libraryElement.definingCompilationUnit = unitElement; | 300 libraryElement.definingCompilationUnit = unitElement; |
| 298 unit.element = unitElement; | 301 unit.element = unitElement; |
| 299 return; | 302 return; |
| 300 } | 303 } |
| 301 | 304 |
| 302 RecordingErrorListener errorListener = _getErrorListener(file); | 305 RecordingErrorListener errorListener = _getErrorListener(file); |
| 303 | 306 |
| 304 String libraryUri = library.uri.toString(); | 307 String libraryUri = _library.uri.toString(); |
| 305 String unitUri = file.uri.toString(); | 308 String unitUri = file.uri.toString(); |
| 306 CompilationUnitElement unitElement = resynthesizer.getElement( | 309 CompilationUnitElement unitElement = _resynthesizer.getElement( |
| 307 new ElementLocationImpl.con3(<String>[libraryUri, unitUri])); | 310 new ElementLocationImpl.con3(<String>[libraryUri, unitUri])); |
| 308 LibraryElement libraryElement = unitElement.library; | 311 LibraryElement libraryElement = unitElement.library; |
| 309 | 312 |
| 310 // TODO(scheglov) Hack: set types for top-level variables | 313 // TODO(scheglov) Hack: set types for top-level variables |
| 311 // Otherwise TypeResolverVisitor will set declared types, and because we | 314 // Otherwise TypeResolverVisitor will set declared types, and because we |
| 312 // don't run InferStaticVariableTypeTask, we will stuck with these declared | 315 // don't run InferStaticVariableTypeTask, we will stuck with these declared |
| 313 // types. And we don't need to run this task - resynthesized elements have | 316 // types. And we don't need to run this task - resynthesized elements have |
| 314 // inferred types. | 317 // inferred types. |
| 315 for (var e in unitElement.topLevelVariables) { | 318 for (var e in unitElement.topLevelVariables) { |
| 316 if (!e.isSynthetic) { | 319 if (!e.isSynthetic) { |
| 317 e.type; | 320 e.type; |
| 318 } | 321 } |
| 319 } | 322 } |
| 320 | 323 |
| 321 new DeclarationResolver().resolve(unit, unitElement); | 324 new DeclarationResolver().resolve(unit, unitElement); |
| 322 | 325 |
| 323 if (file == library) { | 326 if (file == _library) { |
| 324 // TODO(scheglov) fill these maps? | 327 // TODO(scheglov) fill these maps? |
| 325 DirectiveResolver resolver = new DirectiveResolver({}, {}, {}); | 328 DirectiveResolver resolver = new DirectiveResolver({}, {}, {}); |
| 326 unit.accept(resolver); | 329 unit.accept(resolver); |
| 327 } | 330 } |
| 328 | 331 |
| 329 // TODO(scheglov) remove EnumMemberBuilder class | 332 // TODO(scheglov) remove EnumMemberBuilder class |
| 330 | 333 |
| 331 new TypeParameterBoundsResolver( | 334 new TypeParameterBoundsResolver( |
| 332 typeProvider, libraryElement, unitElement.source, errorListener) | 335 _typeProvider, libraryElement, unitElement.source, errorListener) |
| 333 .resolveTypeBounds(unit); | 336 .resolveTypeBounds(unit); |
| 334 | 337 |
| 335 unit.accept(new TypeResolverVisitor( | 338 unit.accept(new TypeResolverVisitor( |
| 336 libraryElement, unitElement.source, typeProvider, errorListener)); | 339 libraryElement, unitElement.source, _typeProvider, errorListener)); |
| 337 | 340 |
| 338 LibraryScope libraryScope = new LibraryScope(libraryElement); | 341 LibraryScope libraryScope = new LibraryScope(libraryElement); |
| 339 unit.accept(new VariableResolverVisitor( | 342 unit.accept(new VariableResolverVisitor( |
| 340 libraryElement, unitElement.source, typeProvider, errorListener, | 343 libraryElement, unitElement.source, _typeProvider, errorListener, |
| 341 nameScope: libraryScope)); | 344 nameScope: libraryScope)); |
| 342 | 345 |
| 343 unit.accept(new PartialResolverVisitor(libraryElement, unitElement.source, | 346 unit.accept(new PartialResolverVisitor(libraryElement, unitElement.source, |
| 344 typeProvider, AnalysisErrorListener.NULL_LISTENER)); | 347 _typeProvider, AnalysisErrorListener.NULL_LISTENER)); |
| 345 | 348 |
| 346 // Nothing for RESOLVED_UNIT8? | 349 // Nothing for RESOLVED_UNIT8? |
| 347 // Nothing for RESOLVED_UNIT9? | 350 // Nothing for RESOLVED_UNIT9? |
| 348 // Nothing for RESOLVED_UNIT10? | 351 // Nothing for RESOLVED_UNIT10? |
| 349 | 352 |
| 350 unit.accept(new ResolverVisitor( | 353 unit.accept(new ResolverVisitor( |
| 351 libraryElement, unitElement.source, typeProvider, errorListener)); | 354 libraryElement, unitElement.source, _typeProvider, errorListener)); |
| 352 | 355 |
| 353 // | 356 // |
| 354 // Find constants to compute. | 357 // Find constants to compute. |
| 355 // | 358 // |
| 356 { | 359 { |
| 357 ConstantFinder constantFinder = new ConstantFinder(); | 360 ConstantFinder constantFinder = new ConstantFinder(); |
| 358 unit.accept(constantFinder); | 361 unit.accept(constantFinder); |
| 359 _constants.addAll(constantFinder.constantsToCompute); | 362 _constants.addAll(constantFinder.constantsToCompute); |
| 360 } | 363 } |
| 361 } | 364 } |
| 362 | 365 |
| 363 /** | 366 /** |
| 364 * Return the result of resolve the given [uriContent], reporting errors | 367 * Return the result of resolve the given [uriContent], reporting errors |
| 365 * against the [uriLiteral]. | 368 * against the [uriLiteral]. |
| 366 */ | 369 */ |
| 367 Source _resolveUri(FileState file, bool isImport, StringLiteral uriLiteral, | 370 Source _resolveUri(FileState file, bool isImport, StringLiteral uriLiteral, |
| 368 String uriContent) { | 371 String uriContent) { |
| 369 UriValidationCode code = | 372 UriValidationCode code = |
| 370 UriBasedDirectiveImpl.validateUri(isImport, uriLiteral, uriContent); | 373 UriBasedDirectiveImpl.validateUri(isImport, uriLiteral, uriContent); |
| 371 if (code == null) { | 374 if (code == null) { |
| 372 try { | 375 try { |
| 373 Uri.parse(uriContent); | 376 Uri.parse(uriContent); |
| 374 } on FormatException { | 377 } on FormatException { |
| 375 return null; | 378 return null; |
| 376 } | 379 } |
| 377 return sourceFactory.resolveUri(file.source, uriContent); | 380 return _sourceFactory.resolveUri(file.source, uriContent); |
| 378 } else if (code == UriValidationCode.URI_WITH_DART_EXT_SCHEME) { | 381 } else if (code == UriValidationCode.URI_WITH_DART_EXT_SCHEME) { |
| 379 return null; | 382 return null; |
| 380 } else if (code == UriValidationCode.URI_WITH_INTERPOLATION) { | 383 } else if (code == UriValidationCode.URI_WITH_INTERPOLATION) { |
| 381 _getErrorReporter(file).reportErrorForNode( | 384 _getErrorReporter(file).reportErrorForNode( |
| 382 CompileTimeErrorCode.URI_WITH_INTERPOLATION, uriLiteral); | 385 CompileTimeErrorCode.URI_WITH_INTERPOLATION, uriLiteral); |
| 383 return null; | 386 return null; |
| 384 } else if (code == UriValidationCode.INVALID_URI) { | 387 } else if (code == UriValidationCode.INVALID_URI) { |
| 385 _getErrorReporter(file).reportErrorForNode( | 388 _getErrorReporter(file).reportErrorForNode( |
| 386 CompileTimeErrorCode.INVALID_URI, uriLiteral, [uriContent]); | 389 CompileTimeErrorCode.INVALID_URI, uriLiteral, [uriContent]); |
| 387 return null; | 390 return null; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 403 } | 406 } |
| 404 | 407 |
| 405 /** | 408 /** |
| 406 * Check the given [directive] to see if the referenced source exists and | 409 * Check the given [directive] to see if the referenced source exists and |
| 407 * report an error if it does not. | 410 * report an error if it does not. |
| 408 */ | 411 */ |
| 409 void _validateUriBasedDirective( | 412 void _validateUriBasedDirective( |
| 410 FileState file, UriBasedDirectiveImpl directive) { | 413 FileState file, UriBasedDirectiveImpl directive) { |
| 411 Source source = directive.uriSource; | 414 Source source = directive.uriSource; |
| 412 if (source != null) { | 415 if (source != null) { |
| 413 if (analysisContext.exists(source)) { | 416 if (_context.exists(source)) { |
| 414 return; | 417 return; |
| 415 } | 418 } |
| 416 } else { | 419 } else { |
| 417 // Don't report errors already reported by ParseDartTask.resolveDirective | 420 // Don't report errors already reported by ParseDartTask.resolveDirective |
| 421 // TODO(scheglov) we don't use this task here |
| 418 if (directive.validate() != null) { | 422 if (directive.validate() != null) { |
| 419 return; | 423 return; |
| 420 } | 424 } |
| 421 } | 425 } |
| 422 StringLiteral uriLiteral = directive.uri; | 426 StringLiteral uriLiteral = directive.uri; |
| 423 CompileTimeErrorCode errorCode = CompileTimeErrorCode.URI_DOES_NOT_EXIST; | 427 CompileTimeErrorCode errorCode = CompileTimeErrorCode.URI_DOES_NOT_EXIST; |
| 424 if (_isGenerated(source)) { | 428 if (_isGenerated(source)) { |
| 425 errorCode = CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED; | 429 errorCode = CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED; |
| 426 } | 430 } |
| 427 _getErrorReporter(file) | 431 _getErrorReporter(file) |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 @override | 567 @override |
| 564 String setContents(Source source, String contents) { | 568 String setContents(Source source, String contents) { |
| 565 throw new UnimplementedError(); | 569 throw new UnimplementedError(); |
| 566 } | 570 } |
| 567 | 571 |
| 568 FileState _getFileForSource(Source source) { | 572 FileState _getFileForSource(Source source) { |
| 569 String path = source.fullName; | 573 String path = source.fullName; |
| 570 return fsState.getFileForPath(path); | 574 return fsState.getFileForPath(path); |
| 571 } | 575 } |
| 572 } | 576 } |
| OLD | NEW |