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 library analyzer.src.task.dart; | 5 library analyzer.src.task.dart; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
(...skipping 2649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2660 @override | 2660 @override |
2661 void internalPerform() { | 2661 void internalPerform() { |
2662 // | 2662 // |
2663 // Prepare inputs. | 2663 // Prepare inputs. |
2664 // | 2664 // |
2665 // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping | 2665 // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping |
2666 // dependency to ensure that the variables that this variable references | 2666 // dependency to ensure that the variables that this variable references |
2667 // have types inferred before inferring the type of this variable. | 2667 // have types inferred before inferring the type of this variable. |
2668 // | 2668 // |
2669 VariableElementImpl variable = target; | 2669 VariableElementImpl variable = target; |
| 2670 |
2670 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | 2671 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
2671 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); | 2672 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); |
2672 RecordingErrorListener errorListener = new RecordingErrorListener(); | 2673 RecordingErrorListener errorListener = new RecordingErrorListener(); |
2673 if (dependencyCycle == null) { | 2674 VariableDeclaration declaration = getDeclaration(unit); |
2674 // | 2675 // |
2675 // Re-resolve the variable's initializer so that the inferred types of oth
er | 2676 // Re-resolve the variable's initializer so that the inferred types of other |
2676 // variables will be propagated. | 2677 // variables will be propagated. |
2677 // | 2678 // |
2678 NodeLocator locator = new NodeLocator(variable.nameOffset); | 2679 Expression initializer = declaration.initializer; |
2679 AstNode node = locator.searchWithin(unit); | 2680 ResolutionEraser.erase(initializer, eraseDeclarations: false); |
2680 VariableDeclaration declaration = node | 2681 ResolutionContext resolutionContext = |
2681 .getAncestor((AstNode ancestor) => ancestor is VariableDeclaration); | 2682 ResolutionContextBuilder.contextFor(initializer, errorListener); |
2682 if (declaration == null || declaration.name != node) { | 2683 ResolverVisitor visitor = new ResolverVisitor( |
2683 throw new AnalysisException( | 2684 variable.library, variable.source, typeProvider, errorListener, |
2684 "NodeLocator failed to find a variable's declaration"); | 2685 nameScope: resolutionContext.scope); |
2685 } | 2686 if (resolutionContext.enclosingClassDeclaration != null) { |
2686 Expression initializer = declaration.initializer; | 2687 visitor.prepareToResolveMembersInClass( |
2687 ResolutionEraser.erase(initializer, eraseDeclarations: false); | 2688 resolutionContext.enclosingClassDeclaration); |
2688 ResolutionContext resolutionContext = | 2689 } |
2689 ResolutionContextBuilder.contextFor(initializer, errorListener); | 2690 visitor.initForIncrementalResolution(); |
2690 ResolverVisitor visitor = new ResolverVisitor( | 2691 initializer.accept(visitor); |
2691 variable.library, variable.source, typeProvider, errorListener, | 2692 |
2692 nameScope: resolutionContext.scope); | 2693 // If we're not in a dependency cycle, and we have no type annotation, |
2693 if (resolutionContext.enclosingClassDeclaration != null) { | 2694 // do inference. |
2694 visitor.prepareToResolveMembersInClass( | 2695 if (dependencyCycle == null && variable.hasImplicitType) { |
2695 resolutionContext.enclosingClassDeclaration); | |
2696 } | |
2697 visitor.initForIncrementalResolution(); | |
2698 initializer.accept(visitor); | |
2699 // | 2696 // |
2700 // Record the type of the variable. | 2697 // Record the type of the variable. |
2701 // | 2698 // |
2702 DartType newType = initializer.staticType; | 2699 DartType newType = initializer.staticType; |
2703 if (newType == null || newType.isBottom) { | 2700 if (newType == null || newType.isBottom) { |
2704 newType = typeProvider.dynamicType; | 2701 newType = typeProvider.dynamicType; |
2705 } | 2702 } |
2706 variable.type = newType; | 2703 variable.type = newType; |
2707 (variable.initializer as ExecutableElementImpl).returnType = newType; | 2704 (variable.initializer as ExecutableElementImpl).returnType = newType; |
2708 if (variable is PropertyInducingElementImpl) { | 2705 if (variable is PropertyInducingElementImpl) { |
(...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4102 | 4099 |
4103 @override | 4100 @override |
4104 bool moveNext() { | 4101 bool moveNext() { |
4105 if (_newSources.isEmpty) { | 4102 if (_newSources.isEmpty) { |
4106 return false; | 4103 return false; |
4107 } | 4104 } |
4108 currentTarget = _newSources.removeLast(); | 4105 currentTarget = _newSources.removeLast(); |
4109 return true; | 4106 return true; |
4110 } | 4107 } |
4111 } | 4108 } |
OLD | NEW |