| OLD | NEW | 
|    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 services.src.index.index_contributor; |    5 library services.src.index.index_contributor; | 
|    6  |    6  | 
|    7 import 'dart:collection' show Queue; |    7 import 'dart:collection' show Queue; | 
|    8  |    8  | 
|    9 import 'package:analysis_server/plugin/index/index_core.dart'; |    9 import 'package:analysis_server/plugin/index/index_core.dart'; | 
|   10 import 'package:analysis_server/src/services/correction/namespace.dart'; |   10 import 'package:analysis_server/src/services/correction/namespace.dart'; | 
|   11 import 'package:analysis_server/src/services/index/index.dart'; |   11 import 'package:analysis_server/src/services/index/index.dart'; | 
|   12 import 'package:analysis_server/src/services/index/index_store.dart'; |   12 import 'package:analysis_server/src/services/index/index_store.dart'; | 
|   13 import 'package:analysis_server/src/services/index/indexable_element.dart'; |   13 import 'package:analysis_server/src/services/index/indexable_element.dart'; | 
 |   14 import 'package:analysis_server/src/services/index/indexable_file.dart'; | 
|   14 import 'package:analyzer/src/generated/ast.dart'; |   15 import 'package:analyzer/src/generated/ast.dart'; | 
|   15 import 'package:analyzer/src/generated/element.dart'; |   16 import 'package:analyzer/src/generated/element.dart'; | 
|   16 import 'package:analyzer/src/generated/engine.dart'; |   17 import 'package:analyzer/src/generated/engine.dart'; | 
|   17 import 'package:analyzer/src/generated/java_engine.dart'; |   18 import 'package:analyzer/src/generated/java_engine.dart'; | 
|   18 import 'package:analyzer/src/generated/scanner.dart'; |   19 import 'package:analyzer/src/generated/scanner.dart'; | 
|   19 import 'package:analyzer/src/generated/source.dart'; |   20 import 'package:analyzer/src/generated/source.dart'; | 
|   20  |   21  | 
|   21 /** |   22 /** | 
|   22  * An [IndexContributor] that contributes relationships for Dart files. |   23  * An [IndexContributor] that contributes relationships for Dart files. | 
|   23  */ |   24  */ | 
|   24 class DartIndexContributor extends IndexContributor { |   25 class DartIndexContributor extends IndexContributor { | 
|   25   @override |   26   @override | 
|   26   void contributeTo(IndexStore store, AnalysisContext context, Object object) { |   27   void contributeTo(IndexStore store, AnalysisContext context, Object object) { | 
|   27     if (store is InternalIndexStore && object is CompilationUnit) { |   28     if (store is InternalIndexStore && object is CompilationUnit) { | 
|   28       _IndexContributor contributor = new _IndexContributor(store); |   29       _IndexContributor contributor = new _IndexContributor(store); | 
|   29       object.accept(contributor); |   30       object.accept(contributor); | 
|   30     } |   31     } | 
|   31   } |   32   } | 
|   32 } |   33 } | 
|   33  |   34  | 
|   34 /** |   35 /** | 
|   35  * Visits a resolved AST and adds relationships into [InternalIndexStore]. |   36  * Visits a resolved AST and adds relationships into [InternalIndexStore]. | 
|   36  */ |   37  */ | 
|   37 class _IndexContributor extends GeneralizingAstVisitor { |   38 class _IndexContributor extends GeneralizingAstVisitor { | 
|   38   final InternalIndexStore _store; |   39   final InternalIndexStore _store; | 
|   39  |   40  | 
 |   41   CompilationUnitElement _unitElement; | 
|   40   LibraryElement _libraryElement; |   42   LibraryElement _libraryElement; | 
|   41  |   43  | 
|   42   Map<ImportElement, Set<Element>> _importElementsMap = {}; |   44   Map<ImportElement, Set<Element>> _importElementsMap = {}; | 
|   43  |   45  | 
|   44   /** |   46   /** | 
|   45    * A stack whose top element (the element with the largest index) is an |   47    * A stack whose top element (the element with the largest index) is an | 
|   46    * element representing the inner-most enclosing scope. |   48    * element representing the inner-most enclosing scope. | 
|   47    */ |   49    */ | 
|   48   Queue<Element> _elementStack = new Queue(); |   50   Queue<Element> _elementStack = new Queue(); | 
|   49  |   51  | 
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  179         } |  181         } | 
|  180       } |  182       } | 
|  181       super.visitClassTypeAlias(node); |  183       super.visitClassTypeAlias(node); | 
|  182     } finally { |  184     } finally { | 
|  183       _exitScope(); |  185       _exitScope(); | 
|  184     } |  186     } | 
|  185   } |  187   } | 
|  186  |  188  | 
|  187   @override |  189   @override | 
|  188   visitCompilationUnit(CompilationUnit node) { |  190   visitCompilationUnit(CompilationUnit node) { | 
|  189     CompilationUnitElement unitElement = node.element; |  191     _unitElement = node.element; | 
|  190     if (unitElement != null) { |  192     if (_unitElement != null) { | 
|  191       _elementStack.add(unitElement); |  193       _elementStack.add(_unitElement); | 
|  192       _libraryElement = unitElement.enclosingElement; |  194       _libraryElement = _unitElement.enclosingElement; | 
|  193       if (_libraryElement != null) { |  195       if (_libraryElement != null) { | 
|  194         super.visitCompilationUnit(node); |  196         super.visitCompilationUnit(node); | 
|  195       } |  197       } | 
|  196     } |  198     } | 
|  197   } |  199   } | 
|  198  |  200  | 
|  199   @override |  201   @override | 
|  200   visitConstructorDeclaration(ConstructorDeclaration node) { |  202   visitConstructorDeclaration(ConstructorDeclaration node) { | 
|  201     ConstructorElement element = node.element; |  203     ConstructorElement element = node.element; | 
|  202     enterScope(element); |  204     enterScope(element); | 
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  272     } |  274     } | 
|  273   } |  275   } | 
|  274  |  276  | 
|  275   @override |  277   @override | 
|  276   visitExportDirective(ExportDirective node) { |  278   visitExportDirective(ExportDirective node) { | 
|  277     ExportElement element = node.element; |  279     ExportElement element = node.element; | 
|  278     if (element != null) { |  280     if (element != null) { | 
|  279       LibraryElement expLibrary = element.exportedLibrary; |  281       LibraryElement expLibrary = element.exportedLibrary; | 
|  280       _recordLibraryReference(node, expLibrary); |  282       _recordLibraryReference(node, expLibrary); | 
|  281     } |  283     } | 
 |  284     _recordUriFileReference(node); | 
|  282     super.visitExportDirective(node); |  285     super.visitExportDirective(node); | 
|  283   } |  286   } | 
|  284  |  287  | 
|  285   @override |  288   @override | 
|  286   visitFormalParameter(FormalParameter node) { |  289   visitFormalParameter(FormalParameter node) { | 
|  287     ParameterElement element = node.element; |  290     ParameterElement element = node.element; | 
|  288     enterScope(element); |  291     enterScope(element); | 
|  289     try { |  292     try { | 
|  290       super.visitFormalParameter(node); |  293       super.visitFormalParameter(node); | 
|  291     } finally { |  294     } finally { | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|  312     super.visitFunctionTypeAlias(node); |  315     super.visitFunctionTypeAlias(node); | 
|  313   } |  316   } | 
|  314  |  317  | 
|  315   @override |  318   @override | 
|  316   visitImportDirective(ImportDirective node) { |  319   visitImportDirective(ImportDirective node) { | 
|  317     ImportElement element = node.element; |  320     ImportElement element = node.element; | 
|  318     if (element != null) { |  321     if (element != null) { | 
|  319       LibraryElement impLibrary = element.importedLibrary; |  322       LibraryElement impLibrary = element.importedLibrary; | 
|  320       _recordLibraryReference(node, impLibrary); |  323       _recordLibraryReference(node, impLibrary); | 
|  321     } |  324     } | 
 |  325     _recordUriFileReference(node); | 
|  322     super.visitImportDirective(node); |  326     super.visitImportDirective(node); | 
|  323   } |  327   } | 
|  324  |  328  | 
|  325   @override |  329   @override | 
|  326   visitIndexExpression(IndexExpression node) { |  330   visitIndexExpression(IndexExpression node) { | 
|  327     MethodElement element = node.bestElement; |  331     MethodElement element = node.bestElement; | 
|  328     if (element is MethodElement) { |  332     if (element is MethodElement) { | 
|  329       Token operator = node.leftBracket; |  333       Token operator = node.leftBracket; | 
|  330       LocationImpl location = |  334       LocationImpl location = | 
|  331           _createLocationForToken(operator, element != null); |  335           _createLocationForToken(operator, element != null); | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  368     _recordImportElementReferenceWithoutPrefix(name); |  372     _recordImportElementReferenceWithoutPrefix(name); | 
|  369     super.visitMethodInvocation(node); |  373     super.visitMethodInvocation(node); | 
|  370   } |  374   } | 
|  371  |  375  | 
|  372   @override |  376   @override | 
|  373   visitPartDirective(PartDirective node) { |  377   visitPartDirective(PartDirective node) { | 
|  374     Element element = node.element; |  378     Element element = node.element; | 
|  375     LocationImpl location = _createLocationForNode(node.uri); |  379     LocationImpl location = _createLocationForNode(node.uri); | 
|  376     recordRelationshipElement( |  380     recordRelationshipElement( | 
|  377         element, IndexConstants.IS_REFERENCED_BY, location); |  381         element, IndexConstants.IS_REFERENCED_BY, location); | 
 |  382     _recordUriFileReference(node); | 
|  378     super.visitPartDirective(node); |  383     super.visitPartDirective(node); | 
|  379   } |  384   } | 
|  380  |  385  | 
|  381   @override |  386   @override | 
|  382   visitPartOfDirective(PartOfDirective node) { |  387   visitPartOfDirective(PartOfDirective node) { | 
|  383     LocationImpl location = _createLocationForNode(node.libraryName); |  388     LocationImpl location = _createLocationForNode(node.libraryName); | 
|  384     recordRelationshipElement( |  389     recordRelationshipElement( | 
|  385         node.element, IndexConstants.IS_REFERENCED_BY, location); |  390         node.element, IndexConstants.IS_REFERENCED_BY, location); | 
|  386   } |  391   } | 
|  387  |  392  | 
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  783       IndexableElement indexable = new IndexableElement(element); |  788       IndexableElement indexable = new IndexableElement(element); | 
|  784       int offset = element.nameOffset; |  789       int offset = element.nameOffset; | 
|  785       int length = element.nameLength; |  790       int length = element.nameLength; | 
|  786       LocationImpl location = new LocationImpl(indexable, offset, length); |  791       LocationImpl location = new LocationImpl(indexable, offset, length); | 
|  787       recordRelationshipElement( |  792       recordRelationshipElement( | 
|  788           _libraryElement, IndexConstants.DEFINES, location); |  793           _libraryElement, IndexConstants.DEFINES, location); | 
|  789       _store.recordTopLevelDeclaration(element); |  794       _store.recordTopLevelDeclaration(element); | 
|  790     } |  795     } | 
|  791   } |  796   } | 
|  792  |  797  | 
 |  798   void _recordUriFileReference(UriBasedDirective directive) { | 
 |  799     Source source = directive.source; | 
 |  800     if (source != null) { | 
 |  801       LocationImpl location = new LocationImpl( | 
 |  802           new IndexableFile(_unitElement.source.fullName), | 
 |  803           directive.uri.offset, | 
 |  804           directive.uri.length); | 
 |  805       _store.recordRelationship(new IndexableFile(source.fullName), | 
 |  806           IndexConstants.IS_REFERENCED_BY, location); | 
 |  807     } | 
 |  808   } | 
 |  809  | 
|  793   /** |  810   /** | 
|  794    * If the given expression has resolved type, returns the new location with th
     is type. |  811    * If the given expression has resolved type, returns the new location with th
     is type. | 
|  795    * |  812    * | 
|  796    * [location] - the base location |  813    * [location] - the base location | 
|  797    * [expression] - the expression assigned at the given location |  814    * [expression] - the expression assigned at the given location | 
|  798    */ |  815    */ | 
|  799   static LocationImpl _getLocationWithExpressionType( |  816   static LocationImpl _getLocationWithExpressionType( | 
|  800       LocationImpl location, Expression expression) { |  817       LocationImpl location, Expression expression) { | 
|  801     if (expression != null) { |  818     if (expression != null) { | 
|  802       return new LocationWithData<DartType>(location, expression.bestType); |  819       return new LocationWithData<DartType>(location, expression.bestType); | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  813   } |  830   } | 
|  814  |  831  | 
|  815   /** |  832   /** | 
|  816    * @return `true` if given "node" is part of [PrefixedIdentifier] "prefix.node
     ". |  833    * @return `true` if given "node" is part of [PrefixedIdentifier] "prefix.node
     ". | 
|  817    */ |  834    */ | 
|  818   static bool _isIdentifierInPrefixedIdentifier(SimpleIdentifier node) { |  835   static bool _isIdentifierInPrefixedIdentifier(SimpleIdentifier node) { | 
|  819     AstNode parent = node.parent; |  836     AstNode parent = node.parent; | 
|  820     return parent is PrefixedIdentifier && parent.identifier == node; |  837     return parent is PrefixedIdentifier && parent.identifier == node; | 
|  821   } |  838   } | 
|  822 } |  839 } | 
| OLD | NEW |