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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/error_verifier.dart
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index bab17daf8e1132c86e9cbb616de537435116a651..717ef2ad6defb872ebb81583d30b6426aa750be3 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -1127,6 +1127,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
@override
Object visitSimpleIdentifier(SimpleIdentifier node) {
+ _checkForAmbiguousImport(node);
_checkForReferenceBeforeDeclaration(node);
_checkForImplicitThisReferenceInInitializer(node);
if (!_isUnqualifiedReferenceToNonLocalStaticMemberAllowed(node)) {
@@ -2336,6 +2337,37 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
}
/**
+ * Check the given node to see whether it was ambiguous because the name was
+ * imported from two or more imports.
+ */
+ void _checkForAmbiguousImport(SimpleIdentifier node) {
+ Element element = node.staticElement;
+ if (element is MultiplyDefinedElementImpl) {
+ String name = element.displayName;
+ List<Element> conflictingMembers = element.conflictingElements;
+ int count = conflictingMembers.length;
+ List<String> libraryNames = new List<String>(count);
+ for (int i = 0; i < count; i++) {
+ libraryNames[i] = _getLibraryName(conflictingMembers[i]);
+ }
+ libraryNames.sort();
+ _errorReporter.reportErrorForNode(StaticWarningCode.AMBIGUOUS_IMPORT,
+ node, [name, StringUtilities.printListOfQuotedNames(libraryNames)]);
+ } else {
+ List<Element> sdkElements =
+ node.getProperty(LibraryImportScope.conflictingSdkElements);
+ if (sdkElements != null) {
+ _errorReporter.reportErrorForNode(
+ StaticWarningCode.CONFLICTING_DART_IMPORT, node, [
+ element.displayName,
+ _getLibraryName(sdkElements[0]),
+ _getLibraryName(element)
+ ]);
+ }
+ }
+ }
+
+ /**
* Verify that the given [expression] can be assigned to its corresponding
* parameters. The [expectedStaticType] is the expected static type of the
* parameter. The [actualStaticType] is the actual static type of the
@@ -6273,6 +6305,53 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
}
}
+ /**
+ * Return the name of the library that defines given [element].
+ */
+ String _getLibraryName(Element element) {
+ if (element == null) {
+ return StringUtilities.EMPTY;
+ }
+ LibraryElement library = element.library;
+ if (library == null) {
+ return StringUtilities.EMPTY;
+ }
+ List<ImportElement> imports = _currentLibrary.imports;
+ int count = imports.length;
+ for (int i = 0; i < count; i++) {
+ if (identical(imports[i].importedLibrary, library)) {
+ return library.definingCompilationUnit.displayName;
+ }
+ }
+ List<String> indirectSources = new List<String>();
+ for (int i = 0; i < count; i++) {
+ LibraryElement importedLibrary = imports[i].importedLibrary;
+ if (importedLibrary != null) {
+ for (LibraryElement exportedLibrary
+ in importedLibrary.exportedLibraries) {
+ if (identical(exportedLibrary, library)) {
+ indirectSources
+ .add(importedLibrary.definingCompilationUnit.displayName);
+ }
+ }
+ }
+ }
+ int indirectCount = indirectSources.length;
+ StringBuffer buffer = new StringBuffer();
+ buffer.write(library.definingCompilationUnit.displayName);
+ if (indirectCount > 0) {
+ buffer.write(" (via ");
+ if (indirectCount > 1) {
+ indirectSources.sort();
+ buffer.write(StringUtilities.printListOfQuotedNames(indirectSources));
+ } else {
+ buffer.write(indirectSources[0]);
+ }
+ buffer.write(")");
+ }
+ return buffer.toString();
+ }
+
ExecutableElement _getOverriddenMember(Element member) {
if (member == null || _inheritanceManager == null) {
return null;
« 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