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 // 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; |
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 * The relationship used to indicate that an element (the left-operand) is inv
oked at a specific | 1205 * The relationship used to indicate that an element (the left-operand) is inv
oked at a specific |
1206 * location (the right operand). This is used for methods. | 1206 * location (the right operand). This is used for methods. |
1207 */ | 1207 */ |
1208 static final Relationship IS_INVOKED_BY_QUALIFIED = Relationship.getRelationsh
ip("is-invoked-by-qualified"); | 1208 static final Relationship IS_INVOKED_BY_QUALIFIED = Relationship.getRelationsh
ip("is-invoked-by-qualified"); |
1209 | 1209 |
1210 /** | 1210 /** |
1211 * The relationship used to indicate that an element (the left-operand) is inv
oked at a specific | 1211 * The relationship used to indicate that an element (the left-operand) is inv
oked at a specific |
1212 * location (the right operand). This is used for methods. | 1212 * location (the right operand). This is used for methods. |
1213 */ | 1213 */ |
1214 static final Relationship IS_INVOKED_BY_UNQUALIFIED = Relationship.getRelation
ship("is-invoked-by-unqualified"); | 1214 static final Relationship IS_INVOKED_BY_UNQUALIFIED = Relationship.getRelation
ship("is-invoked-by-unqualified"); |
| 1215 |
| 1216 /** |
| 1217 * Reference to some [AngularElement]. |
| 1218 */ |
| 1219 static final Relationship ANGULAR_REFERENCE = Relationship.getRelationship("an
gular-reference"); |
| 1220 |
| 1221 /** |
| 1222 * Reference to some closing tag of an XML element. |
| 1223 */ |
| 1224 static final Relationship ANGULAR_CLOSING_TAG_REFERENCE = Relationship.getRela
tionship("angular-closing-tag-reference"); |
1215 } | 1225 } |
1216 | 1226 |
1217 /** | 1227 /** |
1218 * Visits resolved [HtmlUnit] and adds relationships into [IndexStore]. | 1228 * Visits resolved [HtmlUnit] and adds relationships into [IndexStore]. |
1219 * | 1229 * |
1220 * @coverage dart.engine.index | 1230 * @coverage dart.engine.index |
1221 */ | 1231 */ |
1222 class AngularHtmlIndexContributor extends ExpressionVisitor { | 1232 class AngularHtmlIndexContributor extends ExpressionVisitor { |
1223 /** | 1233 /** |
1224 * The [IndexStore] to record relations into. | 1234 * The [IndexStore] to record relations into. |
(...skipping 16 matching lines...) Expand all Loading... |
1241 this._store = store; | 1251 this._store = store; |
1242 _indexContributor = new IndexContributor_AngularHtmlIndexContributor(store,
this); | 1252 _indexContributor = new IndexContributor_AngularHtmlIndexContributor(store,
this); |
1243 } | 1253 } |
1244 | 1254 |
1245 void visitExpression(Expression expression) { | 1255 void visitExpression(Expression expression) { |
1246 // NgFilter | 1256 // NgFilter |
1247 if (expression is SimpleIdentifier) { | 1257 if (expression is SimpleIdentifier) { |
1248 SimpleIdentifier identifier = expression; | 1258 SimpleIdentifier identifier = expression; |
1249 Element element = identifier.bestElement; | 1259 Element element = identifier.bestElement; |
1250 if (element is AngularElement) { | 1260 if (element is AngularElement) { |
1251 _store.recordRelationship(element, IndexConstants.IS_REFERENCED_BY, crea
teLocation(identifier)); | 1261 _store.recordRelationship(element, IndexConstants.ANGULAR_REFERENCE, cre
ateLocation(identifier)); |
1252 return; | 1262 return; |
1253 } | 1263 } |
1254 } | 1264 } |
1255 // index as a normal Dart expression | 1265 // index as a normal Dart expression |
1256 expression.accept(_indexContributor); | 1266 expression.accept(_indexContributor); |
1257 } | 1267 } |
1258 | 1268 |
1259 Object visitHtmlUnit(ht.HtmlUnit node) { | 1269 Object visitHtmlUnit(ht.HtmlUnit node) { |
1260 _htmlUnitElement = node.element; | 1270 _htmlUnitElement = node.element; |
1261 CompilationUnitElement dartUnitElement = _htmlUnitElement.angularCompilation
Unit; | 1271 CompilationUnitElement dartUnitElement = _htmlUnitElement.angularCompilation
Unit; |
1262 _indexContributor.enterScope(dartUnitElement); | 1272 _indexContributor.enterScope(dartUnitElement); |
1263 return super.visitHtmlUnit(node); | 1273 return super.visitHtmlUnit(node); |
1264 } | 1274 } |
1265 | 1275 |
1266 Object visitXmlAttributeNode(ht.XmlAttributeNode node) { | 1276 Object visitXmlAttributeNode(ht.XmlAttributeNode node) { |
1267 Element element = node.element; | 1277 Element element = node.element; |
1268 if (element != null) { | 1278 if (element != null) { |
1269 ht.Token nameToken = node.nameToken; | 1279 ht.Token nameToken = node.nameToken; |
1270 Location location = createLocation2(nameToken); | 1280 Location location = createLocation2(nameToken); |
1271 _store.recordRelationship(element, IndexConstants.IS_REFERENCED_BY, locati
on); | 1281 _store.recordRelationship(element, IndexConstants.ANGULAR_REFERENCE, locat
ion); |
1272 } | 1282 } |
1273 return super.visitXmlAttributeNode(node); | 1283 return super.visitXmlAttributeNode(node); |
1274 } | 1284 } |
1275 | 1285 |
1276 Object visitXmlTagNode(ht.XmlTagNode node) { | 1286 Object visitXmlTagNode(ht.XmlTagNode node) { |
1277 Element element = node.element; | 1287 Element element = node.element; |
1278 if (element != null) { | 1288 if (element != null) { |
1279 ht.Token tagToken = node.tagToken; | 1289 // tag |
1280 Location location = createLocation2(tagToken); | 1290 { |
1281 _store.recordRelationship(element, IndexConstants.IS_REFERENCED_BY, locati
on); | 1291 ht.Token tagToken = node.tagToken; |
| 1292 Location location = createLocation2(tagToken); |
| 1293 _store.recordRelationship(element, IndexConstants.ANGULAR_REFERENCE, loc
ation); |
| 1294 } |
| 1295 // maybe add closing tag range |
| 1296 ht.Token closingTag = node.closingTag; |
| 1297 if (closingTag != null) { |
| 1298 Location location = createLocation2(closingTag); |
| 1299 _store.recordRelationship(element, IndexConstants.ANGULAR_CLOSING_TAG_RE
FERENCE, location); |
| 1300 } |
1282 } | 1301 } |
1283 return super.visitXmlTagNode(node); | 1302 return super.visitXmlTagNode(node); |
1284 } | 1303 } |
1285 | 1304 |
1286 Location createLocation(SimpleIdentifier identifier) => new Location(_htmlUnit
Element, identifier.offset, identifier.length); | 1305 Location createLocation(SimpleIdentifier identifier) => new Location(_htmlUnit
Element, identifier.offset, identifier.length); |
1287 | 1306 |
1288 Location createLocation2(ht.Token token) => new Location(_htmlUnitElement, tok
en.offset, token.length); | 1307 Location createLocation2(ht.Token token) => new Location(_htmlUnitElement, tok
en.offset, token.length); |
1289 } | 1308 } |
1290 | 1309 |
1291 class IndexContributor_AngularHtmlIndexContributor extends IndexContributor { | 1310 class IndexContributor_AngularHtmlIndexContributor extends IndexContributor { |
1292 final AngularHtmlIndexContributor AngularHtmlIndexContributor_this; | 1311 final AngularHtmlIndexContributor AngularHtmlIndexContributor_this; |
1293 | 1312 |
1294 IndexContributor_AngularHtmlIndexContributor(IndexStore arg0, this.AngularHtml
IndexContributor_this) : super(arg0); | 1313 IndexContributor_AngularHtmlIndexContributor(IndexStore arg0, this.AngularHtml
IndexContributor_this) : super(arg0); |
1295 | 1314 |
1296 Element peekElement() => AngularHtmlIndexContributor_this._htmlUnitElement; | 1315 Element peekElement() => AngularHtmlIndexContributor_this._htmlUnitElement; |
1297 | 1316 |
1298 void recordRelationship(Element element, Relationship relationship, Location l
ocation) { | 1317 void recordRelationship(Element element, Relationship relationship, Location l
ocation) { |
1299 AngularElement angularElement = AngularHtmlUnitResolver.getAngularElement(el
ement); | 1318 AngularElement angularElement = AngularHtmlUnitResolver.getAngularElement(el
ement); |
1300 if (angularElement != null) { | 1319 if (angularElement != null) { |
1301 element = angularElement; | 1320 element = angularElement; |
1302 relationship = IndexConstants.IS_REFERENCED_BY; | 1321 relationship = IndexConstants.ANGULAR_REFERENCE; |
1303 } | 1322 } |
1304 super.recordRelationship(element, relationship, location); | 1323 super.recordRelationship(element, relationship, location); |
1305 } | 1324 } |
1306 } | 1325 } |
1307 | 1326 |
1308 /** | 1327 /** |
1309 * The interface [Index] defines the behavior of objects that maintain an index
storing | 1328 * The interface [Index] defines the behavior of objects that maintain an index
storing |
1310 * [Relationship] between [Element]. All of the operations | 1329 * [Relationship] between [Element]. All of the operations |
1311 * defined on the index are asynchronous, and results, when there are any, are p
rovided through a | 1330 * defined on the index are asynchronous, and results, when there are any, are p
rovided through a |
1312 * callback. | 1331 * callback. |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 static IndexContributor_ImportElementInfo getImportElementInfo(SimpleIdentifie
r prefixNode) { | 1576 static IndexContributor_ImportElementInfo getImportElementInfo(SimpleIdentifie
r prefixNode) { |
1558 IndexContributor_ImportElementInfo info = new IndexContributor_ImportElement
Info(); | 1577 IndexContributor_ImportElementInfo info = new IndexContributor_ImportElement
Info(); |
1559 // prepare environment | 1578 // prepare environment |
1560 ASTNode parent = prefixNode.parent; | 1579 ASTNode parent = prefixNode.parent; |
1561 CompilationUnit unit = prefixNode.getAncestor(CompilationUnit); | 1580 CompilationUnit unit = prefixNode.getAncestor(CompilationUnit); |
1562 LibraryElement libraryElement = unit.element.library; | 1581 LibraryElement libraryElement = unit.element.library; |
1563 // prepare used element | 1582 // prepare used element |
1564 Element usedElement = null; | 1583 Element usedElement = null; |
1565 if (parent is PrefixedIdentifier) { | 1584 if (parent is PrefixedIdentifier) { |
1566 PrefixedIdentifier prefixed = parent; | 1585 PrefixedIdentifier prefixed = parent; |
1567 usedElement = prefixed.staticElement; | 1586 if (identical(prefixed.prefix, prefixNode)) { |
1568 info._periodEnd = prefixed.period.end; | 1587 usedElement = prefixed.staticElement; |
| 1588 info._periodEnd = prefixed.period.end; |
| 1589 } |
1569 } | 1590 } |
1570 if (parent is MethodInvocation) { | 1591 if (parent is MethodInvocation) { |
1571 MethodInvocation invocation = parent; | 1592 MethodInvocation invocation = parent; |
1572 usedElement = invocation.methodName.staticElement; | 1593 if (identical(invocation.target, prefixNode)) { |
1573 info._periodEnd = invocation.period.end; | 1594 usedElement = invocation.methodName.staticElement; |
| 1595 info._periodEnd = invocation.period.end; |
| 1596 } |
1574 } | 1597 } |
1575 // we need used Element | 1598 // we need used Element |
1576 if (usedElement == null) { | 1599 if (usedElement == null) { |
1577 return null; | 1600 return null; |
1578 } | 1601 } |
1579 // find ImportElement | 1602 // find ImportElement |
1580 String prefix = prefixNode.name; | 1603 String prefix = prefixNode.name; |
1581 Map<ImportElement, Set<Element>> importElementsMap = {}; | 1604 Map<ImportElement, Set<Element>> importElementsMap = {}; |
1582 info._element = getImportElement2(libraryElement, prefix, usedElement, impor
tElementsMap); | 1605 info._element = getImportElement2(libraryElement, prefix, usedElement, impor
tElementsMap); |
1583 if (info._element == null) { | 1606 if (info._element == null) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1734 if (parent is AssignmentExpression) { | 1757 if (parent is AssignmentExpression) { |
1735 AssignmentExpression assignment = parent as AssignmentExpression; | 1758 AssignmentExpression assignment = parent as AssignmentExpression; |
1736 Expression rhs = assignment.rightHandSide; | 1759 Expression rhs = assignment.rightHandSide; |
1737 location = getLocationWithExpressionType(location, rhs); | 1760 location = getLocationWithExpressionType(location, rhs); |
1738 } | 1761 } |
1739 // done | 1762 // done |
1740 return location; | 1763 return location; |
1741 } | 1764 } |
1742 | 1765 |
1743 /** | 1766 /** |
| 1767 * @return `true` if given "node" is part of an import [Combinator]. |
| 1768 */ |
| 1769 static bool isIdentifierInImportCombinator(SimpleIdentifier node) { |
| 1770 ASTNode parent = node.parent; |
| 1771 return parent is Combinator; |
| 1772 } |
| 1773 |
| 1774 /** |
1744 * @return `true` if given "node" is part of [PrefixedIdentifier] "prefix.node
". | 1775 * @return `true` if given "node" is part of [PrefixedIdentifier] "prefix.node
". |
1745 */ | 1776 */ |
1746 static bool isIdentifierInPrefixedIdentifier(SimpleIdentifier node) { | 1777 static bool isIdentifierInPrefixedIdentifier(SimpleIdentifier node) { |
1747 ASTNode parent = node.parent; | 1778 ASTNode parent = node.parent; |
1748 return parent is PrefixedIdentifier && identical(parent.identifier, node); | 1779 return parent is PrefixedIdentifier && identical(parent.identifier, node); |
1749 } | 1780 } |
1750 | 1781 |
1751 /** | 1782 /** |
1752 * @return `true` if given [SimpleIdentifier] is "name" part of prefixed ident
ifier or | 1783 * @return `true` if given [SimpleIdentifier] is "name" part of prefixed ident
ifier or |
1753 * method invocation. | 1784 * method invocation. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1916 enterScope(element); | 1947 enterScope(element); |
1917 try { | 1948 try { |
1918 return super.visitConstructorDeclaration(node); | 1949 return super.visitConstructorDeclaration(node); |
1919 } finally { | 1950 } finally { |
1920 exitScope(); | 1951 exitScope(); |
1921 } | 1952 } |
1922 } | 1953 } |
1923 | 1954 |
1924 Object visitConstructorName(ConstructorName node) { | 1955 Object visitConstructorName(ConstructorName node) { |
1925 ConstructorElement element = node.staticElement; | 1956 ConstructorElement element = node.staticElement; |
| 1957 // in 'class B = A;' actually A constructors are invoked |
| 1958 if (element != null && element.isSynthetic && element.redirectedConstructor
!= null) { |
| 1959 element = element.redirectedConstructor; |
| 1960 } |
| 1961 // prepare location |
1926 Location location; | 1962 Location location; |
1927 if (node.name != null) { | 1963 if (node.name != null) { |
1928 int start = node.period.offset; | 1964 int start = node.period.offset; |
1929 int end = node.name.end; | 1965 int end = node.name.end; |
1930 location = createLocation4(start, end - start); | 1966 location = createLocation4(start, end - start); |
1931 } else { | 1967 } else { |
1932 int start = node.type.end; | 1968 int start = node.type.end; |
1933 location = createLocation4(start, 0); | 1969 location = createLocation4(start, 0); |
1934 } | 1970 } |
| 1971 // record relationship |
1935 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 1972 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); |
1936 return super.visitConstructorName(node); | 1973 return super.visitConstructorName(node); |
1937 } | 1974 } |
1938 | 1975 |
1939 Object visitExportDirective(ExportDirective node) { | 1976 Object visitExportDirective(ExportDirective node) { |
1940 ExportElement element = node.element as ExportElement; | 1977 ExportElement element = node.element as ExportElement; |
1941 if (element != null) { | 1978 if (element != null) { |
1942 LibraryElement expLibrary = element.exportedLibrary; | 1979 LibraryElement expLibrary = element.exportedLibrary; |
1943 recordLibraryReference(node, expLibrary); | 1980 recordLibraryReference(node, expLibrary); |
1944 } | 1981 } |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2233 Location location = createLocation(element); | 2270 Location location = createLocation(element); |
2234 recordRelationship(_libraryElement, relationship, location); | 2271 recordRelationship(_libraryElement, relationship, location); |
2235 recordRelationship(IndexConstants.UNIVERSE, relationship, location); | 2272 recordRelationship(IndexConstants.UNIVERSE, relationship, location); |
2236 } | 2273 } |
2237 | 2274 |
2238 /** | 2275 /** |
2239 * Records [ImportElement] reference if given [SimpleIdentifier] references so
me | 2276 * Records [ImportElement] reference if given [SimpleIdentifier] references so
me |
2240 * top-level element and not qualified with import prefix. | 2277 * top-level element and not qualified with import prefix. |
2241 */ | 2278 */ |
2242 void recordImportElementReferenceWithoutPrefix(SimpleIdentifier node) { | 2279 void recordImportElementReferenceWithoutPrefix(SimpleIdentifier node) { |
| 2280 if (isIdentifierInImportCombinator(node)) { |
| 2281 return; |
| 2282 } |
2243 if (isIdentifierInPrefixedIdentifier(node)) { | 2283 if (isIdentifierInPrefixedIdentifier(node)) { |
2244 return; | 2284 return; |
2245 } | 2285 } |
2246 Element element = node.staticElement; | 2286 Element element = node.staticElement; |
2247 ImportElement importElement = getImportElement2(_libraryElement, null, eleme
nt, _importElementsMap); | 2287 ImportElement importElement = getImportElement2(_libraryElement, null, eleme
nt, _importElementsMap); |
2248 if (importElement != null) { | 2288 if (importElement != null) { |
2249 Location location = createLocation4(node.offset, 0); | 2289 Location location = createLocation4(node.offset, 0); |
2250 recordRelationship(importElement, IndexConstants.IS_REFERENCED_BY, locatio
n); | 2290 recordRelationship(importElement, IndexConstants.IS_REFERENCED_BY, locatio
n); |
2251 } | 2291 } |
2252 } | 2292 } |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2552 Object visitCompilationUnitMember(CompilationUnitMember node) => null; | 2592 Object visitCompilationUnitMember(CompilationUnitMember node) => null; |
2553 | 2593 |
2554 void indexComponent(AngularComponentElement component) { | 2594 void indexComponent(AngularComponentElement component) { |
2555 indexProperties(component.properties); | 2595 indexProperties(component.properties); |
2556 } | 2596 } |
2557 | 2597 |
2558 void indexDirective(AngularDirectiveElement directive) { | 2598 void indexDirective(AngularDirectiveElement directive) { |
2559 indexProperties(directive.properties); | 2599 indexProperties(directive.properties); |
2560 } | 2600 } |
2561 | 2601 |
| 2602 /** |
| 2603 * Index [FieldElement] references from [AngularPropertyElement]s. |
| 2604 */ |
2562 void indexProperties(List<AngularPropertyElement> properties) { | 2605 void indexProperties(List<AngularPropertyElement> properties) { |
2563 for (AngularPropertyElement property in properties) { | 2606 for (AngularPropertyElement property in properties) { |
2564 FieldElement field = property.field; | 2607 FieldElement field = property.field; |
2565 if (field != null) { | 2608 if (field != null) { |
2566 int offset = property.fieldNameOffset; | 2609 int offset = property.fieldNameOffset; |
| 2610 if (offset == -1) { |
| 2611 continue; |
| 2612 } |
2567 int length = field.name.length; | 2613 int length = field.name.length; |
2568 Location location = new Location(property, offset, length); | 2614 Location location = new Location(property, offset, length); |
2569 // getter reference | 2615 // getter reference |
2570 if (property.propertyKind.callsGetter()) { | 2616 if (property.propertyKind.callsGetter()) { |
2571 PropertyAccessorElement getter = field.getter; | 2617 PropertyAccessorElement getter = field.getter; |
2572 if (getter != null) { | 2618 if (getter != null) { |
2573 _store.recordRelationship(getter, IndexConstants.IS_REFERENCED_BY_QU
ALIFIED, location); | 2619 _store.recordRelationship(getter, IndexConstants.IS_REFERENCED_BY_QU
ALIFIED, location); |
2574 } | 2620 } |
2575 } | 2621 } |
2576 // setter reference | 2622 // setter reference |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2822 * element are available. For example, if the element is a field and the relat
ionship is the | 2868 * element are available. For example, if the element is a field and the relat
ionship is the |
2823 * is-referenced-by relationship, then this method will be invoked with each l
ocation at which the | 2869 * is-referenced-by relationship, then this method will be invoked with each l
ocation at which the |
2824 * field is referenced. | 2870 * field is referenced. |
2825 * | 2871 * |
2826 * @param element the [Element] that has the relationship with the locations | 2872 * @param element the [Element] that has the relationship with the locations |
2827 * @param relationship the relationship between the given element and the loca
tions | 2873 * @param relationship the relationship between the given element and the loca
tions |
2828 * @param locations the locations that were found | 2874 * @param locations the locations that were found |
2829 */ | 2875 */ |
2830 void hasRelationships(Element element, Relationship relationship, List<Locatio
n> locations); | 2876 void hasRelationships(Element element, Relationship relationship, List<Locatio
n> locations); |
2831 } | 2877 } |
OLD | NEW |