| 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'; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 /** | 41 /** |
| 42 * Treats the [sourcePath] as the top level library and analyzes it. | 42 * Treats the [sourcePath] as the top level library and analyzes it. |
| 43 */ | 43 */ |
| 44 void analyze(String sourcePath) { | 44 void analyze(String sourcePath) { |
| 45 sources.clear(); | 45 sources.clear(); |
| 46 errorInfos.clear(); | 46 errorInfos.clear(); |
| 47 if (sourcePath == null) { | 47 if (sourcePath == null) { |
| 48 throw new ArgumentError("sourcePath cannot be null"); | 48 throw new ArgumentError("sourcePath cannot be null"); |
| 49 } | 49 } |
| 50 var sourceFile = new JavaFile(sourcePath); | 50 var sourceFile = new JavaFile(sourcePath); |
| 51 var librarySource = new FileBasedSource.con1(contentCache, sourceFile); | 51 var uriKind = getUriKind(sourceFile); |
| 52 var librarySource = new FileBasedSource.con2(contentCache, sourceFile, uriKi
nd); |
| 52 // resolve library | 53 // resolve library |
| 53 prepareAnalysisContext(sourceFile); | 54 prepareAnalysisContext(sourceFile); |
| 54 var libraryElement = context.computeLibraryElement(librarySource); | 55 var libraryElement = context.computeLibraryElement(librarySource); |
| 55 // prepare source and errors | 56 // prepare source and errors |
| 56 prepareSources(libraryElement); | 57 prepareSources(libraryElement); |
| 57 prepareErrors(); | 58 prepareErrors(); |
| 58 } | 59 } |
| 59 | 60 |
| 60 /// Returns the maximal [ErrorSeverity] of the recorded errors. | 61 /// Returns the maximal [ErrorSeverity] of the recorded errors. |
| 61 ErrorSeverity get maxErrorSeverity { | 62 ErrorSeverity get maxErrorSeverity { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 82 if (packageDirectory != null) { | 83 if (packageDirectory != null) { |
| 83 resolvers.add(new PackageUriResolver([packageDirectory])); | 84 resolvers.add(new PackageUriResolver([packageDirectory])); |
| 84 } | 85 } |
| 85 } | 86 } |
| 86 sourceFactory = new SourceFactory.con1(contentCache, resolvers); | 87 sourceFactory = new SourceFactory.con1(contentCache, resolvers); |
| 87 context = AnalysisEngine.instance.createAnalysisContext(); | 88 context = AnalysisEngine.instance.createAnalysisContext(); |
| 88 context.sourceFactory = sourceFactory; | 89 context.sourceFactory = sourceFactory; |
| 89 | 90 |
| 90 // set options for context | 91 // set options for context |
| 91 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl(); | 92 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl(); |
| 93 contextOptions.cacheSize = 256; |
| 92 contextOptions.hint = !options.disableHints; | 94 contextOptions.hint = !options.disableHints; |
| 93 context.analysisOptions = contextOptions; | 95 context.analysisOptions = contextOptions; |
| 94 } | 96 } |
| 95 | 97 |
| 96 /// Fills [sources]. | 98 /// Fills [sources]. |
| 97 void prepareSources(LibraryElement library) { | 99 void prepareSources(LibraryElement library) { |
| 98 var units = new Set<CompilationUnitElement>(); | 100 var units = new Set<CompilationUnitElement>(); |
| 99 var libraries = new Set<LibraryElement>(); | 101 var libraries = new Set<LibraryElement>(); |
| 100 addLibrarySources(library, libraries, units); | 102 addLibrarySources(library, libraries, units); |
| 101 } | 103 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 while (dir != null) { | 160 while (dir != null) { |
| 159 JavaFile packagesDir = new JavaFile.relative(dir, "packages"); | 161 JavaFile packagesDir = new JavaFile.relative(dir, "packages"); |
| 160 if (packagesDir.exists()) { | 162 if (packagesDir.exists()) { |
| 161 return packagesDir; | 163 return packagesDir; |
| 162 } | 164 } |
| 163 dir = dir.getParentFile(); | 165 dir = dir.getParentFile(); |
| 164 } | 166 } |
| 165 // not found | 167 // not found |
| 166 return null; | 168 return null; |
| 167 } | 169 } |
| 170 |
| 171 /** |
| 172 * Returns the [UriKind] for the given input file. Usually {@link UriKind#FILE
_URI}, but if |
| 173 * the given file is located in the "lib" directory of the [sdk], then returns |
| 174 * {@link UriKind#DART_URI}. |
| 175 */ |
| 176 static UriKind getUriKind(JavaFile file) { |
| 177 // may be file in SDK |
| 178 if (sdk is DirectoryBasedDartSdk) { |
| 179 DirectoryBasedDartSdk directoryBasedSdk = sdk; |
| 180 String sdkLibPath = directoryBasedSdk.libraryDirectory.getPath() + JavaFil
e.separator; |
| 181 if (file.getPath().startsWith(sdkLibPath)) { |
| 182 return UriKind.DART_URI; |
| 183 } |
| 184 } |
| 185 // some generic file |
| 186 return UriKind.FILE_URI; |
| 187 } |
| 168 } | 188 } |
| OLD | NEW |