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

Side by Side Diff: pkg/analyzer/lib/src/generated/source.dart

Issue 2486923007: Create pkg/front_end/src/base and begin populating with general use classes. (Closed)
Patch Set: Fix formatting Created 4 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 unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/lib/task/model.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.source; 5 library analyzer.src.generated.source;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
11 import 'package:analyzer/source/package_map_resolver.dart';
12 import 'package:analyzer/src/context/source.dart'; 11 import 'package:analyzer/src/context/source.dart';
13 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/java_engine.dart'; 13 import 'package:analyzer/src/generated/java_engine.dart';
15 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; 14 import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
16 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; 15 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
17 import 'package:analyzer/src/generated/source_io.dart' show FileBasedSource; 16 import 'package:analyzer/src/generated/source_io.dart' show FileBasedSource;
18 import 'package:analyzer/task/model.dart'; 17 import 'package:front_end/src/base/source.dart';
18 import 'package:front_end/src/base/uri_kind.dart';
19 import 'package:package_config/packages.dart'; 19 import 'package:package_config/packages.dart';
20 import 'package:path/path.dart' as pathos; 20 import 'package:path/path.dart' as pathos;
21 21
22 export 'package:front_end/src/base/source.dart' show Source;
23 export 'package:front_end/src/base/uri_kind.dart' show UriKind;
24
22 /** 25 /**
23 * A function that is used to visit [ContentCache] entries. 26 * A function that is used to visit [ContentCache] entries.
24 */ 27 */
25 typedef void ContentCacheVisitor(String fullPath, int stamp, String contents); 28 typedef void ContentCacheVisitor(String fullPath, int stamp, String contents);
26 29
27 /** 30 /**
28 * A cache used to override the default content of a [Source]. 31 * A cache used to override the default content of a [Source].
29 */ 32 */
30 class ContentCache { 33 class ContentCache {
31 /** 34 /**
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 return other.uriKind == uriKind && other.fullName == fullName; 407 return other.uriKind == uriKind && other.fullName == fullName;
405 } 408 }
406 return false; 409 return false;
407 } 410 }
408 411
409 @override 412 @override
410 bool exists() => false; 413 bool exists() => false;
411 } 414 }
412 415
413 /** 416 /**
414 * The interface `Source` defines the behavior of objects representing source co de that can be
415 * analyzed by the analysis engine.
416 *
417 * Implementations of this interface need to be aware of some assumptions made b y the analysis
418 * engine concerning sources:
419 * * Sources are not required to be unique. That is, there can be multiple insta nces representing
420 * the same source.
421 * * Sources are long lived. That is, the engine is allowed to hold on to a sour ce for an extended
422 * period of time and that source must continue to report accurate and up-to-dat e information.
423 * Because of these assumptions, most implementations will not maintain any stat e but will delegate
424 * to an authoritative system of record in order to implement this API. For exam ple, a source that
425 * represents files on disk would typically query the file system to determine t he state of the
426 * file.
427 *
428 * If the instances that implement this API are the system of record, then they will typically be
429 * unique. In that case, sources that are created that represent non-existent fi les must also be
430 * retained so that if those files are created at a later date the long-lived so urces representing
431 * those files will know that they now exist.
432 */
433 abstract class Source implements AnalysisTarget {
434 /**
435 * An empty list of sources.
436 */
437 static const List<Source> EMPTY_LIST = const <Source>[];
438
439 /**
440 * Get the contents and timestamp of this source.
441 *
442 * Clients should consider using the method [AnalysisContext.getContents]
443 * because contexts can have local overrides of the content of a source that t he source is not
444 * aware of.
445 *
446 * @return the contents and timestamp of the source
447 * @throws Exception if the contents of this source could not be accessed
448 */
449 TimestampedData<String> get contents;
450
451 /**
452 * Return an encoded representation of this source that can be used to create a source that is
453 * equal to this source.
454 *
455 * @return an encoded representation of this source
456 * See [SourceFactory.fromEncoding].
457 */
458 String get encoding;
459
460 /**
461 * Return the full (long) version of the name that can be displayed to the use r to denote this
462 * source. For example, for a source representing a file this would typically be the absolute path
463 * of the file.
464 *
465 * @return a name that can be displayed to the user to denote this source
466 */
467 String get fullName;
468
469 /**
470 * Return a hash code for this source.
471 *
472 * @return a hash code for this source
473 * See [Object.hashCode].
474 */
475 @override
476 int get hashCode;
477
478 /**
479 * Return `true` if this source is in one of the system libraries.
480 *
481 * @return `true` if this is in a system library
482 */
483 bool get isInSystemLibrary;
484
485 @override
486 Source get librarySource => null;
487
488 /**
489 * Return the modification stamp for this source, or a negative value if the
490 * source does not exist. A modification stamp is a non-negative integer with
491 * the property that if the contents of the source have not been modified
492 * since the last time the modification stamp was accessed then the same value
493 * will be returned, but if the contents of the source have been modified one
494 * or more times (even if the net change is zero) the stamps will be different .
495 *
496 * Clients should consider using the method
497 * [AnalysisContext.getModificationStamp] because contexts can have local
498 * overrides of the content of a source that the source is not aware of.
499 */
500 int get modificationStamp;
501
502 /**
503 * Return a short version of the name that can be displayed to the user to den ote this source. For
504 * example, for a source representing a file this would typically be the name of the file.
505 *
506 * @return a name that can be displayed to the user to denote this source
507 */
508 String get shortName;
509
510 @override
511 Source get source => this;
512
513 /**
514 * Return the URI from which this source was originally derived.
515 *
516 * @return the URI from which this source was originally derived
517 */
518 Uri get uri;
519
520 /**
521 * Return the kind of URI from which this source was originally derived. If th is source was
522 * created from an absolute URI, then the returned kind will reflect the schem e of the absolute
523 * URI. If it was created from a relative URI, then the returned kind will be the same as the kind
524 * of the source against which the relative URI was resolved.
525 *
526 * @return the kind of URI from which this source was originally derived
527 */
528 UriKind get uriKind;
529
530 /**
531 * Return `true` if the given object is a source that represents the same sour ce code as
532 * this source.
533 *
534 * @param object the object to be compared with this object
535 * @return `true` if the given object is a source that represents the same sou rce code as
536 * this source
537 * See [Object.==].
538 */
539 @override
540 bool operator ==(Object object);
541
542 /**
543 * Return `true` if this source exists.
544 *
545 * Clients should consider using the method [AnalysisContext.exists] because
546 * contexts can have local overrides of the content of a source that the sourc e is not aware of
547 * and a source with local content is considered to exist even if there is no file on disk.
548 *
549 * @return `true` if this source exists
550 */
551 bool exists();
552 }
553
554 /**
555 * The interface `ContentReceiver` defines the behavior of objects that can rece ive the 417 * The interface `ContentReceiver` defines the behavior of objects that can rece ive the
556 * content of a source. 418 * content of a source.
557 */ 419 */
558 abstract class Source_ContentReceiver { 420 abstract class Source_ContentReceiver {
559 /** 421 /**
560 * Accept the contents of a source. 422 * Accept the contents of a source.
561 * 423 *
562 * @param contents the contents of the source 424 * @param contents the contents of the source
563 * @param modificationTime the time at which the contents were last set 425 * @param modificationTime the time at which the contents were last set
564 */ 426 */
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 /** 718 /**
857 * Return `true` if this [SourceRange] starts in the [otherRange]. 719 * Return `true` if this [SourceRange] starts in the [otherRange].
858 */ 720 */
859 bool startsIn(SourceRange otherRange) => otherRange.contains(offset); 721 bool startsIn(SourceRange otherRange) => otherRange.contains(offset);
860 722
861 @override 723 @override
862 String toString() => '[offset=$offset, length=$length]'; 724 String toString() => '[offset=$offset, length=$length]';
863 } 725 }
864 726
865 /** 727 /**
866 * The enumeration `UriKind` defines the different kinds of URI's that are known to the
867 * analysis engine. These are used to keep track of the kind of URI associated w ith a given source.
868 */
869 class UriKind implements Comparable<UriKind> {
870 /**
871 * A 'dart:' URI.
872 */
873 static const UriKind DART_URI = const UriKind('DART_URI', 0, 0x64);
874
875 /**
876 * A 'file:' URI.
877 */
878 static const UriKind FILE_URI = const UriKind('FILE_URI', 1, 0x66);
879
880 /**
881 * A 'package:' URI.
882 */
883 static const UriKind PACKAGE_URI = const UriKind('PACKAGE_URI', 2, 0x70);
884
885 static const List<UriKind> values = const [DART_URI, FILE_URI, PACKAGE_URI];
886
887 /**
888 * The name of this URI kind.
889 */
890 final String name;
891
892 /**
893 * The ordinal value of the URI kind.
894 */
895 final int ordinal;
896
897 /**
898 * The single character encoding used to identify this kind of URI.
899 */
900 final int encoding;
901
902 /**
903 * Initialize a newly created URI kind to have the given encoding.
904 */
905 const UriKind(this.name, this.ordinal, this.encoding);
906
907 @override
908 int get hashCode => ordinal;
909
910 @override
911 int compareTo(UriKind other) => ordinal - other.ordinal;
912
913 @override
914 String toString() => name;
915
916 /**
917 * Return the URI kind represented by the given [encoding], or `null` if there
918 * is no kind with the given encoding.
919 */
920 static UriKind fromEncoding(int encoding) {
921 while (true) {
922 if (encoding == 0x64) {
923 return DART_URI;
924 } else if (encoding == 0x66) {
925 return FILE_URI;
926 } else if (encoding == 0x70) {
927 return PACKAGE_URI;
928 }
929 break;
930 }
931 return null;
932 }
933
934 /**
935 * Return the URI kind corresponding to the given scheme string.
936 */
937 static UriKind fromScheme(String scheme) {
938 if (scheme == PackageMapUriResolver.PACKAGE_SCHEME) {
939 return UriKind.PACKAGE_URI;
940 } else if (scheme == DartUriResolver.DART_SCHEME) {
941 return UriKind.DART_URI;
942 } else if (scheme == ResourceUriResolver.FILE_SCHEME) {
943 return UriKind.FILE_URI;
944 }
945 return UriKind.FILE_URI;
946 }
947 }
948
949 /**
950 * The abstract class `UriResolver` defines the behavior of objects that are use d to resolve 728 * The abstract class `UriResolver` defines the behavior of objects that are use d to resolve
951 * URI's for a source factory. Subclasses of this class are expected to resolve a single scheme of 729 * URI's for a source factory. Subclasses of this class are expected to resolve a single scheme of
952 * absolute URI. 730 * absolute URI.
953 */ 731 */
954 abstract class UriResolver { 732 abstract class UriResolver {
955 /** 733 /**
956 * Resolve the given absolute URI. Return a [Source] representing the file to which 734 * Resolve the given absolute URI. Return a [Source] representing the file to which
957 * it was resolved, whether or not the resulting source exists, or `null` if i t could not be 735 * it was resolved, whether or not the resulting source exists, or `null` if i t could not be
958 * resolved because the URI is invalid. 736 * resolved because the URI is invalid.
959 * 737 *
960 * @param uri the URI to be resolved 738 * @param uri the URI to be resolved
961 * @param actualUri the actual uri for this source -- if `null`, the value of [uri] will be used 739 * @param actualUri the actual uri for this source -- if `null`, the value of [uri] will be used
962 * @return a [Source] representing the file to which given URI was resolved 740 * @return a [Source] representing the file to which given URI was resolved
963 */ 741 */
964 Source resolveAbsolute(Uri uri, [Uri actualUri]); 742 Source resolveAbsolute(Uri uri, [Uri actualUri]);
965 743
966 /** 744 /**
967 * Return an absolute URI that represents the given [source], or `null` if a 745 * Return an absolute URI that represents the given [source], or `null` if a
968 * valid URI cannot be computed. 746 * valid URI cannot be computed.
969 * 747 *
970 * The computation should be based solely on [source.fullName]. 748 * The computation should be based solely on [source.fullName].
971 */ 749 */
972 Uri restoreAbsolute(Source source) => null; 750 Uri restoreAbsolute(Source source) => null;
973 } 751 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/lib/task/model.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698