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

Side by Side Diff: pkg/analyzer_experimental/lib/src/generated/sdk.dart

Issue 14308011: New Analysis Engine snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 3
4 library engine.sdk; 4 library engine.sdk;
5 5
6 import 'dart:io';
7 import 'dart:uri'; 6 import 'dart:uri';
8 import 'java_core.dart'; 7 import 'java_core.dart';
9 import 'java_io.dart';
10 import 'java_engine.dart'; 8 import 'java_engine.dart';
11 import 'java_engine_io.dart'; 9 import 'source.dart' show Source, ContentCache;
12 import 'source_io.dart'; 10 import 'engine.dart' show AnalysisContext;
13 import 'error.dart';
14 import 'scanner.dart';
15 import 'parser.dart';
16 import 'ast.dart';
17 import 'package:analyzer_experimental/src/generated/engine.dart' show AnalysisEn gine;
18 11
19 /** 12 /**
20 * Represents a single library in the SDK 13 * Represents a single library in the SDK
21 */ 14 */
22 abstract class SdkLibrary { 15 abstract class SdkLibrary {
23 /** 16 /**
24 * Return the name of the category containing the library. 17 * Return the name of the category containing the library.
25 * @return the name of the category containing the library 18 * @return the name of the category containing the library
26 */ 19 */
27 String get category; 20 String get category;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 this._path = path2; 153 this._path = path2;
161 } 154 }
162 /** 155 /**
163 * Record that this library can be run on the VM. 156 * Record that this library can be run on the VM.
164 */ 157 */
165 void setVmLibrary() { 158 void setVmLibrary() {
166 _platforms |= VM_PLATFORM; 159 _platforms |= VM_PLATFORM;
167 } 160 }
168 } 161 }
169 /** 162 /**
170 * Instances of the class {@code SdkLibrariesReader} read and parse the librarie s file
171 * (dart-sdk/lib/_internal/libraries.dart) for information about the libraries i n an SDK. The
172 * library information is represented as a Dart file containing a single top-lev el variable whose
173 * value is a const map. The keys of the map are the names of libraries defined in the SDK and the
174 * values in the map are info objects defining the library. For example, a subse t of a typical SDK
175 * might have a libraries file that looks like the following:
176 * <pre>
177 * final Map&lt;String, LibraryInfo&gt; LIBRARIES = const &lt;LibraryInfo&gt; {
178 * // Used by VM applications
179 * "builtin" : const LibraryInfo(
180 * "builtin/builtin_runtime.dart",
181 * category: "Server",
182 * platforms: VM_PLATFORM),
183 * "compiler" : const LibraryInfo(
184 * "compiler/compiler.dart",
185 * category: "Tools",
186 * platforms: 0),
187 * };
188 * </pre>
189 * @coverage dart.engine.sdk
190 */
191 class SdkLibrariesReader {
192 /**
193 * Return the library map read from the given source.
194 * @return the library map read from the given source
195 */
196 LibraryMap readFrom(JavaFile librariesFile, String libraryFileContents) {
197 List<bool> foundError = [false];
198 AnalysisErrorListener errorListener = new AnalysisErrorListener_7(foundError );
199 Source source = new FileBasedSource.con2(null, librariesFile, false);
200 StringScanner scanner = new StringScanner(source, libraryFileContents, error Listener);
201 Parser parser = new Parser(source, errorListener);
202 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize());
203 SdkLibrariesReader_LibraryBuilder libraryBuilder = new SdkLibrariesReader_Li braryBuilder();
204 if (!foundError[0]) {
205 unit.accept(libraryBuilder);
206 }
207 return libraryBuilder.librariesMap;
208 }
209 }
210 class SdkLibrariesReader_LibraryBuilder extends RecursiveASTVisitor<Object> {
211 /**
212 * The prefix added to the name of a library to form the URI used in code to r eference the
213 * library.
214 */
215 static String _LIBRARY_PREFIX = "dart:";
216 /**
217 * The name of the optional parameter used to indicate whether the library is an implementation
218 * library.
219 */
220 static String _IMPLEMENTATION = "implementation";
221 /**
222 * The name of the optional parameter used to indicate whether the library is documented.
223 */
224 static String _DOCUMENTED = "documented";
225 /**
226 * The name of the optional parameter used to specify the category of the libr ary.
227 */
228 static String _CATEGORY = "category";
229 /**
230 * The name of the optional parameter used to specify the platforms on which t he library can be
231 * used.
232 */
233 static String _PLATFORMS = "platforms";
234 /**
235 * The value of the {@link #PLATFORMS platforms} parameter used to specify tha t the library can
236 * be used on the VM.
237 */
238 static String _VM_PLATFORM = "VM_PLATFORM";
239 /**
240 * The library map that is populated by visiting the AST structure parsed from the contents of
241 * the libraries file.
242 */
243 LibraryMap _librariesMap = new LibraryMap();
244 /**
245 * Return the library map that was populated by visiting the AST structure par sed from the
246 * contents of the libraries file.
247 * @return the library map describing the contents of the SDK
248 */
249 LibraryMap get librariesMap => _librariesMap;
250 Object visitMapLiteralEntry(MapLiteralEntry node) {
251 String libraryName = null;
252 Expression key3 = node.key;
253 if (key3 is SimpleStringLiteral) {
254 libraryName = "${_LIBRARY_PREFIX}${((key3 as SimpleStringLiteral)).value}" ;
255 }
256 Expression value9 = node.value;
257 if (value9 is InstanceCreationExpression) {
258 SdkLibraryImpl library = new SdkLibraryImpl(libraryName);
259 List<Expression> arguments7 = ((value9 as InstanceCreationExpression)).arg umentList.arguments;
260 for (Expression argument in arguments7) {
261 if (argument is SimpleStringLiteral) {
262 library.path = ((argument as SimpleStringLiteral)).value;
263 } else if (argument is NamedExpression) {
264 String name20 = ((argument as NamedExpression)).name.label.name;
265 Expression expression15 = ((argument as NamedExpression)).expression;
266 if (name20 == _CATEGORY) {
267 library.category = ((expression15 as SimpleStringLiteral)).value;
268 } else if (name20 == _IMPLEMENTATION) {
269 library.implementation = ((expression15 as BooleanLiteral)).value;
270 } else if (name20 == _DOCUMENTED) {
271 library.documented = ((expression15 as BooleanLiteral)).value;
272 } else if (name20 == _PLATFORMS) {
273 if (expression15 is SimpleIdentifier) {
274 String identifier = ((expression15 as SimpleIdentifier)).name;
275 if (identifier == _VM_PLATFORM) {
276 library.setVmLibrary();
277 } else {
278 library.setDart2JsLibrary();
279 }
280 }
281 }
282 }
283 }
284 _librariesMap.setLibrary(libraryName, library);
285 }
286 return null;
287 }
288 }
289 class AnalysisErrorListener_7 implements AnalysisErrorListener {
290 List<bool> foundError;
291 AnalysisErrorListener_7(this.foundError);
292 void onError(AnalysisError error) {
293 foundError[0] = true;
294 }
295 }
296 /**
297 * Instances of the class {@code LibraryMap} map Dart library URI's to the {@lin k SdkLibraryImpllibrary}. 163 * Instances of the class {@code LibraryMap} map Dart library URI's to the {@lin k SdkLibraryImpllibrary}.
298 * @coverage dart.engine.sdk 164 * @coverage dart.engine.sdk
299 */ 165 */
300 class LibraryMap { 166 class LibraryMap {
301 /** 167 /**
302 * A table mapping Dart library URI's to the library. 168 * A table mapping Dart library URI's to the library.
303 */ 169 */
304 Map<String, SdkLibraryImpl> _libraryMap = new Map<String, SdkLibraryImpl>(); 170 Map<String, SdkLibraryImpl> _libraryMap = new Map<String, SdkLibraryImpl>();
305 /** 171 /**
306 * Initialize a newly created library map to be empty. 172 * Initialize a newly created library map to be empty.
(...skipping 27 matching lines...) Expand all
334 /** 200 /**
335 * Return the number of library URI's for which a mapping is available. 201 * Return the number of library URI's for which a mapping is available.
336 * @return the number of library URI's for which a mapping is available 202 * @return the number of library URI's for which a mapping is available
337 */ 203 */
338 int size() => _libraryMap.length; 204 int size() => _libraryMap.length;
339 } 205 }
340 /** 206 /**
341 * Instances of the class {@code DartSdk} represent a Dart SDK installed in a sp ecified location. 207 * Instances of the class {@code DartSdk} represent a Dart SDK installed in a sp ecified location.
342 * @coverage dart.engine.sdk 208 * @coverage dart.engine.sdk
343 */ 209 */
344 class DartSdk { 210 abstract class DartSdk {
345 /** 211 /**
346 * The short name of the dart SDK core library. 212 * The short name of the dart SDK core library.
347 */ 213 */
348 static String DART_CORE = "dart:core"; 214 static String DART_CORE = "dart:core";
349 /** 215 /**
350 * The short name of the dart SDK html library. 216 * The short name of the dart SDK html library.
351 */ 217 */
352 static String DART_HTML = "dart:html"; 218 static String DART_HTML = "dart:html";
353 /** 219 /**
354 * The directory containing the SDK. 220 * Return the {@link AnalysisContext} used for all of the sources in this {@li nk DartSdk}.
221 * @return the {@link AnalysisContext} used for all of the sources in this {@l ink DartSdk}
355 */ 222 */
356 JavaFile _sdkDirectory; 223 AnalysisContext get context;
357 /**
358 * The revision number of this SDK, or {@code "0"} if the revision number cann ot be discovered.
359 */
360 String _sdkVersion;
361 /**
362 * The file containing the Dartium executable.
363 */
364 JavaFile _dartiumExecutable;
365 /**
366 * The file containing the VM executable.
367 */
368 JavaFile _vmExecutable;
369 /**
370 * A mapping from Dart library URI's to the library represented by that URI.
371 */
372 LibraryMap _libraryMap;
373 /**
374 * The name of the directory within the SDK directory that contains executable s.
375 */
376 static String _BIN_DIRECTORY_NAME = "bin";
377 /**
378 * The name of the directory within the SDK directory that contains Chromium.
379 */
380 static String _CHROMIUM_DIRECTORY_NAME = "chromium";
381 /**
382 * The name of the environment variable whose value is the path to the default Dart SDK directory.
383 */
384 static String _DART_SDK_ENVIRONMENT_VARIABLE_NAME = "DART_SDK";
385 /**
386 * The name of the file containing the Dartium executable on Linux.
387 */
388 static String _DARTIUM_EXECUTABLE_NAME_LINUX = "chromium/chrome";
389 /**
390 * The name of the file containing the Dartium executable on Macintosh.
391 */
392 static String _DARTIUM_EXECUTABLE_NAME_MAC = "Chromium.app/Contents/MacOS/Chro mium";
393 /**
394 * The name of the file containing the Dartium executable on Windows.
395 */
396 static String _DARTIUM_EXECUTABLE_NAME_WIN = "chromium/Chrome.exe";
397 /**
398 * The name of the {@link System} property whose value is the path to the defa ult Dart SDK
399 * directory.
400 */
401 static String _DEFAULT_DIRECTORY_PROPERTY_NAME = "com.google.dart.sdk";
402 /**
403 * The version number that is returned when the real version number could not be determined.
404 */
405 static String _DEFAULT_VERSION = "0";
406 /**
407 * The name of the directory within the SDK directory that contains documentat ion for the
408 * libraries.
409 */
410 static String _DOCS_DIRECTORY_NAME = "docs";
411 /**
412 * The suffix added to the name of a library to derive the name of the file co ntaining the
413 * documentation for that library.
414 */
415 static String _DOC_FILE_SUFFIX = "_api.json";
416 /**
417 * The name of the directory within the SDK directory that contains the librar ies file.
418 */
419 static String _INTERNAL_DIR = "_internal";
420 /**
421 * The name of the directory within the SDK directory that contains the librar ies.
422 */
423 static String _LIB_DIRECTORY_NAME = "lib";
424 /**
425 * The name of the libraries file.
426 */
427 static String _LIBRARIES_FILE = "libraries.dart";
428 /**
429 * The name of the directory within the SDK directory that contains the packag es.
430 */
431 static String _PKG_DIRECTORY_NAME = "pkg";
432 /**
433 * The name of the file within the SDK directory that contains the revision nu mber of the SDK.
434 */
435 static String _REVISION_FILE_NAME = "revision";
436 /**
437 * The name of the file containing the VM executable on the Windows operating system.
438 */
439 static String _VM_EXECUTABLE_NAME_WIN = "dart.exe";
440 /**
441 * The name of the file containing the VM executable on non-Windows operating systems.
442 */
443 static String _VM_EXECUTABLE_NAME = "dart";
444 /**
445 * Return the default Dart SDK, or {@code null} if the directory containing th e default SDK cannot
446 * be determined (or does not exist).
447 * @return the default Dart SDK
448 */
449 static DartSdk get defaultSdk {
450 JavaFile sdkDirectory = defaultSdkDirectory;
451 if (sdkDirectory == null) {
452 return null;
453 }
454 return new DartSdk(sdkDirectory);
455 }
456 /**
457 * Return the default directory for the Dart SDK, or {@code null} if the direc tory cannot be
458 * determined (or does not exist). The default directory is provided by a {@li nk System} property
459 * named {@code com.google.dart.sdk}, or, if the property is not defined, an e nvironment variable
460 * named {@code DART_SDK}.
461 * @return the default directory for the Dart SDK
462 */
463 static JavaFile get defaultSdkDirectory {
464 String sdkProperty = JavaSystemIO.getProperty(_DEFAULT_DIRECTORY_PROPERTY_NA ME);
465 if (sdkProperty == null) {
466 sdkProperty = JavaSystemIO.getenv(_DART_SDK_ENVIRONMENT_VARIABLE_NAME);
467 if (sdkProperty == null) {
468 return null;
469 }
470 }
471 JavaFile sdkDirectory = new JavaFile(sdkProperty);
472 if (!sdkDirectory.exists()) {
473 return null;
474 }
475 return sdkDirectory;
476 }
477 /**
478 * Initialize a newly created SDK to represent the Dart SDK installed in the g iven directory.
479 * @param sdkDirectory the directory containing the SDK
480 */
481 DartSdk(JavaFile sdkDirectory) {
482 this._sdkDirectory = sdkDirectory.getAbsoluteFile();
483 initializeSdk();
484 initializeLibraryMap();
485 }
486 /**
487 * Return the file containing the Dartium executable, or {@code null} if it do es not exist.
488 * @return the file containing the Dartium executable
489 */
490 JavaFile get dartiumExecutable {
491 {
492 if (_dartiumExecutable == null) {
493 JavaFile file = new JavaFile.relative(_sdkDirectory, dartiumBinaryName);
494 if (file.exists()) {
495 _dartiumExecutable = file;
496 }
497 }
498 }
499 return _dartiumExecutable;
500 }
501 /**
502 * Return the directory where dartium can be found in the Dart SDK (the direct ory that will be the
503 * working directory is Dartium is invoked without changing the default).
504 * @return the directory where dartium can be found
505 */
506 JavaFile get dartiumWorkingDirectory {
507 if (OSUtilities.isWindows() || OSUtilities.isMac()) {
508 return _sdkDirectory;
509 } else {
510 return new JavaFile.relative(_sdkDirectory, _CHROMIUM_DIRECTORY_NAME);
511 }
512 }
513 /**
514 * Return the directory containing the SDK.
515 * @return the directory containing the SDK
516 */
517 JavaFile get directory => _sdkDirectory;
518 /**
519 * Return the directory containing documentation for the SDK.
520 * @return the SDK's documentation directory
521 */
522 JavaFile get docDirectory => new JavaFile.relative(_sdkDirectory, _DOCS_DIRECT ORY_NAME);
523 /**
524 * Return the auxiliary documentation file for the given library, or {@code nu ll} if no such file
525 * exists.
526 * @param libraryName the name of the library associated with the documentatio n file to be
527 * returned
528 * @return the auxiliary documentation file for the library
529 */
530 JavaFile getDocFileFor(String libraryName) {
531 JavaFile dir = docDirectory;
532 if (!dir.exists()) {
533 return null;
534 }
535 JavaFile libDir = new JavaFile.relative(dir, libraryName);
536 JavaFile docFile = new JavaFile.relative(libDir, "${libraryName}${_DOC_FILE_ SUFFIX}");
537 if (docFile.exists()) {
538 return docFile;
539 }
540 return null;
541 }
542 /**
543 * Return the directory within the SDK directory that contains the libraries.
544 * @return the directory that contains the libraries
545 */
546 JavaFile get libraryDirectory => new JavaFile.relative(_sdkDirectory, _LIB_DIR ECTORY_NAME);
547 /**
548 * Return the directory within the SDK directory that contains the packages.
549 * @return the directory that contains the packages
550 */
551 JavaFile get packageDirectory => new JavaFile.relative(directory, _PKG_DIRECTO RY_NAME);
552 /** 224 /**
553 * Return an array containing all of the libraries defined in this SDK. 225 * Return an array containing all of the libraries defined in this SDK.
554 * @return the libraries defined in this SDK 226 * @return the libraries defined in this SDK
555 */ 227 */
556 List<SdkLibrary> get sdkLibraries => _libraryMap.sdkLibraries; 228 List<SdkLibrary> get sdkLibraries;
557 /** 229 /**
558 * Return the revision number of this SDK, or {@code "0"} if the revision numb er cannot be 230 * Return the revision number of this SDK, or {@code "0"} if the revision numb er cannot be
559 * discovered. 231 * discovered.
560 * @return the revision number of this SDK 232 * @return the revision number of this SDK
561 */ 233 */
562 String get sdkVersion { 234 String get sdkVersion;
563 {
564 if (_sdkVersion == null) {
565 _sdkVersion = _DEFAULT_VERSION;
566 JavaFile revisionFile = new JavaFile.relative(_sdkDirectory, _REVISION_F ILE_NAME);
567 try {
568 String revision = revisionFile.readAsStringSync();
569 if (revision != null) {
570 _sdkVersion = revision;
571 }
572 } on IOException catch (exception) {
573 }
574 }
575 }
576 return _sdkVersion;
577 }
578 /** 235 /**
579 * Return an array containing the library URI's for the libraries defined in t his SDK. 236 * Return an array containing the library URI's for the libraries defined in t his SDK.
580 * @return the library URI's for the libraries defined in this SDK 237 * @return the library URI's for the libraries defined in this SDK
581 */ 238 */
582 List<String> get uris => _libraryMap.uris; 239 List<String> get uris;
583 /** 240 /**
584 * Return the file containing the VM executable, or {@code null} if it does no t exist. 241 * Return the source representing the library with the given {@code dart:} URI , or {@code null} if
585 * @return the file containing the VM executable 242 * the given URI does not denote a library in this SDK.
243 * @param contentCache the content cache used to access the contents of the ma pped source
244 * @param dartUri the URI of the library to be returned
245 * @return the source representing the specified library
586 */ 246 */
587 JavaFile get vmExecutable { 247 Source mapDartUri(ContentCache contentCache, String dartUri);
588 {
589 if (_vmExecutable == null) {
590 JavaFile file = new JavaFile.relative(new JavaFile.relative(_sdkDirector y, _BIN_DIRECTORY_NAME), binaryName);
591 if (file.exists()) {
592 _vmExecutable = file;
593 }
594 }
595 }
596 return _vmExecutable;
597 }
598 /**
599 * Return {@code true} if this SDK includes documentation.
600 * @return {@code true} if this installation of the SDK has documentation
601 */
602 bool hasDocumentation() => docDirectory.exists();
603 /**
604 * Return {@code true} if the Dartium binary is available.
605 * @return {@code true} if the Dartium binary is available
606 */
607 bool isDartiumInstalled() => dartiumExecutable != null;
608 /**
609 * Return the file representing the library with the given {@code dart:} URI, or {@code null} if
610 * the given URI does not denote a library in this SDK.
611 * @param dartUri the URI of the library to be returned
612 * @return the file representing the specified library
613 */
614 JavaFile mapDartUri(String dartUri) {
615 SdkLibrary library = _libraryMap.getLibrary(dartUri);
616 if (library == null) {
617 return null;
618 }
619 return new JavaFile.relative(libraryDirectory, library.path);
620 }
621 /**
622 * Ensure that the dart VM is executable. If it is not, make it executable and log that it was
623 * necessary for us to do so.
624 */
625 void ensureVmIsExecutable() {
626 }
627 /**
628 * Return the name of the file containing the VM executable.
629 * @return the name of the file containing the VM executable
630 */
631 String get binaryName {
632 if (OSUtilities.isWindows()) {
633 return _VM_EXECUTABLE_NAME_WIN;
634 } else {
635 return _VM_EXECUTABLE_NAME;
636 }
637 }
638 /**
639 * Return the name of the file containing the Dartium executable.
640 * @return the name of the file containing the Dartium executable
641 */
642 String get dartiumBinaryName {
643 if (OSUtilities.isWindows()) {
644 return _DARTIUM_EXECUTABLE_NAME_WIN;
645 } else if (OSUtilities.isMac()) {
646 return _DARTIUM_EXECUTABLE_NAME_MAC;
647 } else {
648 return _DARTIUM_EXECUTABLE_NAME_LINUX;
649 }
650 }
651 /**
652 * Read all of the configuration files to initialize the library maps.
653 */
654 void initializeLibraryMap() {
655 try {
656 JavaFile librariesFile = new JavaFile.relative(new JavaFile.relative(libra ryDirectory, _INTERNAL_DIR), _LIBRARIES_FILE);
657 String contents = librariesFile.readAsStringSync();
658 _libraryMap = new SdkLibrariesReader().readFrom(librariesFile, contents);
659 } catch (exception) {
660 AnalysisEngine.instance.logger.logError3(exception);
661 _libraryMap = new LibraryMap();
662 }
663 }
664 /**
665 * Initialize the state of the SDK.
666 */
667 void initializeSdk() {
668 if (!OSUtilities.isWindows()) {
669 ensureVmIsExecutable();
670 }
671 }
672 } 248 }
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/lib/src/generated/scanner.dart ('k') | pkg/analyzer_experimental/lib/src/generated/sdk_io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698