| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_impl; | 5 library analyzer_impl; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'generated/java_io.dart'; | 9 import 'generated/java_io.dart'; |
| 10 import 'generated/engine.dart'; | 10 import 'generated/engine.dart'; |
| 11 import 'generated/error.dart'; | 11 import 'generated/error.dart'; |
| 12 import 'generated/source_io.dart'; | 12 import 'generated/source_io.dart'; |
| 13 import 'generated/sdk.dart'; | 13 import 'generated/sdk.dart'; |
| 14 import 'generated/sdk_io.dart'; | 14 import 'generated/sdk_io.dart'; |
| 15 import 'generated/ast.dart'; |
| 15 import 'generated/element.dart'; | 16 import 'generated/element.dart'; |
| 16 import '../options.dart'; | 17 import '../options.dart'; |
| 17 | 18 |
| 18 | 19 |
| 19 DartSdk sdk; | 20 DartSdk sdk; |
| 20 | 21 |
| 21 /// Analyzes single library [File]. | 22 /// Analyzes single library [File]. |
| 22 class AnalyzerImpl { | 23 class AnalyzerImpl { |
| 23 final CommandLineOptions options; | 24 final CommandLineOptions options; |
| 24 | 25 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 43 */ | 44 */ |
| 44 void analyze(String sourcePath) { | 45 void analyze(String sourcePath) { |
| 45 sources.clear(); | 46 sources.clear(); |
| 46 errorInfos.clear(); | 47 errorInfos.clear(); |
| 47 if (sourcePath == null) { | 48 if (sourcePath == null) { |
| 48 throw new ArgumentError("sourcePath cannot be null"); | 49 throw new ArgumentError("sourcePath cannot be null"); |
| 49 } | 50 } |
| 50 var sourceFile = new JavaFile(sourcePath); | 51 var sourceFile = new JavaFile(sourcePath); |
| 51 var uriKind = getUriKind(sourceFile); | 52 var uriKind = getUriKind(sourceFile); |
| 52 var librarySource = new FileBasedSource.con2(contentCache, sourceFile, uriKi
nd); | 53 var librarySource = new FileBasedSource.con2(contentCache, sourceFile, uriKi
nd); |
| 54 // prepare context |
| 55 prepareAnalysisContext(sourceFile); |
| 56 // don't try to analyzer parts |
| 57 var unit = context.parseCompilationUnit(librarySource); |
| 58 var hasLibraryDirective = false; |
| 59 var hasPartOfDirective = false; |
| 60 for (var directive in unit.directives) { |
| 61 if (directive is LibraryDirective) hasLibraryDirective = true; |
| 62 if (directive is PartOfDirective) hasPartOfDirective = true; |
| 63 } |
| 64 if (hasPartOfDirective && !hasLibraryDirective) { |
| 65 print("Only libraries can be analyzed."); |
| 66 print("$sourceFile is a part and can not be analyzed."); |
| 67 return; |
| 68 } |
| 53 // resolve library | 69 // resolve library |
| 54 prepareAnalysisContext(sourceFile); | |
| 55 var libraryElement = context.computeLibraryElement(librarySource); | 70 var libraryElement = context.computeLibraryElement(librarySource); |
| 56 // prepare source and errors | 71 // prepare source and errors |
| 57 prepareSources(libraryElement); | 72 prepareSources(libraryElement); |
| 58 prepareErrors(); | 73 prepareErrors(); |
| 59 } | 74 } |
| 60 | 75 |
| 61 /// Returns the maximal [ErrorSeverity] of the recorded errors. | 76 /// Returns the maximal [ErrorSeverity] of the recorded errors. |
| 62 ErrorSeverity get maxErrorSeverity { | 77 ErrorSeverity get maxErrorSeverity { |
| 63 var status = ErrorSeverity.NONE; | 78 var status = ErrorSeverity.NONE; |
| 64 for (AnalysisErrorInfo errorInfo in errorInfos) { | 79 for (AnalysisErrorInfo errorInfo in errorInfos) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 DirectoryBasedDartSdk directoryBasedSdk = sdk; | 194 DirectoryBasedDartSdk directoryBasedSdk = sdk; |
| 180 String sdkLibPath = directoryBasedSdk.libraryDirectory.getPath() + JavaFil
e.separator; | 195 String sdkLibPath = directoryBasedSdk.libraryDirectory.getPath() + JavaFil
e.separator; |
| 181 if (file.getPath().startsWith(sdkLibPath)) { | 196 if (file.getPath().startsWith(sdkLibPath)) { |
| 182 return UriKind.DART_URI; | 197 return UriKind.DART_URI; |
| 183 } | 198 } |
| 184 } | 199 } |
| 185 // some generic file | 200 // some generic file |
| 186 return UriKind.FILE_URI; | 201 return UriKind.FILE_URI; |
| 187 } | 202 } |
| 188 } | 203 } |
| OLD | NEW |