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

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

Issue 131233009: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 // 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.index; 8 library engine.index;
9 9
10 import 'dart:collection' show Queue; 10 import 'dart:collection' show Queue;
11 import 'java_core.dart'; 11 import 'java_core.dart';
12 import 'java_engine.dart'; 12 import 'java_engine.dart';
13 import 'source.dart'; 13 import 'source.dart';
14 import 'scanner.dart' show Token; 14 import 'scanner.dart' show Token;
15 import 'ast.dart'; 15 import 'ast.dart';
16 import 'element.dart'; 16 import 'element.dart';
17 import 'resolver.dart' show Namespace, NamespaceBuilder; 17 import 'resolver.dart' show Namespace, NamespaceBuilder;
18 import 'engine.dart' show AnalysisEngine, AnalysisContext, InstrumentedAnalysisC ontextImpl, AngularHtmlUnitResolver; 18 import 'engine.dart';
19 import 'html.dart' as ht; 19 import 'html.dart' as ht;
20 20
21 /** 21 /**
22 * Instances of the [RemoveSourceOperation] implement an operation that removes from the index 22 * Instances of the [RemoveSourceOperation] implement an operation that removes from the index
23 * any data based on the content of a specified source. 23 * any data based on the content of a specified source.
24 * 24 *
25 * @coverage dart.engine.index 25 * @coverage dart.engine.index
26 */ 26 */
27 class RemoveSourceOperation implements IndexOperation { 27 class RemoveSourceOperation implements IndexOperation {
28 /** 28 /**
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 context = (context as InstrumentedAnalysisContextImpl).basis; 114 context = (context as InstrumentedAnalysisContextImpl).basis;
115 } 115 }
116 return context; 116 return context;
117 } 117 }
118 118
119 /** 119 /**
120 * @return the [Source] of the enclosing [LibraryElement], may be `null`. 120 * @return the [Source] of the enclosing [LibraryElement], may be `null`.
121 */ 121 */
122 static Source getLibrarySourceOrNull(Element element) { 122 static Source getLibrarySourceOrNull(Element element) {
123 LibraryElement library = element.library; 123 LibraryElement library = element.library;
124 return library != null ? library.source : null; 124 if (library == null) {
125 return null;
126 }
127 if (library.isAngularHtml) {
128 return null;
129 }
130 return library.source;
125 } 131 }
126 132
127 /** 133 /**
128 * We add [AnalysisContext] to this weak set to ensure that we don't continue to add 134 * We add [AnalysisContext] to this weak set to ensure that we don't continue to add
129 * relationships after some context was removed using [removeContext]. 135 * relationships after some context was removed using [removeContext].
130 */ 136 */
131 Expando _removedContexts = new Expando(); 137 Expando _removedContexts = new Expando();
132 138
133 /** 139 /**
134 * This map is used to canonicalize equal keys. 140 * This map is used to canonicalize equal keys.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 if (oldParts != null) { 215 if (oldParts != null) {
210 Set<Source> noParts = oldParts.difference(newParts); 216 Set<Source> noParts = oldParts.difference(newParts);
211 for (Source noPart in noParts) { 217 for (Source noPart in noParts) {
212 removeLocations(context, library, noPart); 218 removeLocations(context, library, noPart);
213 } 219 }
214 } 220 }
215 // remember new parts 221 // remember new parts
216 libraryToUnits[library] = newParts; 222 libraryToUnits[library] = newParts;
217 } 223 }
218 // remember libraries in which unit is used 224 // remember libraries in which unit is used
219 Map<Source, Set<Source>> unitToLibraries = _contextToUnitToLibraries[context ]; 225 recordUnitInLibrary(context, library, unit);
220 if (unitToLibraries == null) {
221 unitToLibraries = {};
222 _contextToUnitToLibraries[context] = unitToLibraries;
223 }
224 Set<Source> libraries = unitToLibraries[unit];
225 if (libraries == null) {
226 libraries = new Set();
227 unitToLibraries[unit] = libraries;
228 }
229 libraries.add(library);
230 // remove locations 226 // remove locations
231 removeLocations(context, library, unit); 227 removeLocations(context, library, unit);
232 // remove keys 228 // remove keys
233 { 229 {
234 Map<MemoryIndexStoreImpl_Source2, Set<MemoryIndexStoreImpl_ElementRelation Key>> sourceToKeys = _contextToSourceToKeys[context]; 230 Map<MemoryIndexStoreImpl_Source2, Set<MemoryIndexStoreImpl_ElementRelation Key>> sourceToKeys = _contextToSourceToKeys[context];
235 if (sourceToKeys != null) { 231 if (sourceToKeys != null) {
236 MemoryIndexStoreImpl_Source2 source2 = new MemoryIndexStoreImpl_Source2( library, unit); 232 MemoryIndexStoreImpl_Source2 source2 = new MemoryIndexStoreImpl_Source2( library, unit);
237 sourceToKeys.remove(source2); 233 bool hadSource = sourceToKeys.remove(source2) != null;
234 if (hadSource) {
235 _sourceCount--;
236 }
238 } 237 }
239 } 238 }
240 // OK, we can index 239 // OK, we can index
241 return true; 240 return true;
242 } 241 }
243 242
244 bool aboutToIndex2(AnalysisContext context, Source source) { 243 bool aboutToIndex2(AnalysisContext context, HtmlElement htmlElement) {
245 context = unwrapContext(context); 244 context = unwrapContext(context);
246 // may be already removed in other thread 245 // may be already removed in other thread
247 if (isRemovedContext(context)) { 246 if (isRemovedContext(context)) {
248 return false; 247 return false;
249 } 248 }
250 // remove locations 249 // remove locations
251 removeLocations(context, source, source); 250 Source source = htmlElement.source;
251 removeLocations(context, null, source);
252 // remove keys 252 // remove keys
253 { 253 {
254 Map<MemoryIndexStoreImpl_Source2, Set<MemoryIndexStoreImpl_ElementRelation Key>> sourceToKeys = _contextToSourceToKeys[context]; 254 Map<MemoryIndexStoreImpl_Source2, Set<MemoryIndexStoreImpl_ElementRelation Key>> sourceToKeys = _contextToSourceToKeys[context];
255 if (sourceToKeys != null) { 255 if (sourceToKeys != null) {
256 MemoryIndexStoreImpl_Source2 source2 = new MemoryIndexStoreImpl_Source2( source, source); 256 MemoryIndexStoreImpl_Source2 source2 = new MemoryIndexStoreImpl_Source2( null, source);
257 sourceToKeys.remove(source2); 257 bool hadSource = sourceToKeys.remove(source2) != null;
258 if (hadSource) {
259 _sourceCount--;
260 }
258 } 261 }
259 } 262 }
263 // remember libraries in which unit is used
264 recordUnitInLibrary(context, null, source);
260 // OK, we can index 265 // OK, we can index
261 return true; 266 return true;
262 } 267 }
263 268
264 List<Location> getRelationships(Element element, Relationship relationship) { 269 List<Location> getRelationships(Element element, Relationship relationship) {
265 MemoryIndexStoreImpl_ElementRelationKey key = new MemoryIndexStoreImpl_Eleme ntRelationKey(element, relationship); 270 MemoryIndexStoreImpl_ElementRelationKey key = new MemoryIndexStoreImpl_Eleme ntRelationKey(element, relationship);
266 Set<Location> locations = _keyToLocations[key]; 271 Set<Location> locations = _keyToLocations[key];
267 if (locations != null) { 272 if (locations != null) {
268 return new List.from(locations); 273 return new List.from(locations);
269 } 274 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 313
309 void recordRelationship(Element element, Relationship relationship, Location l ocation) { 314 void recordRelationship(Element element, Relationship relationship, Location l ocation) {
310 if (element == null || location == null) { 315 if (element == null || location == null) {
311 return; 316 return;
312 } 317 }
313 location = location.clone(); 318 location = location.clone();
314 // at the index level we don't care about Member(s) 319 // at the index level we don't care about Member(s)
315 if (element is Member) { 320 if (element is Member) {
316 element = (element as Member).baseElement; 321 element = (element as Member).baseElement;
317 } 322 }
323 // System.out.println(element + " " + relationship + " " + location);
318 // prepare information 324 // prepare information
319 AnalysisContext elementContext = element.context; 325 AnalysisContext elementContext = element.context;
320 AnalysisContext locationContext = location.element.context; 326 AnalysisContext locationContext = location.element.context;
321 Source elementSource = element.source; 327 Source elementSource = element.source;
322 Source locationSource = location.element.source; 328 Source locationSource = location.element.source;
323 Source elementLibrarySource = getLibrarySourceOrNull(element); 329 Source elementLibrarySource = getLibrarySourceOrNull(element);
324 Source locationLibrarySource = getLibrarySourceOrNull(location.element); 330 Source locationLibrarySource = getLibrarySourceOrNull(location.element);
325 // sanity check 331 // sanity check
326 if (locationContext == null) { 332 if (locationContext == null) {
327 return; 333 return;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 */ 502 */
497 bool isRemovedContext(AnalysisContext context) => _removedContexts[context] != null; 503 bool isRemovedContext(AnalysisContext context) => _removedContexts[context] != null;
498 504
499 /** 505 /**
500 * Marks given [AnalysisContext] as removed. 506 * Marks given [AnalysisContext] as removed.
501 */ 507 */
502 void markRemovedContext(AnalysisContext context) { 508 void markRemovedContext(AnalysisContext context) {
503 _removedContexts[context] = true; 509 _removedContexts[context] = true;
504 } 510 }
505 511
512 void recordUnitInLibrary(AnalysisContext context, Source library, Source unit) {
513 Map<Source, Set<Source>> unitToLibraries = _contextToUnitToLibraries[context ];
514 if (unitToLibraries == null) {
515 unitToLibraries = {};
516 _contextToUnitToLibraries[context] = unitToLibraries;
517 }
518 Set<Source> libraries = unitToLibraries[unit];
519 if (libraries == null) {
520 libraries = new Set();
521 unitToLibraries[unit] = libraries;
522 }
523 libraries.add(library);
524 }
525
506 /** 526 /**
507 * Removes locations recorded in the given library/unit pair. 527 * Removes locations recorded in the given library/unit pair.
508 */ 528 */
509 void removeLocations(AnalysisContext context, Source library, Source unit) { 529 void removeLocations(AnalysisContext context, Source library, Source unit) {
510 MemoryIndexStoreImpl_Source2 source2 = new MemoryIndexStoreImpl_Source2(libr ary, unit); 530 MemoryIndexStoreImpl_Source2 source2 = new MemoryIndexStoreImpl_Source2(libr ary, unit);
511 Map<MemoryIndexStoreImpl_Source2, List<Location>> sourceToLocations = _conte xtToSourceToLocations[context]; 531 Map<MemoryIndexStoreImpl_Source2, List<Location>> sourceToLocations = _conte xtToSourceToLocations[context];
512 if (sourceToLocations != null) { 532 if (sourceToLocations != null) {
513 List<Location> sourceLocations = sourceToLocations.remove(source2); 533 List<Location> sourceLocations = sourceToLocations.remove(source2);
514 if (sourceLocations != null) { 534 if (sourceLocations != null) {
515 for (Location location in sourceLocations) { 535 for (Location location in sourceLocations) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 visitExpressions(node.expressions); 691 visitExpressions(node.expressions);
672 return super.visitXmlAttributeNode(node); 692 return super.visitXmlAttributeNode(node);
673 } 693 }
674 694
675 Object visitXmlTagNode(ht.XmlTagNode node) { 695 Object visitXmlTagNode(ht.XmlTagNode node) {
676 visitExpressions(node.expressions); 696 visitExpressions(node.expressions);
677 return super.visitXmlTagNode(node); 697 return super.visitXmlTagNode(node);
678 } 698 }
679 699
680 /** 700 /**
681 * Visits [Expression]s of the given [EmbeddedExpression]s. 701 * Visits [Expression]s of the given [XmlExpression]s.
682 */ 702 */
683 void visitExpressions(List<ht.EmbeddedExpression> expressions) { 703 void visitExpressions(List<ht.XmlExpression> expressions) {
684 for (ht.EmbeddedExpression embeddedExpression in expressions) { 704 for (ht.XmlExpression xmlExpression in expressions) {
685 Expression expression = embeddedExpression.expression; 705 if (xmlExpression is AngularXmlExpression) {
686 visitExpression(expression); 706 AngularXmlExpression angularXmlExpression = xmlExpression;
707 List<Expression> dartExpressions = angularXmlExpression.expression.expre ssions;
708 for (Expression dartExpression in dartExpressions) {
709 visitExpression(dartExpression);
710 }
711 }
712 if (xmlExpression is ht.RawXmlExpression) {
713 ht.RawXmlExpression rawXmlExpression = xmlExpression;
714 visitExpression(rawXmlExpression.expression);
715 }
687 } 716 }
688 } 717 }
689 } 718 }
690 719
691 /** 720 /**
692 * Relationship between an element and a location. Relationships are identified by a globally unique 721 * Relationship between an element and a location. Relationships are identified by a globally unique
693 * identifier. 722 * identifier.
694 * 723 *
695 * @coverage dart.engine.index 724 * @coverage dart.engine.index
696 */ 725 */
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 799
771 String get statistics => _store.statistics; 800 String get statistics => _store.statistics;
772 801
773 void indexHtmlUnit(AnalysisContext context, ht.HtmlUnit unit) { 802 void indexHtmlUnit(AnalysisContext context, ht.HtmlUnit unit) {
774 if (unit == null) { 803 if (unit == null) {
775 return; 804 return;
776 } 805 }
777 if (unit.element == null) { 806 if (unit.element == null) {
778 return; 807 return;
779 } 808 }
780 if (unit.compilationUnitElement == null) { 809 if (unit.element.angularCompilationUnit == null) {
781 return; 810 return;
782 } 811 }
783 _queue.enqueue(new IndexHtmlUnitOperation(_store, context, unit)); 812 _queue.enqueue(new IndexHtmlUnitOperation(_store, context, unit));
784 } 813 }
785 814
786 void indexUnit(AnalysisContext context, CompilationUnit unit) { 815 void indexUnit(AnalysisContext context, CompilationUnit unit) {
787 if (unit == null) { 816 if (unit == null) {
788 return; 817 return;
789 } 818 }
790 if (unit.element == null) { 819 if (unit.element == null) {
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 _store.recordRelationship(element, IndexConstants.IS_REFERENCED_BY, crea teLocation(identifier)); 1251 _store.recordRelationship(element, IndexConstants.IS_REFERENCED_BY, crea teLocation(identifier));
1223 return; 1252 return;
1224 } 1253 }
1225 } 1254 }
1226 // index as a normal Dart expression 1255 // index as a normal Dart expression
1227 expression.accept(_indexContributor); 1256 expression.accept(_indexContributor);
1228 } 1257 }
1229 1258
1230 Object visitHtmlUnit(ht.HtmlUnit node) { 1259 Object visitHtmlUnit(ht.HtmlUnit node) {
1231 _htmlUnitElement = node.element; 1260 _htmlUnitElement = node.element;
1232 CompilationUnitElement dartUnitElement = node.compilationUnitElement; 1261 CompilationUnitElement dartUnitElement = _htmlUnitElement.angularCompilation Unit;
1233 _indexContributor.enterScope(dartUnitElement); 1262 _indexContributor.enterScope(dartUnitElement);
1234 return super.visitHtmlUnit(node); 1263 return super.visitHtmlUnit(node);
1235 } 1264 }
1236 1265
1237 Object visitXmlAttributeNode(ht.XmlAttributeNode node) { 1266 Object visitXmlAttributeNode(ht.XmlAttributeNode node) {
1238 Element element = node.element; 1267 Element element = node.element;
1239 if (element != null) { 1268 if (element != null) {
1240 ht.Token nameToken = node.nameToken; 1269 ht.Token nameToken = node.nameToken;
1241 Location location = createLocation2(nameToken); 1270 Location location = createLocation2(nameToken);
1242 _store.recordRelationship(element, IndexConstants.IS_REFERENCED_BY, locati on); 1271 _store.recordRelationship(element, IndexConstants.IS_REFERENCED_BY, locati on);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 * the library are not parts of the library anymore, and clears their informat ion. 1414 * the library are not parts of the library anymore, and clears their informat ion.
1386 * 1415 *
1387 * @param the [AnalysisContext] in which unit being indexed 1416 * @param the [AnalysisContext] in which unit being indexed
1388 * @param unitElement the element of the unit being indexed 1417 * @param unitElement the element of the unit being indexed
1389 * @return `true` the given [AnalysisContext] is active, or `false` if it was 1418 * @return `true` the given [AnalysisContext] is active, or `false` if it was
1390 * removed before, so no any unit may be indexed with it 1419 * removed before, so no any unit may be indexed with it
1391 */ 1420 */
1392 bool aboutToIndex(AnalysisContext context, CompilationUnitElement unitElement) ; 1421 bool aboutToIndex(AnalysisContext context, CompilationUnitElement unitElement) ;
1393 1422
1394 /** 1423 /**
1395 * Notifies the index store that we are going to index the given [Source]. 1424 * Notifies the index store that we are going to index the given [HtmlElement] .
1396 *
1397 * This method should be used only for a [Source] that cannot be a part of mul tiple
1398 * libraries. Otherwise [aboutToIndex] should be
1399 * used.
1400 * 1425 *
1401 * @param the [AnalysisContext] in which unit being indexed 1426 * @param the [AnalysisContext] in which unit being indexed
1402 * @param source the [Source] being indexed 1427 * @param htmlElement the [HtmlElement] being indexed
1403 * @return `true` the given [AnalysisContext] is active, or `false` if it was 1428 * @return `true` the given [AnalysisContext] is active, or `false` if it was
1404 * removed before, so no any unit may be indexed with it 1429 * removed before, so no any unit may be indexed with it
1405 */ 1430 */
1406 bool aboutToIndex2(AnalysisContext context, Source source); 1431 bool aboutToIndex2(AnalysisContext context, HtmlElement htmlElement);
1407 1432
1408 /** 1433 /**
1409 * Return the locations of the elements that have the given relationship with the given element. 1434 * Return the locations of the elements that have the given relationship with the given element.
1410 * For example, if the element represents a method and the relationship is the is-referenced-by 1435 * For example, if the element represents a method and the relationship is the is-referenced-by
1411 * relationship, then the returned locations will be all of the places where t he method is 1436 * relationship, then the returned locations will be all of the places where t he method is
1412 * invoked. 1437 * invoked.
1413 * 1438 *
1414 * @param element the the element that has the relationship with the locations to be returned 1439 * @param element the the element that has the relationship with the locations to be returned
1415 * @param relationship the [Relationship] between the given element and the lo cations to be 1440 * @param relationship the [Relationship] between the given element and the lo cations to be
1416 * returned 1441 * returned
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2649 /** 2674 /**
2650 * @return the [Source] to be indexed. 2675 * @return the [Source] to be indexed.
2651 */ 2676 */
2652 Source get source => _source; 2677 Source get source => _source;
2653 2678
2654 bool get isQuery => false; 2679 bool get isQuery => false;
2655 2680
2656 void performOperation() { 2681 void performOperation() {
2657 { 2682 {
2658 try { 2683 try {
2659 bool mayIndex = _indexStore.aboutToIndex2(_context, _source); 2684 bool mayIndex = _indexStore.aboutToIndex2(_context, _htmlElement);
2660 if (!mayIndex) { 2685 if (!mayIndex) {
2661 return; 2686 return;
2662 } 2687 }
2663 AngularHtmlIndexContributor contributor = new AngularHtmlIndexContributo r(_indexStore); 2688 AngularHtmlIndexContributor contributor = new AngularHtmlIndexContributo r(_indexStore);
2664 unit.accept(contributor); 2689 unit.accept(contributor);
2665 } catch (exception) { 2690 } catch (exception) {
2666 AnalysisEngine.instance.logger.logError2("Could not index ${unit.element .location}", exception); 2691 AnalysisEngine.instance.logger.logError2("Could not index ${unit.element .location}", exception);
2667 } 2692 }
2668 } 2693 }
2669 } 2694 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2797 * element are available. For example, if the element is a field and the relat ionship is the 2822 * element are available. For example, if the element is a field and the relat ionship is the
2798 * is-referenced-by relationship, then this method will be invoked with each l ocation at which the 2823 * is-referenced-by relationship, then this method will be invoked with each l ocation at which the
2799 * field is referenced. 2824 * field is referenced.
2800 * 2825 *
2801 * @param element the [Element] that has the relationship with the locations 2826 * @param element the [Element] that has the relationship with the locations
2802 * @param relationship the relationship between the given element and the loca tions 2827 * @param relationship the relationship between the given element and the loca tions
2803 * @param locations the locations that were found 2828 * @param locations the locations that were found
2804 */ 2829 */
2805 void hasRelationships(Element element, Relationship relationship, List<Locatio n> locations); 2830 void hasRelationships(Element element, Relationship relationship, List<Locatio n> locations);
2806 } 2831 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698