| 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/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 4646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4657 } finally { | 4657 } finally { |
| 4658 dependsOn = null; | 4658 dependsOn = null; |
| 4659 scope = outerScope; | 4659 scope = outerScope; |
| 4660 } | 4660 } |
| 4661 } else { | 4661 } else { |
| 4662 super.visitFunctionTypeAlias(node); | 4662 super.visitFunctionTypeAlias(node); |
| 4663 } | 4663 } |
| 4664 } | 4664 } |
| 4665 | 4665 |
| 4666 @override | 4666 @override |
| 4667 visitMethodDeclaration(MethodDeclaration node) { |
| 4668 ReferencedNamesScope outerScope = scope; |
| 4669 try { |
| 4670 scope = new ReferencedNamesScope.forMethod(scope, node); |
| 4671 super.visitMethodDeclaration(node); |
| 4672 } finally { |
| 4673 scope = outerScope; |
| 4674 } |
| 4675 } |
| 4676 |
| 4677 @override |
| 4667 visitSimpleIdentifier(SimpleIdentifier node) { | 4678 visitSimpleIdentifier(SimpleIdentifier node) { |
| 4668 // Ignore all declarations. | 4679 // Ignore all declarations. |
| 4669 if (node.inDeclarationContext()) { | 4680 if (node.inDeclarationContext()) { |
| 4670 return; | 4681 return; |
| 4671 } | 4682 } |
| 4672 // Ignore class names references from constructors. | 4683 // Ignore class names references from constructors. |
| 4673 AstNode parent = node.parent; | 4684 AstNode parent = node.parent; |
| 4674 if (parent is ConstructorDeclaration && parent.returnType == node) { | 4685 if (parent is ConstructorDeclaration && parent.returnType == node) { |
| 4675 return; | 4686 return; |
| 4676 } | 4687 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 4707 } | 4718 } |
| 4708 } | 4719 } |
| 4709 return scope; | 4720 return scope; |
| 4710 } | 4721 } |
| 4711 | 4722 |
| 4712 factory ReferencedNamesScope.forClass( | 4723 factory ReferencedNamesScope.forClass( |
| 4713 ReferencedNamesScope enclosing, ClassDeclaration node) { | 4724 ReferencedNamesScope enclosing, ClassDeclaration node) { |
| 4714 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); | 4725 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); |
| 4715 scope._addTypeParameters(node.typeParameters); | 4726 scope._addTypeParameters(node.typeParameters); |
| 4716 for (ClassMember member in node.members) { | 4727 for (ClassMember member in node.members) { |
| 4717 if (member is MethodDeclaration) { | 4728 if (member is FieldDeclaration) { |
| 4729 for (VariableDeclaration variable in member.fields.variables) { |
| 4730 scope.add(variable.name.name); |
| 4731 } |
| 4732 } else if (member is MethodDeclaration) { |
| 4718 scope.add(member.name.name); | 4733 scope.add(member.name.name); |
| 4719 } | 4734 } |
| 4720 } | 4735 } |
| 4721 return scope; | 4736 return scope; |
| 4722 } | 4737 } |
| 4723 | 4738 |
| 4724 factory ReferencedNamesScope.forFunction( | 4739 factory ReferencedNamesScope.forFunction( |
| 4725 ReferencedNamesScope enclosing, FunctionDeclaration node) { | 4740 ReferencedNamesScope enclosing, FunctionDeclaration node) { |
| 4726 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); | 4741 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); |
| 4727 scope._addTypeParameters(node.functionExpression.typeParameters); | 4742 scope._addTypeParameters(node.functionExpression.typeParameters); |
| 4728 node.functionExpression.parameters?.parameters | 4743 scope._addFormalParameters(node.functionExpression.parameters); |
| 4729 ?.map((p) => p is NormalFormalParameter ? p.identifier.name : '') | |
| 4730 ?.forEach(scope.add); | |
| 4731 return scope; | 4744 return scope; |
| 4732 } | 4745 } |
| 4733 | 4746 |
| 4734 factory ReferencedNamesScope.forFunctionTypeAlias( | 4747 factory ReferencedNamesScope.forFunctionTypeAlias( |
| 4735 ReferencedNamesScope enclosing, FunctionTypeAlias node) { | 4748 ReferencedNamesScope enclosing, FunctionTypeAlias node) { |
| 4736 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); | 4749 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); |
| 4737 scope._addTypeParameters(node.typeParameters); | 4750 scope._addTypeParameters(node.typeParameters); |
| 4738 return scope; | 4751 return scope; |
| 4739 } | 4752 } |
| 4740 | 4753 |
| 4754 factory ReferencedNamesScope.forMethod( |
| 4755 ReferencedNamesScope enclosing, MethodDeclaration node) { |
| 4756 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); |
| 4757 scope._addTypeParameters(node.typeParameters); |
| 4758 scope._addFormalParameters(node.parameters); |
| 4759 return scope; |
| 4760 } |
| 4761 |
| 4741 void add(String name) { | 4762 void add(String name) { |
| 4742 names ??= new Set<String>(); | 4763 names ??= new Set<String>(); |
| 4743 names.add(name); | 4764 names.add(name); |
| 4744 } | 4765 } |
| 4745 | 4766 |
| 4746 bool contains(String name) { | 4767 bool contains(String name) { |
| 4747 if (names != null && names.contains(name)) { | 4768 if (names != null && names.contains(name)) { |
| 4748 return true; | 4769 return true; |
| 4749 } | 4770 } |
| 4750 if (enclosing != null) { | 4771 if (enclosing != null) { |
| 4751 return enclosing.contains(name); | 4772 return enclosing.contains(name); |
| 4752 } | 4773 } |
| 4753 return false; | 4774 return false; |
| 4754 } | 4775 } |
| 4755 | 4776 |
| 4777 void _addFormalParameters(FormalParameterList parameterList) { |
| 4778 if (parameterList != null) { |
| 4779 parameterList.parameters |
| 4780 .map((p) => p is NormalFormalParameter ? p.identifier.name : '') |
| 4781 .forEach(add); |
| 4782 } |
| 4783 } |
| 4784 |
| 4756 void _addTypeParameters(TypeParameterList typeParameterList) { | 4785 void _addTypeParameters(TypeParameterList typeParameterList) { |
| 4757 typeParameterList?.typeParameters?.map((p) => p.name.name)?.forEach(add); | 4786 typeParameterList?.typeParameters?.map((p) => p.name.name)?.forEach(add); |
| 4758 } | 4787 } |
| 4759 } | 4788 } |
| 4760 | 4789 |
| 4761 /** | 4790 /** |
| 4762 * A task that ensures that the expression AST for a constant is resolved and | 4791 * A task that ensures that the expression AST for a constant is resolved and |
| 4763 * sets the [CONSTANT_EXPRESSION_RESOLVED] result. | 4792 * sets the [CONSTANT_EXPRESSION_RESOLVED] result. |
| 4764 */ | 4793 */ |
| 4765 class ResolveConstantExpressionTask extends ConstantEvaluationAnalysisTask { | 4794 class ResolveConstantExpressionTask extends ConstantEvaluationAnalysisTask { |
| (...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6156 | 6185 |
| 6157 @override | 6186 @override |
| 6158 bool moveNext() { | 6187 bool moveNext() { |
| 6159 if (_newSources.isEmpty) { | 6188 if (_newSources.isEmpty) { |
| 6160 return false; | 6189 return false; |
| 6161 } | 6190 } |
| 6162 currentTarget = _newSources.removeLast(); | 6191 currentTarget = _newSources.removeLast(); |
| 6163 return true; | 6192 return true; |
| 6164 } | 6193 } |
| 6165 } | 6194 } |
| OLD | NEW |