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

Unified Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1901923002: Add UNDEFINED_HIDDEN_NAME, UNDEFINED_SHOWN_NAME (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: less "is" Created 4 years, 8 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/test/generated/hint_code_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 3f1c0ed3e7638d871a9b04261d8f8aa9ee92354b..a56ec4a20a17ea4a9831fc7e671a350afbba514c 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -1932,6 +1932,21 @@ class DeadCodeVerifier extends RecursiveAstVisitor<Object> {
}
@override
+ Object visitExportDirective(ExportDirective node) {
+ ExportElement exportElement = node.element;
+ if (exportElement != null) {
+ // The element is null when the URI is invalid
+ LibraryElement library = exportElement.exportedLibrary;
+ if (library != null) {
+ for (Combinator combinator in node.combinators) {
+ _checkCombinator(exportElement.exportedLibrary, combinator);
+ }
+ }
+ }
+ return super.visitExportDirective(node);
+ }
+
+ @override
Object visitIfStatement(IfStatement node) {
Expression conditionExpression = node.condition;
conditionExpression?.accept(this);
@@ -1961,6 +1976,21 @@ class DeadCodeVerifier extends RecursiveAstVisitor<Object> {
}
@override
+ Object visitImportDirective(ImportDirective node) {
+ ImportElement importElement = node.element;
+ if (importElement != null) {
+ // The element is null when the URI is invalid
+ LibraryElement library = importElement.importedLibrary;
+ if (library != null) {
+ for (Combinator combinator in node.combinators) {
+ _checkCombinator(library, combinator);
+ }
+ }
+ }
+ return super.visitImportDirective(node);
+ }
+
+ @override
Object visitSwitchCase(SwitchCase node) {
_checkForDeadStatementsInNodeList(node.statements);
return super.visitSwitchCase(node);
@@ -2060,6 +2090,35 @@ class DeadCodeVerifier extends RecursiveAstVisitor<Object> {
}
/**
+ * Resolve the names in the given [combinator] in the scope of the given
+ * [library].
+ */
+ void _checkCombinator(LibraryElement library, Combinator combinator) {
+ Namespace namespace =
+ new NamespaceBuilder().createExportNamespaceForLibrary(library);
+ NodeList<SimpleIdentifier> names;
+ ErrorCode hintCode;
+ if (combinator is HideCombinator) {
+ names = combinator.hiddenNames;
+ hintCode = HintCode.UNDEFINED_HIDDEN_NAME;
+ } else {
+ names = (combinator as ShowCombinator).shownNames;
+ hintCode = HintCode.UNDEFINED_SHOWN_NAME;
+ }
+ for (SimpleIdentifier name in names) {
+ String nameStr = name.name;
+ Element element = namespace.get(nameStr);
+ if (element == null) {
+ element = namespace.get("$nameStr=");
+ }
+ if (element == null) {
+ _errorReporter.reportErrorForNode(
+ hintCode, name, [library.identifier, nameStr]);
+ }
+ }
+ }
+
+ /**
* Given some [NodeList] of [Statement]s, from either a [Block] or
* [SwitchMember], this loops through the list in reverse order searching for statements
* after a return, unlabeled break or unlabeled continue statement to mark them as dead code.
« no previous file with comments | « pkg/analyzer/lib/src/generated/error.dart ('k') | pkg/analyzer/test/generated/hint_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698