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

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

Issue 2627093010: Report errors like IMPORT_OF_NON_LIBRARY with the new analysis driver. (Closed)
Patch Set: Created 3 years, 11 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
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 6e3ecfcfdb5f744d75d8850096b2936b3b3c9fae..43146a226bfaa36c4155154194b0ae57d90e80b6 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -2283,8 +2283,16 @@ class DeadCodeVerifier extends RecursiveAstVisitor<Object> {
* by a [DirectiveElementBuilder].
*/
class DirectiveResolver extends SimpleAstVisitor {
+ final Map<Source, int> sourceModificationTimeMap;
+ final Map<Source, SourceKind> importSourceKindMap;
+ final Map<Source, SourceKind> exportSourceKindMap;
+ final List<AnalysisError> errors = <AnalysisError>[];
+
LibraryElement _enclosingLibrary;
+ DirectiveResolver(this.sourceModificationTimeMap, this.importSourceKindMap,
+ this.exportSourceKindMap);
+
@override
void visitCompilationUnit(CompilationUnit node) {
_enclosingLibrary =
@@ -2301,6 +2309,19 @@ class DirectiveResolver extends SimpleAstVisitor {
for (ExportElement element in _enclosingLibrary.exports) {
if (element.nameOffset == nodeOffset) {
node.element = element;
+ // Verify the exported source kind.
+ Source exportedSource = element.exportedLibrary.source;
+ int exportedTime = sourceModificationTimeMap[exportedSource] ?? -1;
+ if (exportedTime >= 0 &&
+ exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) {
+ StringLiteral uriLiteral = node.uri;
+ errors.add(new AnalysisError(
+ _enclosingLibrary.source,
+ uriLiteral.offset,
+ uriLiteral.length,
+ CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
+ [uriLiteral.toSource()]));
+ }
break;
}
}
@@ -2313,6 +2334,22 @@ class DirectiveResolver extends SimpleAstVisitor {
for (ImportElement element in _enclosingLibrary.imports) {
if (element.nameOffset == nodeOffset) {
node.element = element;
+ // Verify the imported source kind.
+ Source importedSource = element.importedLibrary.source;
+ int importedTime = sourceModificationTimeMap[importedSource] ?? -1;
+ if (importedTime >= 0 &&
+ importSourceKindMap[importedSource] != SourceKind.LIBRARY) {
+ StringLiteral uriLiteral = node.uri;
+ ErrorCode errorCode = element.isDeferred
+ ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
+ : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY;
+ errors.add(new AnalysisError(
+ _enclosingLibrary.source,
+ uriLiteral.offset,
+ uriLiteral.length,
+ errorCode,
+ [uriLiteral.toSource()]));
+ }
break;
}
}

Powered by Google App Engine
This is Rietveld 408576698