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

Unified Diff: pkg/analyzer/lib/src/analyzer_impl.dart

Issue 54903009: Issue 14685. Don't analyzer parts. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Inform user that only libraries can be analyzed. Created 7 years, 1 month 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/analyzer_impl.dart
diff --git a/pkg/analyzer/lib/src/analyzer_impl.dart b/pkg/analyzer/lib/src/analyzer_impl.dart
index c7beef72ad41fd5a5b415b05dd0d889cf8f85b46..7f79c5d0d57a9355ff817b38790622ec38320045 100644
--- a/pkg/analyzer/lib/src/analyzer_impl.dart
+++ b/pkg/analyzer/lib/src/analyzer_impl.dart
@@ -12,6 +12,7 @@ import 'generated/error.dart';
import 'generated/source_io.dart';
import 'generated/sdk.dart';
import 'generated/sdk_io.dart';
+import 'generated/ast.dart';
import 'generated/element.dart';
import '../options.dart';
@@ -50,8 +51,22 @@ class AnalyzerImpl {
var sourceFile = new JavaFile(sourcePath);
var uriKind = getUriKind(sourceFile);
var librarySource = new FileBasedSource.con2(contentCache, sourceFile, uriKind);
- // resolve library
+ // prepare context
prepareAnalysisContext(sourceFile);
+ // don't try to analyzer parts
+ var unit = context.parseCompilationUnit(librarySource);
+ var hasLibraryDirective = false;
+ var hasPartOfDirective = false;
+ for (var directive in unit.directives) {
+ if (directive is LibraryDirective) hasLibraryDirective = true;
+ if (directive is PartOfDirective) hasPartOfDirective = true;
+ }
+ if (hasPartOfDirective && !hasLibraryDirective) {
+ print("Only libraries can be analyzed.");
+ print("$sourceFile is a part and can not be analyzed.");
+ return;
+ }
+ // resolve library
var libraryElement = context.computeLibraryElement(librarySource);
// prepare source and errors
prepareSources(libraryElement);

Powered by Google App Engine
This is Rietveld 408576698