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

Side by Side Diff: pkg/analysis_server/lib/src/context_manager.dart

Issue 1249023003: Clarify nomenclature of "ancestor" and "root" in context manager. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | no next file » | 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 context.directory.manager; 5 library context.directory.manager;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:convert'; 9 import 'dart:convert';
10 import 'dart:core' hide Resource; 10 import 'dart:core' hide Resource;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 : folder = folder, 98 : folder = folder,
99 pathFilter = new PathFilter(folder.path, null) { 99 pathFilter = new PathFilter(folder.path, null) {
100 packageDescriptionPath = packagespecFile.path; 100 packageDescriptionPath = packagespecFile.path;
101 parent.children.add(this); 101 parent.children.add(this);
102 } 102 }
103 103
104 /** 104 /**
105 * Create the virtual [ContextInfo] which acts as an ancestor to all other 105 * Create the virtual [ContextInfo] which acts as an ancestor to all other
106 * [ContextInfo]s. 106 * [ContextInfo]s.
107 */ 107 */
108 ContextInfo._ancestor() 108 ContextInfo._root()
109 : folder = null, 109 : folder = null,
110 pathFilter = null; 110 pathFilter = null;
111 111
112 /** 112 /**
113 * Returns `true` if the folder associated with this context is not contained 113 * Returns `true` if this is a "top level" context, meaning that the folder
114 * within any other folders that have an associated context. 114 * associated with it is not contained within any other folders that have an
115 * associated context.
115 */ 116 */
116 bool get isRoot => parent.parent == null; 117 bool get isTopLevel => parent.parent == null;
117 118
118 /** 119 /**
119 * Returns `true` if [path] is excluded, as it is in one of the children. 120 * Returns `true` if [path] is excluded, as it is in one of the children.
120 */ 121 */
121 bool excludes(String path) { 122 bool excludes(String path) {
122 return children.any((child) { 123 return children.any((child) {
123 return child.folder.contains(path); 124 return child.folder.contains(path);
124 }); 125 });
125 } 126 }
126 127
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 */ 357 */
357 final InstrumentationService _instrumentationService; 358 final InstrumentationService _instrumentationService;
358 359
359 @override 360 @override
360 ContextManagerCallbacks callbacks; 361 ContextManagerCallbacks callbacks;
361 362
362 /** 363 /**
363 * Virtual [ContextInfo] which acts as the ancestor of all other 364 * Virtual [ContextInfo] which acts as the ancestor of all other
364 * [ContextInfo]s. 365 * [ContextInfo]s.
365 */ 366 */
366 final ContextInfo _ancestorInfo = new ContextInfo._ancestor(); 367 final ContextInfo _rootInfo = new ContextInfo._root();
367 368
368 ContextManagerImpl(this.resourceProvider, this.packageResolverProvider, 369 ContextManagerImpl(this.resourceProvider, this.packageResolverProvider,
369 this._packageMapProvider, this._instrumentationService) { 370 this._packageMapProvider, this._instrumentationService) {
370 pathContext = resourceProvider.pathContext; 371 pathContext = resourceProvider.pathContext;
371 } 372 }
372 373
373 @override 374 @override
374 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) { 375 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) {
375 List<AnalysisContext> contexts = <AnalysisContext>[]; 376 List<AnalysisContext> contexts = <AnalysisContext>[];
376 _contexts.forEach((Folder contextFolder, ContextInfo info) { 377 _contexts.forEach((Folder contextFolder, ContextInfo info) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 info.packageRoot = newPackageRoot; 498 info.packageRoot = newPackageRoot;
498 _recomputePackageUriResolver(info); 499 _recomputePackageUriResolver(info);
499 } 500 }
500 }); 501 });
501 // create new contexts 502 // create new contexts
502 for (Folder includedFolder in includedFolders) { 503 for (Folder includedFolder in includedFolders) {
503 bool wasIncluded = contextFolders.any((folder) { 504 bool wasIncluded = contextFolders.any((folder) {
504 return folder.isOrContains(includedFolder.path); 505 return folder.isOrContains(includedFolder.path);
505 }); 506 });
506 if (!wasIncluded) { 507 if (!wasIncluded) {
507 _createContexts(_ancestorInfo, includedFolder, false); 508 _createContexts(_rootInfo, includedFolder, false);
508 } 509 }
509 } 510 }
510 // remove newly excluded sources 511 // remove newly excluded sources
511 _contexts.forEach((folder, info) { 512 _contexts.forEach((folder, info) {
512 // prepare excluded sources 513 // prepare excluded sources
513 Map<String, Source> excludedSources = new HashMap<String, Source>(); 514 Map<String, Source> excludedSources = new HashMap<String, Source>();
514 info.sources.forEach((String path, Source source) { 515 info.sources.forEach((String path, Source source) {
515 if (_isExcludedBy(excludedPaths, path) && 516 if (_isExcludedBy(excludedPaths, path) &&
516 !_isExcludedBy(oldExcludedPaths, path)) { 517 !_isExcludedBy(oldExcludedPaths, path)) {
517 excludedSources[path] = source; 518 excludedSources[path] = source;
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 if (_isInPackagesDir(path, folder)) { 912 if (_isInPackagesDir(path, folder)) {
912 return; 913 return;
913 } 914 }
914 915
915 Resource resource = resourceProvider.getResource(path); 916 Resource resource = resourceProvider.getResource(path);
916 917
917 if (ENABLE_PACKAGESPEC_SUPPORT) { 918 if (ENABLE_PACKAGESPEC_SUPPORT) {
918 String directoryPath = pathContext.dirname(path); 919 String directoryPath = pathContext.dirname(path);
919 920
920 // Check to see if we need to create a new context. 921 // Check to see if we need to create a new context.
921 if (info.isRoot) { 922 if (info.isTopLevel) {
922 923
923 // Only create a new context if this is not the same directory 924 // Only create a new context if this is not the same directory
924 // described by our info object. 925 // described by our info object.
925 if (info.folder.path != directoryPath) { 926 if (info.folder.path != directoryPath) {
926 if (_isPubspec(path)) { 927 if (_isPubspec(path)) {
927 // Check for a sibling .packages file. 928 // Check for a sibling .packages file.
928 if (!resourceProvider.getFile( 929 if (!resourceProvider.getFile(
929 pathos.join(directoryPath, PACKAGE_SPEC_NAME)).exists) { 930 pathos.join(directoryPath, PACKAGE_SPEC_NAME)).exists) {
930 _extractContext(info, resource); 931 _extractContext(info, resource);
931 return; 932 return;
932 } 933 }
933 } 934 }
934 if (_isPackagespec(path)) { 935 if (_isPackagespec(path)) {
935 // Check for a sibling pubspec.yaml file. 936 // Check for a sibling pubspec.yaml file.
936 if (!resourceProvider 937 if (!resourceProvider
937 .getFile(pathos.join(directoryPath, PUBSPEC_NAME)).exists) { 938 .getFile(pathos.join(directoryPath, PUBSPEC_NAME)).exists) {
938 _extractContext(info, resource); 939 _extractContext(info, resource);
939 return; 940 return;
940 } 941 }
941 } 942 }
942 } 943 }
943 } 944 }
944 } else { 945 } else {
945 // pubspec was added in a sub-folder, extract a new context 946 // pubspec was added in a sub-folder, extract a new context
946 if (_isPubspec(path) && 947 if (_isPubspec(path) &&
947 info.isRoot && 948 info.isTopLevel &&
948 !info.isPathToPackageDescription(path)) { 949 !info.isPathToPackageDescription(path)) {
949 _extractContext(info, resource); 950 _extractContext(info, resource);
950 return; 951 return;
951 } 952 }
952 } 953 }
953 954
954 // If the file went away and was replaced by a folder before we 955 // If the file went away and was replaced by a folder before we
955 // had a chance to process the event, resource might be a Folder. In 956 // had a chance to process the event, resource might be a Folder. In
956 // that case don't add it. 957 // that case don't add it.
957 if (resource is File) { 958 if (resource is File) {
958 File file = resource; 959 File file = resource;
959 if (callbacks.shouldFileBeAnalyzed(file)) { 960 if (callbacks.shouldFileBeAnalyzed(file)) {
960 ChangeSet changeSet = new ChangeSet(); 961 ChangeSet changeSet = new ChangeSet();
961 Source source = createSourceInContext(info.context, file); 962 Source source = createSourceInContext(info.context, file);
962 changeSet.addedSource(source); 963 changeSet.addedSource(source);
963 callbacks.applyChangesToContext(folder, changeSet); 964 callbacks.applyChangesToContext(folder, changeSet);
964 info.sources[path] = source; 965 info.sources[path] = source;
965 } 966 }
966 } 967 }
967 break; 968 break;
968 case ChangeType.REMOVE: 969 case ChangeType.REMOVE:
969 970
970 // If package spec info is removed, check to see if we can merge context s. 971 // If package spec info is removed, check to see if we can merge context s.
971 // Note that it's important to verify that there is NEITHER a .packages nor a 972 // Note that it's important to verify that there is NEITHER a .packages nor a
972 // lingering pubspec.yaml before merging. 973 // lingering pubspec.yaml before merging.
973 if (!info.isRoot) { 974 if (!info.isTopLevel) {
974 if (ENABLE_PACKAGESPEC_SUPPORT) { 975 if (ENABLE_PACKAGESPEC_SUPPORT) {
975 String directoryPath = pathContext.dirname(path); 976 String directoryPath = pathContext.dirname(path);
976 977
977 // Only merge if this is the same directory described by our info ob ject. 978 // Only merge if this is the same directory described by our info ob ject.
978 if (info.folder.path == directoryPath) { 979 if (info.folder.path == directoryPath) {
979 if (_isPubspec(path)) { 980 if (_isPubspec(path)) {
980 // Check for a sibling .packages file. 981 // Check for a sibling .packages file.
981 if (!resourceProvider.getFile( 982 if (!resourceProvider.getFile(
982 pathos.join(directoryPath, PACKAGE_SPEC_NAME)).exists) { 983 pathos.join(directoryPath, PACKAGE_SPEC_NAME)).exists) {
983 _mergeContext(info); 984 _mergeContext(info);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 */ 1151 */
1151 final List<AnalysisContext> removed; 1152 final List<AnalysisContext> removed;
1152 1153
1153 /** 1154 /**
1154 * Initialize a newly created event to indicate which contexts have changed. 1155 * Initialize a newly created event to indicate which contexts have changed.
1155 */ 1156 */
1156 ContextsChangedEvent({this.added: AnalysisContext.EMPTY_LIST, 1157 ContextsChangedEvent({this.added: AnalysisContext.EMPTY_LIST,
1157 this.changed: AnalysisContext.EMPTY_LIST, 1158 this.changed: AnalysisContext.EMPTY_LIST,
1158 this.removed: AnalysisContext.EMPTY_LIST}); 1159 this.removed: AnalysisContext.EMPTY_LIST});
1159 } 1160 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698