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

Unified Diff: pkg/analyzer/lib/src/dart/analysis/analysis_impl.dart

Issue 2684793003: Resolve import/export directives in analyzer itself, report non-libraries. (Closed)
Patch Set: Created 3 years, 10 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/analysis/analysis_impl.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/analysis_impl.dart b/pkg/analyzer/lib/src/dart/analysis/analysis_impl.dart
index 8edc373b73717a2388cf72af14b9a929a957f831..cb70d84d115f8c94b358895ef5e5863b2e646f65 100644
--- a/pkg/analyzer/lib/src/dart/analysis/analysis_impl.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/analysis_impl.dart
@@ -331,6 +331,14 @@ class AnalyzerImpl {
}
/**
+ * Return `true` if the given [source] is a library.
+ */
+ bool _isLibrarySource(Source source) {
+ String uriStr = source.uri.toString();
+ return _store.unlinkedMap[uriStr]?.isPartOf == false;
+ }
+
+ /**
* Return a new parsed unresolved [CompilationUnit].
*/
CompilationUnit _parse(FileState file) {
@@ -379,6 +387,31 @@ class AnalyzerImpl {
if (directive is LibraryDirective) {
libraryNameNode = directive.name;
directivesToResolve.add(directive);
+ } else if (directive is ImportDirective) {
+ for (ImportElement importElement in _libraryElement.imports) {
+ if (importElement.nameOffset == directive.offset) {
+ directive.element = importElement;
+ if (!_isLibrarySource(importElement.importedLibrary.source)) {
+ ErrorCode errorCode = importElement.isDeferred
+ ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
+ : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY;
+ libraryErrorReporter.reportErrorForNode(
+ errorCode, directive.uri, [directive.uri]);
+ }
+ }
+ }
+ } else if (directive is ExportDirective) {
+ for (ExportElement exportElement in _libraryElement.exports) {
+ if (exportElement.nameOffset == directive.offset) {
+ directive.element = exportElement;
+ if (!_isLibrarySource(exportElement.exportedLibrary.source)) {
+ libraryErrorReporter.reportErrorForNode(
+ CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
+ directive.uri,
+ [directive.uri]);
+ }
+ }
+ }
} else if (directive is PartDirective) {
hasPartDirective = true;
StringLiteral partUri = directive.uri;
@@ -441,11 +474,7 @@ class AnalyzerImpl {
directive.element = _libraryElement;
}
- {
- // TODO(scheglov) fill these maps?
- DirectiveResolver resolver = new DirectiveResolver({}, {}, {});
- definingCompilationUnit.accept(resolver);
- }
+ // TODO(scheglov) remove DirectiveResolver class
}
void _resolveFile(FileState file, CompilationUnit unit) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698