| 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 engine.resolver.error_verifier; | 5 library engine.resolver.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/src/generated/static_type_analyzer.dart'; | 10 import 'package:analyzer/src/generated/static_type_analyzer.dart'; |
| (...skipping 2235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2246 for (MethodElement method in _enclosingClass.methods) { | 2246 for (MethodElement method in _enclosingClass.methods) { |
| 2247 String name = method.name; | 2247 String name = method.name; |
| 2248 // find inherited property accessor (and can be only getter) | 2248 // find inherited property accessor (and can be only getter) |
| 2249 ExecutableElement inherited = | 2249 ExecutableElement inherited = |
| 2250 _inheritanceManager.lookupInheritance(_enclosingClass, name); | 2250 _inheritanceManager.lookupInheritance(_enclosingClass, name); |
| 2251 if (inherited is! PropertyAccessorElement) { | 2251 if (inherited is! PropertyAccessorElement) { |
| 2252 continue; | 2252 continue; |
| 2253 } | 2253 } |
| 2254 // report problem | 2254 // report problem |
| 2255 hasProblem = true; | 2255 hasProblem = true; |
| 2256 _errorReporter.reportErrorForOffset( | 2256 _errorReporter.reportErrorForElement( |
| 2257 CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD, | 2257 CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD, method, [ |
| 2258 method.nameOffset, | |
| 2259 name.length, [ | |
| 2260 _enclosingClass.displayName, | 2258 _enclosingClass.displayName, |
| 2261 inherited.enclosingElement.displayName, | 2259 inherited.enclosingElement.displayName, |
| 2262 name | 2260 name |
| 2263 ]); | 2261 ]); |
| 2264 } | 2262 } |
| 2265 // getter declared in the enclosing class vs. inherited method | 2263 // getter declared in the enclosing class vs. inherited method |
| 2266 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { | 2264 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
| 2267 if (!accessor.isGetter) { | 2265 if (!accessor.isGetter) { |
| 2268 continue; | 2266 continue; |
| 2269 } | 2267 } |
| 2270 String name = accessor.name; | 2268 String name = accessor.name; |
| 2271 // find inherited method | 2269 // find inherited method |
| 2272 ExecutableElement inherited = | 2270 ExecutableElement inherited = |
| 2273 _inheritanceManager.lookupInheritance(_enclosingClass, name); | 2271 _inheritanceManager.lookupInheritance(_enclosingClass, name); |
| 2274 if (inherited is! MethodElement) { | 2272 if (inherited is! MethodElement) { |
| 2275 continue; | 2273 continue; |
| 2276 } | 2274 } |
| 2277 // report problem | 2275 // report problem |
| 2278 hasProblem = true; | 2276 hasProblem = true; |
| 2279 _errorReporter.reportErrorForOffset( | 2277 _errorReporter.reportErrorForElement( |
| 2280 CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER, | 2278 CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER, accessor, [ |
| 2281 accessor.nameOffset, | |
| 2282 name.length, [ | |
| 2283 _enclosingClass.displayName, | 2279 _enclosingClass.displayName, |
| 2284 inherited.enclosingElement.displayName, | 2280 inherited.enclosingElement.displayName, |
| 2285 name | 2281 name |
| 2286 ]); | 2282 ]); |
| 2287 } | 2283 } |
| 2288 // done | 2284 // done |
| 2289 return hasProblem; | 2285 return hasProblem; |
| 2290 } | 2286 } |
| 2291 | 2287 |
| 2292 /** | 2288 /** |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2552 * See [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS], and | 2548 * See [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS], and |
| 2553 * [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]. | 2549 * [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]. |
| 2554 */ | 2550 */ |
| 2555 bool _checkForConflictingTypeVariableErrorCodes( | 2551 bool _checkForConflictingTypeVariableErrorCodes( |
| 2556 ClassDeclaration declaration) { | 2552 ClassDeclaration declaration) { |
| 2557 bool problemReported = false; | 2553 bool problemReported = false; |
| 2558 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) { | 2554 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) { |
| 2559 String name = typeParameter.name; | 2555 String name = typeParameter.name; |
| 2560 // name is same as the name of the enclosing class | 2556 // name is same as the name of the enclosing class |
| 2561 if (_enclosingClass.name == name) { | 2557 if (_enclosingClass.name == name) { |
| 2562 _errorReporter.reportErrorForOffset( | 2558 _errorReporter.reportErrorForElement( |
| 2563 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS, | 2559 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS, |
| 2564 typeParameter.nameOffset, | 2560 typeParameter, |
| 2565 name.length, | |
| 2566 [name]); | 2561 [name]); |
| 2567 problemReported = true; | 2562 problemReported = true; |
| 2568 } | 2563 } |
| 2569 // check members | 2564 // check members |
| 2570 if (_enclosingClass.getMethod(name) != null || | 2565 if (_enclosingClass.getMethod(name) != null || |
| 2571 _enclosingClass.getGetter(name) != null || | 2566 _enclosingClass.getGetter(name) != null || |
| 2572 _enclosingClass.getSetter(name) != null) { | 2567 _enclosingClass.getSetter(name) != null) { |
| 2573 _errorReporter.reportErrorForOffset( | 2568 _errorReporter.reportErrorForElement( |
| 2574 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER, | 2569 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER, |
| 2575 typeParameter.nameOffset, | 2570 typeParameter, |
| 2576 name.length, | |
| 2577 [name]); | 2571 [name]); |
| 2578 problemReported = true; | 2572 problemReported = true; |
| 2579 } | 2573 } |
| 2580 } | 2574 } |
| 2581 return problemReported; | 2575 return problemReported; |
| 2582 } | 2576 } |
| 2583 | 2577 |
| 2584 /** | 2578 /** |
| 2585 * Verify that if the given [constructor] declaration is 'const' then there | 2579 * Verify that if the given [constructor] declaration is 'const' then there |
| 2586 * are no invocations of non-'const' super constructors. | 2580 * are no invocations of non-'const' super constructors. |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3001 // determine the display name, use the extended display name if the | 2995 // determine the display name, use the extended display name if the |
| 3002 // enclosing class of the inherited member is in a different source | 2996 // enclosing class of the inherited member is in a different source |
| 3003 String displayName; | 2997 String displayName; |
| 3004 Element enclosingElement = inheritedMember.enclosingElement; | 2998 Element enclosingElement = inheritedMember.enclosingElement; |
| 3005 if (enclosingElement.source == _enclosingClass.source) { | 2999 if (enclosingElement.source == _enclosingClass.source) { |
| 3006 displayName = enclosingElement.displayName; | 3000 displayName = enclosingElement.displayName; |
| 3007 } else { | 3001 } else { |
| 3008 displayName = enclosingElement.getExtendedDisplayName(null); | 3002 displayName = enclosingElement.getExtendedDisplayName(null); |
| 3009 } | 3003 } |
| 3010 // report problem | 3004 // report problem |
| 3011 _errorReporter.reportErrorForOffset( | 3005 _errorReporter.reportErrorForElement( |
| 3012 CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE, | 3006 CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE, |
| 3013 staticMember.nameOffset, | 3007 staticMember, |
| 3014 name.length, | |
| 3015 [name, displayName]); | 3008 [name, displayName]); |
| 3016 return true; | 3009 return true; |
| 3017 } | 3010 } |
| 3018 | 3011 |
| 3019 /** | 3012 /** |
| 3020 * Verify that if the given list [literal] has type arguments then there is | 3013 * Verify that if the given list [literal] has type arguments then there is |
| 3021 * exactly one. The [typeArguments] are the type arguments. | 3014 * exactly one. The [typeArguments] are the type arguments. |
| 3022 * | 3015 * |
| 3023 * See [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]. | 3016 * See [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]. |
| 3024 */ | 3017 */ |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4019 return false; | 4012 return false; |
| 4020 } | 4013 } |
| 4021 String className = _enclosingClass.name; | 4014 String className = _enclosingClass.name; |
| 4022 if (className == null) { | 4015 if (className == null) { |
| 4023 return false; | 4016 return false; |
| 4024 } | 4017 } |
| 4025 bool problemReported = false; | 4018 bool problemReported = false; |
| 4026 // check accessors | 4019 // check accessors |
| 4027 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { | 4020 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
| 4028 if (className == accessor.name) { | 4021 if (className == accessor.name) { |
| 4029 _errorReporter.reportErrorForOffset( | 4022 _errorReporter.reportErrorForElement( |
| 4030 CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, | 4023 CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, accessor); |
| 4031 accessor.nameOffset, | |
| 4032 className.length); | |
| 4033 problemReported = true; | 4024 problemReported = true; |
| 4034 } | 4025 } |
| 4035 } | 4026 } |
| 4036 // don't check methods, they would be constructors | 4027 // don't check methods, they would be constructors |
| 4037 // done | 4028 // done |
| 4038 return problemReported; | 4029 return problemReported; |
| 4039 } | 4030 } |
| 4040 | 4031 |
| 4041 /** | 4032 /** |
| 4042 * Check to make sure that all similarly typed accessors are of the same type | 4033 * Check to make sure that all similarly typed accessors are of the same type |
| (...skipping 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5958 if (size > 1) { | 5949 if (size > 1) { |
| 5959 // Construct a string showing the cyclic implements path: | 5950 // Construct a string showing the cyclic implements path: |
| 5960 // "A, B, C, D, A" | 5951 // "A, B, C, D, A" |
| 5961 String separator = ", "; | 5952 String separator = ", "; |
| 5962 StringBuffer buffer = new StringBuffer(); | 5953 StringBuffer buffer = new StringBuffer(); |
| 5963 for (int i = 0; i < size; i++) { | 5954 for (int i = 0; i < size; i++) { |
| 5964 buffer.write(path[i].displayName); | 5955 buffer.write(path[i].displayName); |
| 5965 buffer.write(separator); | 5956 buffer.write(separator); |
| 5966 } | 5957 } |
| 5967 buffer.write(element.displayName); | 5958 buffer.write(element.displayName); |
| 5968 _errorReporter.reportErrorForOffset( | 5959 _errorReporter.reportErrorForElement( |
| 5969 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 5960 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 5970 _enclosingClass.nameOffset, | 5961 _enclosingClass, |
| 5971 enclosingClassName.length, | |
| 5972 [enclosingClassName, buffer.toString()]); | 5962 [enclosingClassName, buffer.toString()]); |
| 5973 return true; | 5963 return true; |
| 5974 } else { | 5964 } else { |
| 5975 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS or | 5965 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS or |
| 5976 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or | 5966 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or |
| 5977 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH | 5967 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH |
| 5978 _errorReporter.reportErrorForOffset( | 5968 _errorReporter.reportErrorForElement(_getBaseCaseErrorCode(element), |
| 5979 _getBaseCaseErrorCode(element), | 5969 _enclosingClass, [enclosingClassName]); |
| 5980 _enclosingClass.nameOffset, | |
| 5981 enclosingClassName.length, | |
| 5982 [enclosingClassName]); | |
| 5983 return true; | 5970 return true; |
| 5984 } | 5971 } |
| 5985 } | 5972 } |
| 5986 if (path.indexOf(element) > 0) { | 5973 if (path.indexOf(element) > 0) { |
| 5987 return false; | 5974 return false; |
| 5988 } | 5975 } |
| 5989 path.add(element); | 5976 path.add(element); |
| 5990 // n-case | 5977 // n-case |
| 5991 InterfaceType supertype = element.supertype; | 5978 InterfaceType supertype = element.supertype; |
| 5992 if (supertype != null && | 5979 if (supertype != null && |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6077 toCheck.add(type.element); | 6064 toCheck.add(type.element); |
| 6078 // type arguments | 6065 // type arguments |
| 6079 if (type is InterfaceType) { | 6066 if (type is InterfaceType) { |
| 6080 InterfaceType interfaceType = type; | 6067 InterfaceType interfaceType = type; |
| 6081 for (DartType typeArgument in interfaceType.typeArguments) { | 6068 for (DartType typeArgument in interfaceType.typeArguments) { |
| 6082 _addTypeToCheck(typeArgument); | 6069 _addTypeToCheck(typeArgument); |
| 6083 } | 6070 } |
| 6084 } | 6071 } |
| 6085 } | 6072 } |
| 6086 } | 6073 } |
| OLD | NEW |