From f8a99cde53e5fe3bbbee2d14baeb474487cb8742 Mon Sep 17 00:00:00 2001 From: "paulberry@google.com" Date: Tue, 10 Mar 2015 21:48:49 +0000 Subject: [PATCH] Don't suppress error/warning output for package being analyzed. BUG=dartbug.com/22761 R=brianwilkerson@google.com Review URL: https://codereview.chromium.org//987413003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@44385 260f80e4-7a28-3924-810f-c04153c831b5 --- pkg/analyzer/lib/src/analyzer_impl.dart | 34 +++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pkg/analyzer/lib/src/analyzer_impl.dart b/pkg/analyzer/lib/src/analyzer_impl.dart index a9f72a31a3f..2897e8bd54b 100644 --- a/pkg/analyzer/lib/src/analyzer_impl.dart +++ b/pkg/analyzer/lib/src/analyzer_impl.dart @@ -61,6 +61,15 @@ class AnalyzerImpl { final HashMap sourceErrorsMap = new HashMap(); + /** + * If the file specified on the command line is part of a package, the name + * of that package. Otherwise `null`. This allows us to analyze the file + * specified on the command line as though it is reached via a "package:" + * URI, but avoid suppressing its output in the event that the user has not + * specified the "--package-warnings" option. + */ + String _selfPackageName; + AnalyzerImpl(String sourcePath, this.options, this.startTime, this.isBatch) : sourcePath = _normalizeSourcePath(sourcePath) { if (sdk == null) { @@ -101,7 +110,7 @@ class AnalyzerImpl { { UriKind uriKind = library.source.uriKind; // Optionally skip package: libraries. - if (!options.showPackageWarnings && uriKind == UriKind.PACKAGE_URI) { + if (!options.showPackageWarnings && _isOtherPackage(library.source.uri)) { return; } // Optionally skip SDK libraries. @@ -210,6 +219,11 @@ class AnalyzerImpl { librarySource = computeLibrarySource(); + Uri libraryUri = librarySource.uri; + if (libraryUri.scheme == 'package' && libraryUri.pathSegments.length > 0) { + _selfPackageName = libraryUri.pathSegments[0]; + } + // Create and add a ChangeSet ChangeSet changeSet = new ChangeSet(); changeSet.addedSource(librarySource); @@ -295,7 +309,7 @@ class AnalyzerImpl { } return options.showSdkWarnings; } - if (source.uri.scheme == 'package') { + if (_isOtherPackage(source.uri)) { return options.showPackageWarnings; } return true; @@ -342,6 +356,22 @@ class AnalyzerImpl { return true; } + /** + * Determine whether the given URI refers to a package other than the package + * being analyzed. + */ + bool _isOtherPackage(Uri uri) { + if (uri.scheme != 'package') { + return false; + } + if (_selfPackageName != null && + uri.pathSegments.length > 0 && + uri.pathSegments[0] == _selfPackageName) { + return false; + } + return true; + } + _printColdPerf() { // print cold VM performance numbers int totalTime = JavaSystem.currentTimeMillis() - startTime;