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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.generated.resolver; 5 library analyzer.src.generated.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
(...skipping 2265 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 } 2276 }
2277 2277
2278 /** 2278 /**
2279 * A visitor that resolves directives in an AST structure to already built 2279 * A visitor that resolves directives in an AST structure to already built
2280 * elements. 2280 * elements.
2281 * 2281 *
2282 * The resulting AST must have everything resolved that would have been resolved 2282 * The resulting AST must have everything resolved that would have been resolved
2283 * by a [DirectiveElementBuilder]. 2283 * by a [DirectiveElementBuilder].
2284 */ 2284 */
2285 class DirectiveResolver extends SimpleAstVisitor { 2285 class DirectiveResolver extends SimpleAstVisitor {
2286 final Map<Source, int> sourceModificationTimeMap;
2287 final Map<Source, SourceKind> importSourceKindMap;
2288 final Map<Source, SourceKind> exportSourceKindMap;
2289 final List<AnalysisError> errors = <AnalysisError>[];
2290
2286 LibraryElement _enclosingLibrary; 2291 LibraryElement _enclosingLibrary;
2287 2292
2293 DirectiveResolver(this.sourceModificationTimeMap, this.importSourceKindMap,
2294 this.exportSourceKindMap);
2295
2288 @override 2296 @override
2289 void visitCompilationUnit(CompilationUnit node) { 2297 void visitCompilationUnit(CompilationUnit node) {
2290 _enclosingLibrary = 2298 _enclosingLibrary =
2291 resolutionMap.elementDeclaredByCompilationUnit(node).library; 2299 resolutionMap.elementDeclaredByCompilationUnit(node).library;
2292 for (Directive directive in node.directives) { 2300 for (Directive directive in node.directives) {
2293 directive.accept(this); 2301 directive.accept(this);
2294 } 2302 }
2295 } 2303 }
2296 2304
2297 @override 2305 @override
2298 void visitExportDirective(ExportDirective node) { 2306 void visitExportDirective(ExportDirective node) {
2299 int nodeOffset = node.offset; 2307 int nodeOffset = node.offset;
2300 node.element = null; 2308 node.element = null;
2301 for (ExportElement element in _enclosingLibrary.exports) { 2309 for (ExportElement element in _enclosingLibrary.exports) {
2302 if (element.nameOffset == nodeOffset) { 2310 if (element.nameOffset == nodeOffset) {
2303 node.element = element; 2311 node.element = element;
2312 // Verify the exported source kind.
2313 Source exportedSource = element.exportedLibrary.source;
2314 int exportedTime = sourceModificationTimeMap[exportedSource] ?? -1;
2315 if (exportedTime >= 0 &&
2316 exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) {
2317 StringLiteral uriLiteral = node.uri;
2318 errors.add(new AnalysisError(
2319 _enclosingLibrary.source,
2320 uriLiteral.offset,
2321 uriLiteral.length,
2322 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
2323 [uriLiteral.toSource()]));
2324 }
2304 break; 2325 break;
2305 } 2326 }
2306 } 2327 }
2307 } 2328 }
2308 2329
2309 @override 2330 @override
2310 void visitImportDirective(ImportDirective node) { 2331 void visitImportDirective(ImportDirective node) {
2311 int nodeOffset = node.offset; 2332 int nodeOffset = node.offset;
2312 node.element = null; 2333 node.element = null;
2313 for (ImportElement element in _enclosingLibrary.imports) { 2334 for (ImportElement element in _enclosingLibrary.imports) {
2314 if (element.nameOffset == nodeOffset) { 2335 if (element.nameOffset == nodeOffset) {
2315 node.element = element; 2336 node.element = element;
2337 // Verify the imported source kind.
2338 Source importedSource = element.importedLibrary.source;
2339 int importedTime = sourceModificationTimeMap[importedSource] ?? -1;
2340 if (importedTime >= 0 &&
2341 importSourceKindMap[importedSource] != SourceKind.LIBRARY) {
2342 StringLiteral uriLiteral = node.uri;
2343 ErrorCode errorCode = element.isDeferred
2344 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
2345 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY;
2346 errors.add(new AnalysisError(
2347 _enclosingLibrary.source,
2348 uriLiteral.offset,
2349 uriLiteral.length,
2350 errorCode,
2351 [uriLiteral.toSource()]));
2352 }
2316 break; 2353 break;
2317 } 2354 }
2318 } 2355 }
2319 } 2356 }
2320 2357
2321 @override 2358 @override
2322 void visitLibraryDirective(LibraryDirective node) { 2359 void visitLibraryDirective(LibraryDirective node) {
2323 node.element = _enclosingLibrary; 2360 node.element = _enclosingLibrary;
2324 } 2361 }
2325 } 2362 }
(...skipping 8451 matching lines...) Expand 10 before | Expand all | Expand 10 after
10777 return null; 10814 return null;
10778 } 10815 }
10779 if (identical(node.staticElement, variable)) { 10816 if (identical(node.staticElement, variable)) {
10780 if (node.inSetterContext()) { 10817 if (node.inSetterContext()) {
10781 result = true; 10818 result = true;
10782 } 10819 }
10783 } 10820 }
10784 return null; 10821 return null;
10785 } 10822 }
10786 } 10823 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698