Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 2314963002: Remove the final error being generated in a scope (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 // - DefaultFormalParameter contains a simple one, so it gets here, 1120 // - DefaultFormalParameter contains a simple one, so it gets here,
1121 // - FieldFormalParameter error should be reported on the field, 1121 // - FieldFormalParameter error should be reported on the field,
1122 // - FunctionTypedFormalParameter is a function type, not dynamic. 1122 // - FunctionTypedFormalParameter is a function type, not dynamic.
1123 _checkForImplicitDynamicIdentifier(node, node.identifier); 1123 _checkForImplicitDynamicIdentifier(node, node.identifier);
1124 1124
1125 return super.visitSimpleFormalParameter(node); 1125 return super.visitSimpleFormalParameter(node);
1126 } 1126 }
1127 1127
1128 @override 1128 @override
1129 Object visitSimpleIdentifier(SimpleIdentifier node) { 1129 Object visitSimpleIdentifier(SimpleIdentifier node) {
1130 _checkForAmbiguousImport(node);
1130 _checkForReferenceBeforeDeclaration(node); 1131 _checkForReferenceBeforeDeclaration(node);
1131 _checkForImplicitThisReferenceInInitializer(node); 1132 _checkForImplicitThisReferenceInInitializer(node);
1132 if (!_isUnqualifiedReferenceToNonLocalStaticMemberAllowed(node)) { 1133 if (!_isUnqualifiedReferenceToNonLocalStaticMemberAllowed(node)) {
1133 _checkForUnqualifiedReferenceToNonLocalStaticMember(node); 1134 _checkForUnqualifiedReferenceToNonLocalStaticMember(node);
1134 } 1135 }
1135 return super.visitSimpleIdentifier(node); 1136 return super.visitSimpleIdentifier(node);
1136 } 1137 }
1137 1138
1138 @override 1139 @override
1139 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 1140 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after
2329 element.library.definingCompilationUnit.displayName 2330 element.library.definingCompilationUnit.displayName
2330 ]); 2331 ]);
2331 return; 2332 return;
2332 } else { 2333 } else {
2333 _exportedElements[name] = element; 2334 _exportedElements[name] = element;
2334 } 2335 }
2335 } 2336 }
2336 } 2337 }
2337 2338
2338 /** 2339 /**
2340 * Check the given node to see whether it was ambiguous because the name was
2341 * imported from two or more imports.
2342 */
2343 void _checkForAmbiguousImport(SimpleIdentifier node) {
2344 Element element = node.staticElement;
2345 if (element is MultiplyDefinedElementImpl) {
2346 String name = element.displayName;
2347 List<Element> conflictingMembers = element.conflictingElements;
2348 int count = conflictingMembers.length;
2349 List<String> libraryNames = new List<String>(count);
2350 for (int i = 0; i < count; i++) {
2351 libraryNames[i] = _getLibraryName(conflictingMembers[i]);
2352 }
2353 libraryNames.sort();
2354 _errorReporter.reportErrorForNode(StaticWarningCode.AMBIGUOUS_IMPORT,
2355 node, [name, StringUtilities.printListOfQuotedNames(libraryNames)]);
2356 } else {
2357 List<Element> sdkElements =
2358 node.getProperty(LibraryImportScope.conflictingSdkElements);
2359 if (sdkElements != null) {
2360 _errorReporter.reportErrorForNode(
2361 StaticWarningCode.CONFLICTING_DART_IMPORT, node, [
2362 element.displayName,
2363 _getLibraryName(sdkElements[0]),
2364 _getLibraryName(element)
2365 ]);
2366 }
2367 }
2368 }
2369
2370 /**
2339 * Verify that the given [expression] can be assigned to its corresponding 2371 * Verify that the given [expression] can be assigned to its corresponding
2340 * parameters. The [expectedStaticType] is the expected static type of the 2372 * parameters. The [expectedStaticType] is the expected static type of the
2341 * parameter. The [actualStaticType] is the actual static type of the 2373 * parameter. The [actualStaticType] is the actual static type of the
2342 * argument. 2374 * argument.
2343 * 2375 *
2344 * This method corresponds to 2376 * This method corresponds to
2345 * [BestPracticesVerifier.checkForArgumentTypeNotAssignable]. 2377 * [BestPracticesVerifier.checkForArgumentTypeNotAssignable].
2346 * 2378 *
2347 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], 2379 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE],
2348 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], 2380 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE],
(...skipping 3917 matching lines...) Expand 10 before | Expand all | Expand 10 after
6266 */ 6298 */
6267 DartType _getGetterType(PropertyAccessorElement getter) { 6299 DartType _getGetterType(PropertyAccessorElement getter) {
6268 FunctionType functionType = getter.type; 6300 FunctionType functionType = getter.type;
6269 if (functionType != null) { 6301 if (functionType != null) {
6270 return functionType.returnType; 6302 return functionType.returnType;
6271 } else { 6303 } else {
6272 return null; 6304 return null;
6273 } 6305 }
6274 } 6306 }
6275 6307
6308 /**
6309 * Return the name of the library that defines given [element].
6310 */
6311 String _getLibraryName(Element element) {
6312 if (element == null) {
6313 return StringUtilities.EMPTY;
6314 }
6315 LibraryElement library = element.library;
6316 if (library == null) {
6317 return StringUtilities.EMPTY;
6318 }
6319 List<ImportElement> imports = _currentLibrary.imports;
6320 int count = imports.length;
6321 for (int i = 0; i < count; i++) {
6322 if (identical(imports[i].importedLibrary, library)) {
6323 return library.definingCompilationUnit.displayName;
6324 }
6325 }
6326 List<String> indirectSources = new List<String>();
6327 for (int i = 0; i < count; i++) {
6328 LibraryElement importedLibrary = imports[i].importedLibrary;
6329 if (importedLibrary != null) {
6330 for (LibraryElement exportedLibrary
6331 in importedLibrary.exportedLibraries) {
6332 if (identical(exportedLibrary, library)) {
6333 indirectSources
6334 .add(importedLibrary.definingCompilationUnit.displayName);
6335 }
6336 }
6337 }
6338 }
6339 int indirectCount = indirectSources.length;
6340 StringBuffer buffer = new StringBuffer();
6341 buffer.write(library.definingCompilationUnit.displayName);
6342 if (indirectCount > 0) {
6343 buffer.write(" (via ");
6344 if (indirectCount > 1) {
6345 indirectSources.sort();
6346 buffer.write(StringUtilities.printListOfQuotedNames(indirectSources));
6347 } else {
6348 buffer.write(indirectSources[0]);
6349 }
6350 buffer.write(")");
6351 }
6352 return buffer.toString();
6353 }
6354
6276 ExecutableElement _getOverriddenMember(Element member) { 6355 ExecutableElement _getOverriddenMember(Element member) {
6277 if (member == null || _inheritanceManager == null) { 6356 if (member == null || _inheritanceManager == null) {
6278 return null; 6357 return null;
6279 } 6358 }
6280 6359
6281 ClassElement classElement = 6360 ClassElement classElement =
6282 member.getAncestor((element) => element is ClassElement); 6361 member.getAncestor((element) => element is ClassElement);
6283 if (classElement == null) { 6362 if (classElement == null) {
6284 return null; 6363 return null;
6285 } 6364 }
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
6816 class _InvocationCollector extends RecursiveAstVisitor { 6895 class _InvocationCollector extends RecursiveAstVisitor {
6817 final List<String> superCalls = <String>[]; 6896 final List<String> superCalls = <String>[];
6818 6897
6819 @override 6898 @override
6820 visitMethodInvocation(MethodInvocation node) { 6899 visitMethodInvocation(MethodInvocation node) {
6821 if (node.target is SuperExpression) { 6900 if (node.target is SuperExpression) {
6822 superCalls.add(node.methodName.name); 6901 superCalls.add(node.methodName.name);
6823 } 6902 }
6824 } 6903 }
6825 } 6904 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error.dart ('k') | pkg/analyzer/lib/src/generated/incremental_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698