| 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.error_verifier; | 5 library analyzer.src.generated.error_verifier; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import "dart:math" as math; | 8 import "dart:math" as math; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 if (fieldElement.isConst) { | 1652 if (fieldElement.isConst) { |
| 1653 _errorReporter.reportErrorForNode( | 1653 _errorReporter.reportErrorForNode( |
| 1654 CompileTimeErrorCode.CONST_NOT_INITIALIZED, | 1654 CompileTimeErrorCode.CONST_NOT_INITIALIZED, |
| 1655 constructor.returnType, | 1655 constructor.returnType, |
| 1656 [fieldElement.name]); | 1656 [fieldElement.name]); |
| 1657 } | 1657 } |
| 1658 } | 1658 } |
| 1659 }); | 1659 }); |
| 1660 | 1660 |
| 1661 if (notInitFinalFields.isNotEmpty) { | 1661 if (notInitFinalFields.isNotEmpty) { |
| 1662 AnalysisErrorWithProperties analysisError; | |
| 1663 List<String> names = notInitFinalFields.map((item) => item.name).toList(); | 1662 List<String> names = notInitFinalFields.map((item) => item.name).toList(); |
| 1664 names.sort(); | 1663 names.sort(); |
| 1665 if (names.length == 1) { | 1664 if (names.length == 1) { |
| 1666 analysisError = _errorReporter.newErrorWithProperties( | 1665 _errorReporter.reportErrorForNode( |
| 1667 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1, | 1666 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1, |
| 1668 constructor.returnType, | 1667 constructor.returnType, |
| 1669 names); | 1668 names); |
| 1670 } else if (names.length == 2) { | 1669 } else if (names.length == 2) { |
| 1671 analysisError = _errorReporter.newErrorWithProperties( | 1670 _errorReporter.reportErrorForNode( |
| 1672 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2, | 1671 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2, |
| 1673 constructor.returnType, | 1672 constructor.returnType, |
| 1674 names); | 1673 names); |
| 1675 } else { | 1674 } else { |
| 1676 analysisError = _errorReporter.newErrorWithProperties( | 1675 _errorReporter.reportErrorForNode( |
| 1677 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS, | 1676 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS, |
| 1678 constructor.returnType, | 1677 constructor.returnType, |
| 1679 [names[0], names[1], names.length - 2]); | 1678 [names[0], names[1], names.length - 2]); |
| 1680 } | 1679 } |
| 1681 analysisError.setProperty( | |
| 1682 ErrorProperty.NOT_INITIALIZED_FIELDS, notInitFinalFields); | |
| 1683 _errorReporter.reportError(analysisError); | |
| 1684 } | 1680 } |
| 1685 } | 1681 } |
| 1686 | 1682 |
| 1687 /** | 1683 /** |
| 1688 * Check the given [derivedElement] against override-error codes. The | 1684 * Check the given [derivedElement] against override-error codes. The |
| 1689 * [baseElement] is the element that the executable element is | 1685 * [baseElement] is the element that the executable element is |
| 1690 * overriding. The [parameters] is the parameters of the executable element. | 1686 * overriding. The [parameters] is the parameters of the executable element. |
| 1691 * The [errorNameTarget] is the node to report problems on. | 1687 * The [errorNameTarget] is the node to report problems on. |
| 1692 * | 1688 * |
| 1693 * See [StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
], | 1689 * See [StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
], |
| (...skipping 4954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6648 } | 6644 } |
| 6649 } | 6645 } |
| 6650 // The not qualifying concrete executable element was found, add it to the | 6646 // The not qualifying concrete executable element was found, add it to the |
| 6651 // list. | 6647 // list. |
| 6652 missingOverrides.add(executableElt); | 6648 missingOverrides.add(executableElt); |
| 6653 } | 6649 } |
| 6654 return missingOverrides; | 6650 return missingOverrides; |
| 6655 } | 6651 } |
| 6656 | 6652 |
| 6657 /** | 6653 /** |
| 6654 * Return [FieldElement]s that are declared in the [ClassDeclaration] with |
| 6655 * the given [constructor], but are not initialized. |
| 6656 */ |
| 6657 static List<FieldElement> computeNotInitializedFields( |
| 6658 ConstructorDeclaration constructor) { |
| 6659 Set<FieldElement> fields = new Set<FieldElement>(); |
| 6660 var classDeclaration = constructor.parent as ClassDeclaration; |
| 6661 for (ClassMember fieldDeclaration in classDeclaration.members) { |
| 6662 if (fieldDeclaration is FieldDeclaration) { |
| 6663 for (VariableDeclaration field in fieldDeclaration.fields.variables) { |
| 6664 if (field.initializer == null) { |
| 6665 fields.add(field.element); |
| 6666 } |
| 6667 } |
| 6668 } |
| 6669 } |
| 6670 |
| 6671 List<FormalParameter> parameters = constructor.parameters?.parameters ?? []; |
| 6672 for (FormalParameter parameter in parameters) { |
| 6673 if (parameter is DefaultFormalParameter) { |
| 6674 parameter = (parameter as DefaultFormalParameter).parameter; |
| 6675 } |
| 6676 if (parameter is FieldFormalParameter) { |
| 6677 FieldFormalParameterElement element = |
| 6678 parameter.identifier.staticElement as FieldFormalParameterElement; |
| 6679 fields.remove(element.field); |
| 6680 } |
| 6681 } |
| 6682 |
| 6683 for (ConstructorInitializer initializer in constructor.initializers) { |
| 6684 if (initializer is ConstructorFieldInitializer) { |
| 6685 fields.remove(initializer.fieldName.staticElement); |
| 6686 } |
| 6687 } |
| 6688 |
| 6689 return fields.toList(); |
| 6690 } |
| 6691 |
| 6692 /** |
| 6658 * Return the static type of the given [expression] that is to be used for | 6693 * Return the static type of the given [expression] that is to be used for |
| 6659 * type analysis. | 6694 * type analysis. |
| 6660 */ | 6695 */ |
| 6661 static DartType getStaticType(Expression expression) { | 6696 static DartType getStaticType(Expression expression) { |
| 6662 DartType type = expression.staticType; | 6697 DartType type = expression.staticType; |
| 6663 if (type == null) { | 6698 if (type == null) { |
| 6664 // TODO(brianwilkerson) This should never happen. | 6699 // TODO(brianwilkerson) This should never happen. |
| 6665 return DynamicTypeImpl.instance; | 6700 return DynamicTypeImpl.instance; |
| 6666 } | 6701 } |
| 6667 return type; | 6702 return type; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6958 class _InvocationCollector extends RecursiveAstVisitor { | 6993 class _InvocationCollector extends RecursiveAstVisitor { |
| 6959 final List<String> superCalls = <String>[]; | 6994 final List<String> superCalls = <String>[]; |
| 6960 | 6995 |
| 6961 @override | 6996 @override |
| 6962 visitMethodInvocation(MethodInvocation node) { | 6997 visitMethodInvocation(MethodInvocation node) { |
| 6963 if (node.target is SuperExpression) { | 6998 if (node.target is SuperExpression) { |
| 6964 superCalls.add(node.methodName.name); | 6999 superCalls.add(node.methodName.name); |
| 6965 } | 7000 } |
| 6966 } | 7001 } |
| 6967 } | 7002 } |
| OLD | NEW |