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

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: Move error generation to DeadCodeVerifier 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..d3a6aa325dee57e78c256b4c109002c0ca3dd35c 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,38 @@ 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;
+ if (combinator is HideCombinator) {
Brian Wilkerson 2016/04/20 21:34:25 Can we pass in the list of names (and the hint cod
srawlins 2016/04/20 21:52:39 I've uploaded another patch. Is this what you want
Brian Wilkerson 2016/04/20 22:49:32 Close enough. I was thinking of void _checkCombin
+ names = combinator.hiddenNames;
+ } else {
+ names = (combinator as ShowCombinator).shownNames;
+ }
+ for (SimpleIdentifier name in names) {
+ String nameStr = name.name;
+ Element element = namespace.get(nameStr);
+ if (element == null) {
+ element = namespace.get("$nameStr=");
+ }
+ if (element == null) {
+ ErrorCode hintCode;
+ if (combinator is HideCombinator) {
+ hintCode = HintCode.UNDEFINED_HIDDEN_NAME;
+ } else {
+ hintCode = HintCode.UNDEFINED_SHOWN_NAME;
+ }
+ _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