| 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; |
| 11 import 'java_core.dart'; | 11 import 'java_core.dart'; |
| 12 import 'java_engine.dart'; |
| 12 import 'source.dart'; | 13 import 'source.dart'; |
| 13 import 'scanner.dart' show Token; | 14 import 'scanner.dart' show Token; |
| 14 import 'ast.dart'; | 15 import 'ast.dart'; |
| 15 import 'element.dart'; | 16 import 'element.dart'; |
| 16 import 'resolver.dart' show Namespace, NamespaceBuilder; | 17 import 'resolver.dart' show Namespace, NamespaceBuilder; |
| 17 import 'engine.dart' show AnalysisEngine, AnalysisContext, InstrumentedAnalysisC
ontextImpl; | 18 import 'engine.dart' show AnalysisEngine, AnalysisContext, InstrumentedAnalysisC
ontextImpl, AngularHtmlUnitResolver; |
| 18 import 'html.dart' as ht; | 19 import 'html.dart' as ht; |
| 19 | 20 |
| 20 /** | 21 /** |
| 21 * 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 |
| 22 * any data based on the content of a specified source. | 23 * any data based on the content of a specified source. |
| 23 * | 24 * |
| 24 * @coverage dart.engine.index | 25 * @coverage dart.engine.index |
| 25 */ | 26 */ |
| 26 class RemoveSourceOperation implements IndexOperation { | 27 class RemoveSourceOperation implements IndexOperation { |
| 27 /** | 28 /** |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 | 1203 |
| 1203 HtmlElement _htmlUnitElement; | 1204 HtmlElement _htmlUnitElement; |
| 1204 | 1205 |
| 1205 /** | 1206 /** |
| 1206 * Initialize a newly created Angular HTML index contributor. | 1207 * Initialize a newly created Angular HTML index contributor. |
| 1207 * | 1208 * |
| 1208 * @param store the [IndexStore] to record relations into. | 1209 * @param store the [IndexStore] to record relations into. |
| 1209 */ | 1210 */ |
| 1210 AngularHtmlIndexContributor(IndexStore store) { | 1211 AngularHtmlIndexContributor(IndexStore store) { |
| 1211 this._store = store; | 1212 this._store = store; |
| 1212 _indexContributor = new IndexContributor(store); | 1213 _indexContributor = new IndexContributor_AngularHtmlIndexContributor(store,
this); |
| 1213 } | 1214 } |
| 1214 | 1215 |
| 1215 void visitExpression(Expression expression) { | 1216 void visitExpression(Expression expression) { |
| 1217 // NgFilter |
| 1218 if (expression is SimpleIdentifier) { |
| 1219 SimpleIdentifier identifier = expression; |
| 1220 Element element = identifier.bestElement; |
| 1221 if (element is AngularElement) { |
| 1222 _store.recordRelationship(element, IndexConstants.IS_REFERENCED_BY, crea
teLocation(identifier)); |
| 1223 return; |
| 1224 } |
| 1225 } |
| 1226 // index as a normal Dart expression |
| 1216 expression.accept(_indexContributor); | 1227 expression.accept(_indexContributor); |
| 1217 } | 1228 } |
| 1218 | 1229 |
| 1219 Object visitHtmlUnit(ht.HtmlUnit node) { | 1230 Object visitHtmlUnit(ht.HtmlUnit node) { |
| 1220 _htmlUnitElement = node.element; | 1231 _htmlUnitElement = node.element; |
| 1221 CompilationUnitElement dartUnitElement = node.compilationUnitElement; | 1232 CompilationUnitElement dartUnitElement = node.compilationUnitElement; |
| 1222 _indexContributor.enterScope(dartUnitElement); | 1233 _indexContributor.enterScope(dartUnitElement); |
| 1223 return super.visitHtmlUnit(node); | 1234 return super.visitHtmlUnit(node); |
| 1224 } | 1235 } |
| 1225 | 1236 |
| 1226 Object visitXmlAttributeNode(ht.XmlAttributeNode node) { | 1237 Object visitXmlAttributeNode(ht.XmlAttributeNode node) { |
| 1227 Element element = node.element; | 1238 Element element = node.element; |
| 1228 if (element != null) { | 1239 if (element != null) { |
| 1229 ht.Token nameToken = node.nameToken; | 1240 ht.Token nameToken = node.nameToken; |
| 1230 Location location = createLocation(nameToken); | 1241 Location location = createLocation2(nameToken); |
| 1231 _store.recordRelationship(element, IndexConstants.IS_REFERENCED_BY, locati
on); | 1242 _store.recordRelationship(element, IndexConstants.IS_REFERENCED_BY, locati
on); |
| 1232 } | 1243 } |
| 1233 return super.visitXmlAttributeNode(node); | 1244 return super.visitXmlAttributeNode(node); |
| 1234 } | 1245 } |
| 1235 | 1246 |
| 1236 Object visitXmlTagNode(ht.XmlTagNode node) { | 1247 Object visitXmlTagNode(ht.XmlTagNode node) { |
| 1237 Element element = node.element; | 1248 Element element = node.element; |
| 1238 if (element != null) { | 1249 if (element != null) { |
| 1239 ht.Token tagToken = node.tagToken; | 1250 ht.Token tagToken = node.tagToken; |
| 1240 Location location = createLocation(tagToken); | 1251 Location location = createLocation2(tagToken); |
| 1241 _store.recordRelationship(element, IndexConstants.IS_REFERENCED_BY, locati
on); | 1252 _store.recordRelationship(element, IndexConstants.IS_REFERENCED_BY, locati
on); |
| 1242 } | 1253 } |
| 1243 return super.visitXmlTagNode(node); | 1254 return super.visitXmlTagNode(node); |
| 1244 } | 1255 } |
| 1245 | 1256 |
| 1246 Location createLocation(ht.Token token) => new Location(_htmlUnitElement, toke
n.offset, token.length); | 1257 Location createLocation(SimpleIdentifier identifier) => new Location(_htmlUnit
Element, identifier.offset, identifier.length); |
| 1258 |
| 1259 Location createLocation2(ht.Token token) => new Location(_htmlUnitElement, tok
en.offset, token.length); |
| 1260 } |
| 1261 |
| 1262 class IndexContributor_AngularHtmlIndexContributor extends IndexContributor { |
| 1263 final AngularHtmlIndexContributor AngularHtmlIndexContributor_this; |
| 1264 |
| 1265 IndexContributor_AngularHtmlIndexContributor(IndexStore arg0, this.AngularHtml
IndexContributor_this) : super(arg0); |
| 1266 |
| 1267 Element peekElement() => AngularHtmlIndexContributor_this._htmlUnitElement; |
| 1268 |
| 1269 void recordRelationship(Element element, Relationship relationship, Location l
ocation) { |
| 1270 AngularElement angularElement = AngularHtmlUnitResolver.getAngularElement(el
ement); |
| 1271 if (angularElement != null) { |
| 1272 element = angularElement; |
| 1273 relationship = IndexConstants.IS_REFERENCED_BY; |
| 1274 } |
| 1275 super.recordRelationship(element, relationship, location); |
| 1276 } |
| 1247 } | 1277 } |
| 1248 | 1278 |
| 1249 /** | 1279 /** |
| 1250 * The interface [Index] defines the behavior of objects that maintain an index
storing | 1280 * The interface [Index] defines the behavior of objects that maintain an index
storing |
| 1251 * [Relationship] between [Element]. All of the operations | 1281 * [Relationship] between [Element]. All of the operations |
| 1252 * defined on the index are asynchronous, and results, when there are any, are p
rovided through a | 1282 * defined on the index are asynchronous, and results, when there are any, are p
rovided through a |
| 1253 * callback. | 1283 * callback. |
| 1254 * | 1284 * |
| 1255 * Despite being asynchronous, the results of the operations are guaranteed to b
e consistent with | 1285 * Despite being asynchronous, the results of the operations are guaranteed to b
e consistent with |
| 1256 * the expectation that operations are performed in the order in which they are
requested. | 1286 * the expectation that operations are performed in the order in which they are
requested. |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1764 recordElementDefinition(element, IndexConstants.DEFINES_CLASS); | 1794 recordElementDefinition(element, IndexConstants.DEFINES_CLASS); |
| 1765 { | 1795 { |
| 1766 ExtendsClause extendsClause = node.extendsClause; | 1796 ExtendsClause extendsClause = node.extendsClause; |
| 1767 if (extendsClause != null) { | 1797 if (extendsClause != null) { |
| 1768 TypeName superclassNode = extendsClause.superclass; | 1798 TypeName superclassNode = extendsClause.superclass; |
| 1769 recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); | 1799 recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); |
| 1770 } else { | 1800 } else { |
| 1771 InterfaceType superType = element.supertype; | 1801 InterfaceType superType = element.supertype; |
| 1772 if (superType != null) { | 1802 if (superType != null) { |
| 1773 ClassElement objectElement = superType.element; | 1803 ClassElement objectElement = superType.element; |
| 1774 recordRelationship(objectElement, IndexConstants.IS_EXTENDED_BY, cre
ateLocation3(node.name.offset, 0)); | 1804 recordRelationship(objectElement, IndexConstants.IS_EXTENDED_BY, cre
ateLocation4(node.name.offset, 0)); |
| 1775 } | 1805 } |
| 1776 } | 1806 } |
| 1777 } | 1807 } |
| 1778 { | 1808 { |
| 1779 WithClause withClause = node.withClause; | 1809 WithClause withClause = node.withClause; |
| 1780 if (withClause != null) { | 1810 if (withClause != null) { |
| 1781 for (TypeName mixinNode in withClause.mixinTypes) { | 1811 for (TypeName mixinNode in withClause.mixinTypes) { |
| 1782 recordSuperType(mixinNode, IndexConstants.IS_MIXED_IN_BY); | 1812 recordSuperType(mixinNode, IndexConstants.IS_MIXED_IN_BY); |
| 1783 } | 1813 } |
| 1784 } | 1814 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1843 } | 1873 } |
| 1844 | 1874 |
| 1845 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 1875 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 1846 ConstructorElement element = node.element; | 1876 ConstructorElement element = node.element; |
| 1847 // define | 1877 // define |
| 1848 { | 1878 { |
| 1849 Location location; | 1879 Location location; |
| 1850 if (node.name != null) { | 1880 if (node.name != null) { |
| 1851 int start = node.period.offset; | 1881 int start = node.period.offset; |
| 1852 int end = node.name.end; | 1882 int end = node.name.end; |
| 1853 location = createLocation3(start, end - start); | 1883 location = createLocation4(start, end - start); |
| 1854 } else { | 1884 } else { |
| 1855 int start = node.returnType.end; | 1885 int start = node.returnType.end; |
| 1856 location = createLocation3(start, 0); | 1886 location = createLocation4(start, 0); |
| 1857 } | 1887 } |
| 1858 recordRelationship(element, IndexConstants.IS_DEFINED_BY, location); | 1888 recordRelationship(element, IndexConstants.IS_DEFINED_BY, location); |
| 1859 } | 1889 } |
| 1860 // visit children | 1890 // visit children |
| 1861 enterScope(element); | 1891 enterScope(element); |
| 1862 try { | 1892 try { |
| 1863 return super.visitConstructorDeclaration(node); | 1893 return super.visitConstructorDeclaration(node); |
| 1864 } finally { | 1894 } finally { |
| 1865 exitScope(); | 1895 exitScope(); |
| 1866 } | 1896 } |
| 1867 } | 1897 } |
| 1868 | 1898 |
| 1869 Object visitConstructorName(ConstructorName node) { | 1899 Object visitConstructorName(ConstructorName node) { |
| 1870 ConstructorElement element = node.staticElement; | 1900 ConstructorElement element = node.staticElement; |
| 1871 Location location; | 1901 Location location; |
| 1872 if (node.name != null) { | 1902 if (node.name != null) { |
| 1873 int start = node.period.offset; | 1903 int start = node.period.offset; |
| 1874 int end = node.name.end; | 1904 int end = node.name.end; |
| 1875 location = createLocation3(start, end - start); | 1905 location = createLocation4(start, end - start); |
| 1876 } else { | 1906 } else { |
| 1877 int start = node.type.end; | 1907 int start = node.type.end; |
| 1878 location = createLocation3(start, 0); | 1908 location = createLocation4(start, 0); |
| 1879 } | 1909 } |
| 1880 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 1910 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); |
| 1881 return super.visitConstructorName(node); | 1911 return super.visitConstructorName(node); |
| 1882 } | 1912 } |
| 1883 | 1913 |
| 1884 Object visitExportDirective(ExportDirective node) { | 1914 Object visitExportDirective(ExportDirective node) { |
| 1885 ExportElement element = node.element as ExportElement; | 1915 ExportElement element = node.element as ExportElement; |
| 1886 if (element != null) { | 1916 if (element != null) { |
| 1887 LibraryElement expLibrary = element.exportedLibrary; | 1917 LibraryElement expLibrary = element.exportedLibrary; |
| 1888 recordLibraryReference(node, expLibrary); | 1918 recordLibraryReference(node, expLibrary); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1923 LibraryElement impLibrary = element.importedLibrary; | 1953 LibraryElement impLibrary = element.importedLibrary; |
| 1924 recordLibraryReference(node, impLibrary); | 1954 recordLibraryReference(node, impLibrary); |
| 1925 } | 1955 } |
| 1926 return super.visitImportDirective(node); | 1956 return super.visitImportDirective(node); |
| 1927 } | 1957 } |
| 1928 | 1958 |
| 1929 Object visitIndexExpression(IndexExpression node) { | 1959 Object visitIndexExpression(IndexExpression node) { |
| 1930 MethodElement element = node.bestElement; | 1960 MethodElement element = node.bestElement; |
| 1931 if (element is MethodElement) { | 1961 if (element is MethodElement) { |
| 1932 Token operator = node.leftBracket; | 1962 Token operator = node.leftBracket; |
| 1933 Location location = createLocation4(operator); | 1963 Location location = createLocation5(operator); |
| 1934 recordRelationship(element, IndexConstants.IS_INVOKED_BY_QUALIFIED, locati
on); | 1964 recordRelationship(element, IndexConstants.IS_INVOKED_BY_QUALIFIED, locati
on); |
| 1935 } | 1965 } |
| 1936 return super.visitIndexExpression(node); | 1966 return super.visitIndexExpression(node); |
| 1937 } | 1967 } |
| 1938 | 1968 |
| 1939 Object visitMethodDeclaration(MethodDeclaration node) { | 1969 Object visitMethodDeclaration(MethodDeclaration node) { |
| 1940 ExecutableElement element = node.element; | 1970 ExecutableElement element = node.element; |
| 1941 enterScope(element); | 1971 enterScope(element); |
| 1942 try { | 1972 try { |
| 1943 return super.visitMethodDeclaration(node); | 1973 return super.visitMethodDeclaration(node); |
| 1944 } finally { | 1974 } finally { |
| 1945 exitScope(); | 1975 exitScope(); |
| 1946 } | 1976 } |
| 1947 } | 1977 } |
| 1948 | 1978 |
| 1949 Object visitMethodInvocation(MethodInvocation node) { | 1979 Object visitMethodInvocation(MethodInvocation node) { |
| 1950 SimpleIdentifier name = node.methodName; | 1980 SimpleIdentifier name = node.methodName; |
| 1951 Element element = name.bestElement; | 1981 Element element = name.bestElement; |
| 1952 if (element is MethodElement) { | 1982 if (element is MethodElement) { |
| 1953 Location location = createLocation2(name); | 1983 Location location = createLocation3(name); |
| 1954 Relationship relationship; | 1984 Relationship relationship; |
| 1955 if (node.target != null) { | 1985 if (node.target != null) { |
| 1956 relationship = IndexConstants.IS_INVOKED_BY_QUALIFIED; | 1986 relationship = IndexConstants.IS_INVOKED_BY_QUALIFIED; |
| 1957 } else { | 1987 } else { |
| 1958 relationship = IndexConstants.IS_INVOKED_BY_UNQUALIFIED; | 1988 relationship = IndexConstants.IS_INVOKED_BY_UNQUALIFIED; |
| 1959 } | 1989 } |
| 1960 recordRelationship(element, relationship, location); | 1990 recordRelationship(element, relationship, location); |
| 1961 } | 1991 } |
| 1962 if (element is FunctionElement) { | 1992 if (element is FunctionElement) { |
| 1963 Location location = createLocation2(name); | 1993 Location location = createLocation3(name); |
| 1964 recordRelationship(element, IndexConstants.IS_INVOKED_BY, location); | 1994 recordRelationship(element, IndexConstants.IS_INVOKED_BY, location); |
| 1965 } | 1995 } |
| 1966 recordImportElementReferenceWithoutPrefix(name); | 1996 recordImportElementReferenceWithoutPrefix(name); |
| 1967 return super.visitMethodInvocation(node); | 1997 return super.visitMethodInvocation(node); |
| 1968 } | 1998 } |
| 1969 | 1999 |
| 1970 Object visitPartDirective(PartDirective node) { | 2000 Object visitPartDirective(PartDirective node) { |
| 1971 Element element = node.element; | 2001 Element element = node.element; |
| 1972 Location location = createLocation2(node.uri); | 2002 Location location = createLocation3(node.uri); |
| 1973 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 2003 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); |
| 1974 return super.visitPartDirective(node); | 2004 return super.visitPartDirective(node); |
| 1975 } | 2005 } |
| 1976 | 2006 |
| 1977 Object visitPartOfDirective(PartOfDirective node) { | 2007 Object visitPartOfDirective(PartOfDirective node) { |
| 1978 Location location = createLocation2(node.libraryName); | 2008 Location location = createLocation3(node.libraryName); |
| 1979 recordRelationship(node.element, IndexConstants.IS_REFERENCED_BY, location); | 2009 recordRelationship(node.element, IndexConstants.IS_REFERENCED_BY, location); |
| 1980 return null; | 2010 return null; |
| 1981 } | 2011 } |
| 1982 | 2012 |
| 1983 Object visitPostfixExpression(PostfixExpression node) { | 2013 Object visitPostfixExpression(PostfixExpression node) { |
| 1984 recordOperatorReference(node.operator, node.bestElement); | 2014 recordOperatorReference(node.operator, node.bestElement); |
| 1985 return super.visitPostfixExpression(node); | 2015 return super.visitPostfixExpression(node); |
| 1986 } | 2016 } |
| 1987 | 2017 |
| 1988 Object visitPrefixExpression(PrefixExpression node) { | 2018 Object visitPrefixExpression(PrefixExpression node) { |
| 1989 recordOperatorReference(node.operator, node.bestElement); | 2019 recordOperatorReference(node.operator, node.bestElement); |
| 1990 return super.visitPrefixExpression(node); | 2020 return super.visitPrefixExpression(node); |
| 1991 } | 2021 } |
| 1992 | 2022 |
| 1993 Object visitSimpleIdentifier(SimpleIdentifier node) { | 2023 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 1994 Element nameElement = new NameElementImpl(node.name); | 2024 Element nameElement = new NameElementImpl(node.name); |
| 1995 Location location = createLocation2(node); | 2025 Location location = createLocation3(node); |
| 1996 // name in declaration | 2026 // name in declaration |
| 1997 if (node.inDeclarationContext()) { | 2027 if (node.inDeclarationContext()) { |
| 1998 recordRelationship(nameElement, IndexConstants.IS_DEFINED_BY, location); | 2028 recordRelationship(nameElement, IndexConstants.IS_DEFINED_BY, location); |
| 1999 return null; | 2029 return null; |
| 2000 } | 2030 } |
| 2001 // prepare information | 2031 // prepare information |
| 2002 Element element = node.bestElement; | 2032 Element element = node.bestElement; |
| 2003 // qualified name reference | 2033 // qualified name reference |
| 2004 recordQualifiedMemberReference(node, element, nameElement, location); | 2034 recordQualifiedMemberReference(node, element, nameElement, location); |
| 2005 // stop if already handled | 2035 // stop if already handled |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2041 recordImportElementReferenceWithoutPrefix(node); | 2071 recordImportElementReferenceWithoutPrefix(node); |
| 2042 return super.visitSimpleIdentifier(node); | 2072 return super.visitSimpleIdentifier(node); |
| 2043 } | 2073 } |
| 2044 | 2074 |
| 2045 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { | 2075 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
| 2046 ConstructorElement element = node.staticElement; | 2076 ConstructorElement element = node.staticElement; |
| 2047 Location location; | 2077 Location location; |
| 2048 if (node.constructorName != null) { | 2078 if (node.constructorName != null) { |
| 2049 int start = node.period.offset; | 2079 int start = node.period.offset; |
| 2050 int end = node.constructorName.end; | 2080 int end = node.constructorName.end; |
| 2051 location = createLocation3(start, end - start); | 2081 location = createLocation4(start, end - start); |
| 2052 } else { | 2082 } else { |
| 2053 int start = node.keyword.end; | 2083 int start = node.keyword.end; |
| 2054 location = createLocation3(start, 0); | 2084 location = createLocation4(start, 0); |
| 2055 } | 2085 } |
| 2056 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 2086 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); |
| 2057 return super.visitSuperConstructorInvocation(node); | 2087 return super.visitSuperConstructorInvocation(node); |
| 2058 } | 2088 } |
| 2059 | 2089 |
| 2060 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 2090 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 2061 VariableDeclarationList variables = node.variables; | 2091 VariableDeclarationList variables = node.variables; |
| 2062 for (VariableDeclaration variableDeclaration in variables.variables) { | 2092 for (VariableDeclaration variableDeclaration in variables.variables) { |
| 2063 Element element = variableDeclaration.element; | 2093 Element element = variableDeclaration.element; |
| 2064 recordElementDefinition(element, IndexConstants.DEFINES_VARIABLE); | 2094 recordElementDefinition(element, IndexConstants.DEFINES_VARIABLE); |
| 2065 } | 2095 } |
| 2066 return super.visitTopLevelVariableDeclaration(node); | 2096 return super.visitTopLevelVariableDeclaration(node); |
| 2067 } | 2097 } |
| 2068 | 2098 |
| 2069 Object visitTypeParameter(TypeParameter node) { | 2099 Object visitTypeParameter(TypeParameter node) { |
| 2070 TypeParameterElement element = node.element; | 2100 TypeParameterElement element = node.element; |
| 2071 enterScope(element); | 2101 enterScope(element); |
| 2072 try { | 2102 try { |
| 2073 return super.visitTypeParameter(node); | 2103 return super.visitTypeParameter(node); |
| 2074 } finally { | 2104 } finally { |
| 2075 exitScope(); | 2105 exitScope(); |
| 2076 } | 2106 } |
| 2077 } | 2107 } |
| 2078 | 2108 |
| 2079 Object visitVariableDeclaration(VariableDeclaration node) { | 2109 Object visitVariableDeclaration(VariableDeclaration node) { |
| 2080 VariableElement element = node.element; | 2110 VariableElement element = node.element; |
| 2081 // record declaration | 2111 // record declaration |
| 2082 { | 2112 { |
| 2083 SimpleIdentifier name = node.name; | 2113 SimpleIdentifier name = node.name; |
| 2084 Location location = createLocation2(name); | 2114 Location location = createLocation3(name); |
| 2085 location = getLocationWithExpressionType(location, node.initializer); | 2115 location = getLocationWithExpressionType(location, node.initializer); |
| 2086 recordRelationship(element, IndexConstants.IS_DEFINED_BY, location); | 2116 recordRelationship(element, IndexConstants.IS_DEFINED_BY, location); |
| 2087 } | 2117 } |
| 2088 // visit | 2118 // visit |
| 2089 enterScope(element); | 2119 enterScope(element); |
| 2090 try { | 2120 try { |
| 2091 return super.visitVariableDeclaration(node); | 2121 return super.visitVariableDeclaration(node); |
| 2092 } finally { | 2122 } finally { |
| 2093 exitScope(); | 2123 exitScope(); |
| 2094 } | 2124 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2113 } | 2143 } |
| 2114 } | 2144 } |
| 2115 } | 2145 } |
| 2116 // visit variables | 2146 // visit variables |
| 2117 variables.accept(this); | 2147 variables.accept(this); |
| 2118 } | 2148 } |
| 2119 return null; | 2149 return null; |
| 2120 } | 2150 } |
| 2121 | 2151 |
| 2122 /** | 2152 /** |
| 2153 * Record the given relationship between the given [Element] and [Location]. |
| 2154 */ |
| 2155 void recordRelationship(Element element, Relationship relationship, Location l
ocation) { |
| 2156 if (element != null && location != null) { |
| 2157 _store.recordRelationship(element, relationship, location); |
| 2158 } |
| 2159 } |
| 2160 |
| 2161 /** |
| 2123 * @return the [Location] representing location of the [ASTNode]. | 2162 * @return the [Location] representing location of the [ASTNode]. |
| 2124 */ | 2163 */ |
| 2125 Location createLocation2(ASTNode node) => createLocation3(node.offset, node.le
ngth); | 2164 Location createLocation3(ASTNode node) => createLocation4(node.offset, node.le
ngth); |
| 2126 | 2165 |
| 2127 /** | 2166 /** |
| 2128 * @param offset the offset of the location within [Source] | 2167 * @param offset the offset of the location within [Source] |
| 2129 * @param length the length of the location | 2168 * @param length the length of the location |
| 2130 * @return the [Location] representing the given offset and length within the
inner-most | 2169 * @return the [Location] representing the given offset and length within the
inner-most |
| 2131 * [Element]. | 2170 * [Element]. |
| 2132 */ | 2171 */ |
| 2133 Location createLocation3(int offset, int length) { | 2172 Location createLocation4(int offset, int length) { |
| 2134 Element element = peekElement(); | 2173 Element element = peekElement(); |
| 2135 return new Location(element, offset, length); | 2174 return new Location(element, offset, length); |
| 2136 } | 2175 } |
| 2137 | 2176 |
| 2138 /** | 2177 /** |
| 2139 * @return the [Location] representing location of the [Token]. | 2178 * @return the [Location] representing location of the [Token]. |
| 2140 */ | 2179 */ |
| 2141 Location createLocation4(Token token) => createLocation3(token.offset, token.l
ength); | 2180 Location createLocation5(Token token) => createLocation4(token.offset, token.l
ength); |
| 2142 | 2181 |
| 2143 /** | 2182 /** |
| 2144 * Exit the current scope. | 2183 * Exit the current scope. |
| 2145 */ | 2184 */ |
| 2146 void exitScope() { | 2185 void exitScope() { |
| 2147 _elementStack.removeFirst(); | 2186 _elementStack.removeFirst(); |
| 2148 } | 2187 } |
| 2149 | 2188 |
| 2150 /** | 2189 /** |
| 2151 * @return `true` if given node already indexed as more interesting reference,
so it should | 2190 * @return `true` if given node already indexed as more interesting reference,
so it should |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2175 * Records [ImportElement] reference if given [SimpleIdentifier] references so
me | 2214 * Records [ImportElement] reference if given [SimpleIdentifier] references so
me |
| 2176 * top-level element and not qualified with import prefix. | 2215 * top-level element and not qualified with import prefix. |
| 2177 */ | 2216 */ |
| 2178 void recordImportElementReferenceWithoutPrefix(SimpleIdentifier node) { | 2217 void recordImportElementReferenceWithoutPrefix(SimpleIdentifier node) { |
| 2179 if (isIdentifierInPrefixedIdentifier(node)) { | 2218 if (isIdentifierInPrefixedIdentifier(node)) { |
| 2180 return; | 2219 return; |
| 2181 } | 2220 } |
| 2182 Element element = node.staticElement; | 2221 Element element = node.staticElement; |
| 2183 ImportElement importElement = getImportElement2(_libraryElement, null, eleme
nt, _importElementsMap); | 2222 ImportElement importElement = getImportElement2(_libraryElement, null, eleme
nt, _importElementsMap); |
| 2184 if (importElement != null) { | 2223 if (importElement != null) { |
| 2185 Location location = createLocation3(node.offset, 0); | 2224 Location location = createLocation4(node.offset, 0); |
| 2186 recordRelationship(importElement, IndexConstants.IS_REFERENCED_BY, locatio
n); | 2225 recordRelationship(importElement, IndexConstants.IS_REFERENCED_BY, locatio
n); |
| 2187 } | 2226 } |
| 2188 } | 2227 } |
| 2189 | 2228 |
| 2190 /** | 2229 /** |
| 2191 * Records [ImportElement] that declares given prefix and imports library with
element used | 2230 * Records [ImportElement] that declares given prefix and imports library with
element used |
| 2192 * with given prefix node. | 2231 * with given prefix node. |
| 2193 */ | 2232 */ |
| 2194 void recordImportElementReferenceWithPrefix(SimpleIdentifier prefixNode) { | 2233 void recordImportElementReferenceWithPrefix(SimpleIdentifier prefixNode) { |
| 2195 IndexContributor_ImportElementInfo info = getImportElementInfo(prefixNode); | 2234 IndexContributor_ImportElementInfo info = getImportElementInfo(prefixNode); |
| 2196 if (info != null) { | 2235 if (info != null) { |
| 2197 int offset = prefixNode.offset; | 2236 int offset = prefixNode.offset; |
| 2198 int length = info._periodEnd - offset; | 2237 int length = info._periodEnd - offset; |
| 2199 Location location = createLocation3(offset, length); | 2238 Location location = createLocation4(offset, length); |
| 2200 recordRelationship(info._element, IndexConstants.IS_REFERENCED_BY, locatio
n); | 2239 recordRelationship(info._element, IndexConstants.IS_REFERENCED_BY, locatio
n); |
| 2201 } | 2240 } |
| 2202 } | 2241 } |
| 2203 | 2242 |
| 2204 /** | 2243 /** |
| 2205 * Records reference to defining [CompilationUnitElement] of the given | 2244 * Records reference to defining [CompilationUnitElement] of the given |
| 2206 * [LibraryElement]. | 2245 * [LibraryElement]. |
| 2207 */ | 2246 */ |
| 2208 void recordLibraryReference(UriBasedDirective node, LibraryElement library) { | 2247 void recordLibraryReference(UriBasedDirective node, LibraryElement library) { |
| 2209 if (library != null) { | 2248 if (library != null) { |
| 2210 Location location = createLocation2(node.uri); | 2249 Location location = createLocation3(node.uri); |
| 2211 recordRelationship(library.definingCompilationUnit, IndexConstants.IS_REFE
RENCED_BY, location); | 2250 recordRelationship(library.definingCompilationUnit, IndexConstants.IS_REFE
RENCED_BY, location); |
| 2212 } | 2251 } |
| 2213 } | 2252 } |
| 2214 | 2253 |
| 2215 /** | 2254 /** |
| 2216 * Record reference to the given operator [Element] and name. | 2255 * Record reference to the given operator [Element] and name. |
| 2217 */ | 2256 */ |
| 2218 void recordOperatorReference(Token operator, Element element) { | 2257 void recordOperatorReference(Token operator, Element element) { |
| 2219 // prepare location | 2258 // prepare location |
| 2220 Location location = createLocation4(operator); | 2259 Location location = createLocation5(operator); |
| 2221 // record name reference | 2260 // record name reference |
| 2222 { | 2261 { |
| 2223 String name = operator.lexeme; | 2262 String name = operator.lexeme; |
| 2224 if (name == "++") { | 2263 if (name == "++") { |
| 2225 name = "+"; | 2264 name = "+"; |
| 2226 } | 2265 } |
| 2227 if (name == "--") { | 2266 if (name == "--") { |
| 2228 name = "-"; | 2267 name = "-"; |
| 2229 } | 2268 } |
| 2230 if (name.endsWith("=") && name != "==") { | 2269 if (StringUtilities.endsWithChar(name, 0x3D) && name != "==") { |
| 2231 name = name.substring(0, name.length - 1); | 2270 name = name.substring(0, name.length - 1); |
| 2232 } | 2271 } |
| 2233 Element nameElement = new NameElementImpl(name); | 2272 Element nameElement = new NameElementImpl(name); |
| 2234 Relationship relationship = element != null ? IndexConstants.IS_REFERENCED
_BY_QUALIFIED_RESOLVED : IndexConstants.IS_REFERENCED_BY_QUALIFIED_UNRESOLVED; | 2273 Relationship relationship = element != null ? IndexConstants.IS_REFERENCED
_BY_QUALIFIED_RESOLVED : IndexConstants.IS_REFERENCED_BY_QUALIFIED_UNRESOLVED; |
| 2235 recordRelationship(nameElement, relationship, location); | 2274 recordRelationship(nameElement, relationship, location); |
| 2236 } | 2275 } |
| 2237 // record element reference | 2276 // record element reference |
| 2238 if (element != null) { | 2277 if (element != null) { |
| 2239 recordRelationship(element, IndexConstants.IS_INVOKED_BY_QUALIFIED, locati
on); | 2278 recordRelationship(element, IndexConstants.IS_INVOKED_BY_QUALIFIED, locati
on); |
| 2240 } | 2279 } |
| 2241 } | 2280 } |
| 2242 | 2281 |
| 2243 /** | 2282 /** |
| 2244 * Records reference if the given [SimpleIdentifier] looks like a qualified pr
operty access | 2283 * Records reference if the given [SimpleIdentifier] looks like a qualified pr
operty access |
| 2245 * or method invocation. | 2284 * or method invocation. |
| 2246 */ | 2285 */ |
| 2247 void recordQualifiedMemberReference(SimpleIdentifier node, Element element, El
ement nameElement, Location location) { | 2286 void recordQualifiedMemberReference(SimpleIdentifier node, Element element, El
ement nameElement, Location location) { |
| 2248 if (isQualified(node)) { | 2287 if (isQualified(node)) { |
| 2249 Relationship relationship = element != null ? IndexConstants.IS_REFERENCED
_BY_QUALIFIED_RESOLVED : IndexConstants.IS_REFERENCED_BY_QUALIFIED_UNRESOLVED; | 2288 Relationship relationship = element != null ? IndexConstants.IS_REFERENCED
_BY_QUALIFIED_RESOLVED : IndexConstants.IS_REFERENCED_BY_QUALIFIED_UNRESOLVED; |
| 2250 recordRelationship(nameElement, relationship, location); | 2289 recordRelationship(nameElement, relationship, location); |
| 2251 } | 2290 } |
| 2252 } | 2291 } |
| 2253 | 2292 |
| 2254 /** | 2293 /** |
| 2255 * Record the given relationship between the given [Element] and [Location]. | |
| 2256 */ | |
| 2257 void recordRelationship(Element element, Relationship relationship, Location l
ocation) { | |
| 2258 if (element != null && location != null) { | |
| 2259 _store.recordRelationship(element, relationship, location); | |
| 2260 } | |
| 2261 } | |
| 2262 | |
| 2263 /** | |
| 2264 * Records extends/implements relationships between given [ClassElement] and [
Type] of | 2294 * Records extends/implements relationships between given [ClassElement] and [
Type] of |
| 2265 * "superNode". | 2295 * "superNode". |
| 2266 */ | 2296 */ |
| 2267 void recordSuperType(TypeName superNode, Relationship relationship) { | 2297 void recordSuperType(TypeName superNode, Relationship relationship) { |
| 2268 if (superNode != null) { | 2298 if (superNode != null) { |
| 2269 Identifier superName = superNode.name; | 2299 Identifier superName = superNode.name; |
| 2270 if (superName != null) { | 2300 if (superName != null) { |
| 2271 Element superElement = superName.staticElement; | 2301 Element superElement = superName.staticElement; |
| 2272 recordRelationship(superElement, relationship, createLocation2(superNode
)); | 2302 recordRelationship(superElement, relationship, createLocation3(superNode
)); |
| 2273 } | 2303 } |
| 2274 } | 2304 } |
| 2275 } | 2305 } |
| 2276 } | 2306 } |
| 2277 | 2307 |
| 2278 /** | 2308 /** |
| 2279 * Information about [ImportElement] and place where it is referenced using | 2309 * Information about [ImportElement] and place where it is referenced using |
| 2280 * [PrefixElement]. | 2310 * [PrefixElement]. |
| 2281 */ | 2311 */ |
| 2282 class IndexContributor_ImportElementInfo { | 2312 class IndexContributor_ImportElementInfo { |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2767 * element are available. For example, if the element is a field and the relat
ionship is the | 2797 * element are available. For example, if the element is a field and the relat
ionship is the |
| 2768 * is-referenced-by relationship, then this method will be invoked with each l
ocation at which the | 2798 * is-referenced-by relationship, then this method will be invoked with each l
ocation at which the |
| 2769 * field is referenced. | 2799 * field is referenced. |
| 2770 * | 2800 * |
| 2771 * @param element the [Element] that has the relationship with the locations | 2801 * @param element the [Element] that has the relationship with the locations |
| 2772 * @param relationship the relationship between the given element and the loca
tions | 2802 * @param relationship the relationship between the given element and the loca
tions |
| 2773 * @param locations the locations that were found | 2803 * @param locations the locations that were found |
| 2774 */ | 2804 */ |
| 2775 void hasRelationships(Element element, Relationship relationship, List<Locatio
n> locations); | 2805 void hasRelationships(Element element, Relationship relationship, List<Locatio
n> locations); |
| 2776 } | 2806 } |
| OLD | NEW |