OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.generated.resolver; | 5 library analyzer.src.generated.resolver; |
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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 // This was determined to not be a good hint, see: dartbug.com/16029 | 199 // This was determined to not be a good hint, see: dartbug.com/16029 |
200 //checkForOverridingPrivateMember(node); | 200 //checkForOverridingPrivateMember(node); |
201 _checkForMissingReturn(node.returnType, node.body); | 201 _checkForMissingReturn(node.returnType, node.body); |
202 _checkForUnnecessaryNoSuchMethod(node); | 202 _checkForUnnecessaryNoSuchMethod(node); |
203 return super.visitMethodDeclaration(node); | 203 return super.visitMethodDeclaration(node); |
204 } | 204 } |
205 | 205 |
206 @override | 206 @override |
207 Object visitMethodInvocation(MethodInvocation node) { | 207 Object visitMethodInvocation(MethodInvocation node) { |
208 _checkForCanBeNullAfterNullAware(node.realTarget, node.operator); | 208 _checkForCanBeNullAfterNullAware(node.realTarget, node.operator); |
209 _checkForInvalidProtectedMethodCalls(node); | |
209 return super.visitMethodInvocation(node); | 210 return super.visitMethodInvocation(node); |
210 } | 211 } |
211 | 212 |
212 @override | 213 @override |
213 Object visitPostfixExpression(PostfixExpression node) { | 214 Object visitPostfixExpression(PostfixExpression node) { |
214 _checkForDeprecatedMemberUse(node.bestElement, node); | 215 _checkForDeprecatedMemberUse(node.bestElement, node); |
215 return super.visitPostfixExpression(node); | 216 return super.visitPostfixExpression(node); |
216 } | 217 } |
217 | 218 |
218 @override | 219 @override |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 if (!_typeSystem.isAssignableTo(bestRightType, leftType)) { | 602 if (!_typeSystem.isAssignableTo(bestRightType, leftType)) { |
602 _errorReporter.reportTypeErrorForNode( | 603 _errorReporter.reportTypeErrorForNode( |
603 HintCode.INVALID_ASSIGNMENT, rhs, [bestRightType, leftType]); | 604 HintCode.INVALID_ASSIGNMENT, rhs, [bestRightType, leftType]); |
604 return true; | 605 return true; |
605 } | 606 } |
606 } | 607 } |
607 return false; | 608 return false; |
608 } | 609 } |
609 | 610 |
610 /** | 611 /** |
612 * Produces a hint if the given invocation is of a protected method outside | |
613 * a subclass instance method. | |
614 */ | |
615 void _checkForInvalidProtectedMethodCalls(MethodInvocation node) { | |
616 Element element = node.methodName.staticElement; | |
Brian Wilkerson
2016/02/23 17:45:56
Given that this is a hint, I suspect that we want
pquitslund
2016/02/23 22:59:07
Done.
| |
617 if (element == null || !element.isProtected) { | |
618 return; | |
619 } | |
620 | |
621 ClassElement definingClass = element.enclosingElement; | |
622 | |
623 MethodDeclaration decl = | |
624 node.getAncestor((AstNode node) => node is MethodDeclaration); | |
625 if (decl == null) { | |
626 _errorReporter.reportErrorForNode( | |
627 HintCode.INVALID_USE_OF_PROTECTED_MEMBER, | |
628 node, | |
629 [node.methodName.toString(), definingClass.name]); | |
630 return; | |
631 } | |
632 | |
633 ClassElement invokingClass = decl.element?.enclosingElement; | |
634 if (invokingClass != null && | |
635 !invokingClass.type.isSubtypeOf(definingClass.type)) { | |
Brian Wilkerson
2016/02/23 17:45:56
The comment for the annotation says "extend or mix
pquitslund
2016/02/23 22:59:07
Fixed.
| |
636 _errorReporter.reportErrorForNode( | |
637 HintCode.INVALID_USE_OF_PROTECTED_MEMBER, | |
638 node, | |
639 [node.methodName.toString(), definingClass.name]); | |
640 } | |
641 } | |
642 | |
643 /** | |
611 * Check that the imported library does not define a loadLibrary function. The import has already | 644 * Check that the imported library does not define a loadLibrary function. The import has already |
612 * been determined to be deferred when this is called. | 645 * been determined to be deferred when this is called. |
613 * | 646 * |
614 * @param node the import directive to evaluate | 647 * @param node the import directive to evaluate |
615 * @param importElement the [ImportElement] retrieved from the node | 648 * @param importElement the [ImportElement] retrieved from the node |
616 * @return `true` if and only if an error code is generated on the passed node | 649 * @return `true` if and only if an error code is generated on the passed node |
617 * See [CompileTimeErrorCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION]. | 650 * See [CompileTimeErrorCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION]. |
618 */ | 651 */ |
619 bool _checkForLoadLibraryFunction( | 652 bool _checkForLoadLibraryFunction( |
620 ImportDirective node, ImportElement importElement) { | 653 ImportDirective node, ImportElement importElement) { |
(...skipping 7759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8380 safelyVisit(node.target); | 8413 safelyVisit(node.target); |
8381 safelyVisit(node.typeArguments); | 8414 safelyVisit(node.typeArguments); |
8382 node.accept(elementResolver); | 8415 node.accept(elementResolver); |
8383 _inferFunctionExpressionsParametersTypes(node.argumentList); | 8416 _inferFunctionExpressionsParametersTypes(node.argumentList); |
8384 _inferArgumentTypesFromContext(node); | 8417 _inferArgumentTypesFromContext(node); |
8385 safelyVisit(node.argumentList); | 8418 safelyVisit(node.argumentList); |
8386 node.accept(typeAnalyzer); | 8419 node.accept(typeAnalyzer); |
8387 return null; | 8420 return null; |
8388 } | 8421 } |
8389 | 8422 |
8390 void _inferArgumentTypesFromContext(InvocationExpression node) { | |
8391 DartType contextType = node.staticInvokeType; | |
8392 if (contextType is FunctionType) { | |
8393 DartType originalType = node.function.staticType; | |
8394 DartType returnContextType = InferenceContext.getType(node); | |
8395 TypeSystem ts = typeSystem; | |
8396 if (returnContextType != null && | |
8397 node.typeArguments == null && | |
8398 originalType is FunctionType && | |
8399 originalType.typeFormals.isNotEmpty && | |
8400 ts is StrongTypeSystemImpl) { | |
8401 | |
8402 contextType = ts.inferGenericFunctionCall(typeProvider, originalType, | |
8403 DartType.EMPTY_LIST, DartType.EMPTY_LIST, returnContextType); | |
8404 } | |
8405 | |
8406 InferenceContext.setType(node.argumentList, contextType); | |
8407 } | |
8408 } | |
8409 | |
8410 @override | 8423 @override |
8411 Object visitNamedExpression(NamedExpression node) { | 8424 Object visitNamedExpression(NamedExpression node) { |
8412 InferenceContext.setType(node.expression, InferenceContext.getType(node)); | 8425 InferenceContext.setType(node.expression, InferenceContext.getType(node)); |
8413 return super.visitNamedExpression(node); | 8426 return super.visitNamedExpression(node); |
8414 } | 8427 } |
8415 | 8428 |
8416 @override | 8429 @override |
8417 Object visitNode(AstNode node) { | 8430 Object visitNode(AstNode node) { |
8418 node.visitChildren(this); | 8431 node.visitChildren(this); |
8419 node.accept(elementResolver); | 8432 node.accept(elementResolver); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8727 List<ParameterElement> onDataParameters = onDataType.parameters; | 8740 List<ParameterElement> onDataParameters = onDataType.parameters; |
8728 if (onDataParameters == null || onDataParameters.isEmpty) { | 8741 if (onDataParameters == null || onDataParameters.isEmpty) { |
8729 return null; | 8742 return null; |
8730 } | 8743 } |
8731 return onDataParameters[0].type; | 8744 return onDataParameters[0].type; |
8732 } | 8745 } |
8733 } | 8746 } |
8734 return null; | 8747 return null; |
8735 } | 8748 } |
8736 | 8749 |
8750 void _inferArgumentTypesFromContext(InvocationExpression node) { | |
8751 DartType contextType = node.staticInvokeType; | |
8752 if (contextType is FunctionType) { | |
8753 DartType originalType = node.function.staticType; | |
8754 DartType returnContextType = InferenceContext.getType(node); | |
8755 TypeSystem ts = typeSystem; | |
8756 if (returnContextType != null && | |
8757 node.typeArguments == null && | |
8758 originalType is FunctionType && | |
8759 originalType.typeFormals.isNotEmpty && | |
8760 ts is StrongTypeSystemImpl) { | |
8761 contextType = ts.inferGenericFunctionCall(typeProvider, originalType, | |
8762 DartType.EMPTY_LIST, DartType.EMPTY_LIST, returnContextType); | |
8763 } | |
8764 | |
8765 InferenceContext.setType(node.argumentList, contextType); | |
8766 } | |
8767 } | |
8768 | |
8737 void _inferFormalParameterList(FormalParameterList node, DartType type) { | 8769 void _inferFormalParameterList(FormalParameterList node, DartType type) { |
8738 if (typeAnalyzer.inferFormalParameterList(node, type)) { | 8770 if (typeAnalyzer.inferFormalParameterList(node, type)) { |
8739 // TODO(leafp): This gets dropped on the floor if we're in the field | 8771 // TODO(leafp): This gets dropped on the floor if we're in the field |
8740 // inference task. We should probably keep these infos. | 8772 // inference task. We should probably keep these infos. |
8741 inferenceContext.recordInference(node.parent, type); | 8773 inferenceContext.recordInference(node.parent, type); |
8742 } | 8774 } |
8743 } | 8775 } |
8744 | 8776 |
8745 /** | 8777 /** |
8746 * If given "mayBeClosure" is [FunctionExpression] without explicit parameters types and its | 8778 * If given "mayBeClosure" is [FunctionExpression] without explicit parameters types and its |
(...skipping 4053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12800 nonFields.add(node); | 12832 nonFields.add(node); |
12801 return null; | 12833 return null; |
12802 } | 12834 } |
12803 | 12835 |
12804 @override | 12836 @override |
12805 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 12837 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
12806 | 12838 |
12807 @override | 12839 @override |
12808 Object visitWithClause(WithClause node) => null; | 12840 Object visitWithClause(WithClause node) => null; |
12809 } | 12841 } |
OLD | NEW |