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

Unified Diff: pkg/analyzer/lib/src/summary/index_unit.dart

Issue 1733843007: Add tests for indexing. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/summary/index_unit.dart
diff --git a/pkg/analyzer/lib/src/summary/index_unit.dart b/pkg/analyzer/lib/src/summary/index_unit.dart
index 446094508c4dd5b1bfb1ca7a8248a0f3d4caa980..1808967b8618760e33a041ec40c96c95217203ef 100644
--- a/pkg/analyzer/lib/src/summary/index_unit.dart
+++ b/pkg/analyzer/lib/src/summary/index_unit.dart
@@ -75,6 +75,7 @@ class PackageIndexAssembler {
elementUnitUris: _elementUnitUris,
elementUnits: elementInfoList.map((e) => e.unitId).toList(),
elementOffsets: elementInfoList.map((e) => e.offset).toList(),
+ elementKinds: elementInfoList.map((e) => e.kind).toList(),
uris: _uris,
units: _units.map((unit) => unit.assemble()).toList());
}
@@ -97,7 +98,12 @@ class PackageIndexAssembler {
return _elementMap.putIfAbsent(element, () {
CompilationUnitElement unitElement = getUnitElement(element);
int unitId = _getUnitElementId(unitElement);
- return new _ElementInfo(unitId, element.nameOffset);
+ int offset = element.nameOffset;
+ if (element is LibraryElement || element is CompilationUnitElement) {
+ offset = 0;
+ }
+ IndexElementKind kind = getIndexElementKind(element);
+ return new _ElementInfo(unitId, offset, kind);
});
}
@@ -130,6 +136,20 @@ class PackageIndexAssembler {
}
/**
+ * Return the kind of the given [element].
+ */
+ static IndexElementKind getIndexElementKind(Element element) {
+ if (element is ConstructorElement && element.isSynthetic) {
Paul Berry 2016/02/26 19:02:05 Why are only synthetic constructors classified as
+ return IndexElementKind.constructor;
+ } else if (element is PropertyAccessorElement) {
+ return element.isGetter
+ ? IndexElementKind.getter
+ : IndexElementKind.setter;
+ }
+ return IndexElementKind.element;
+ }
+
+ /**
* Return the [CompilationUnitElement] that should be used for [element].
* Throw [StateError] if the [element] is not linked into a unit.
*/
@@ -150,6 +170,11 @@ class PackageIndexAssembler {
* Information about an element referenced in index.
*/
class _ElementInfo {
+ static const int KIND_ELEMENT = 0;
Paul Berry 2016/02/26 19:02:05 I don't see where these are used, and I'm concerne
+ static const int KIND_GETTER = 1;
+ static const int KIND_SETTER = 2;
+ static const int KIND_CONSTRUCTOR = 3;
+
/**
* The identifier of the [CompilationUnitElement] containing this element.
*/
@@ -161,12 +186,17 @@ class _ElementInfo {
final int offset;
/**
+ * The kind of the element.
+ */
+ final IndexElementKind kind;
+
+ /**
* The unique id of the element. It is set after indexing of the whole
* package is done and we are assembling the full package index.
*/
int id;
- _ElementInfo(this.unitId, this.offset);
+ _ElementInfo(this.unitId, this.offset, this.kind);
}
/**
@@ -208,14 +238,6 @@ class _IndexContributor extends GeneralizingAstVisitor {
}
/**
- * Records reference to defining [CompilationUnitElement] of the given
- * [LibraryElement].
- */
- void recordLibraryReference(UriBasedDirective node, LibraryElement library) {
- recordRelation(library, IndexRelationKind.IS_REFERENCED_BY, node?.uri);
- }
-
- /**
* Record reference to the given operator [Element] and name.
*/
void recordOperatorReference(Token operator, Element element) {
@@ -264,11 +286,14 @@ class _IndexContributor extends GeneralizingAstVisitor {
Element element, IndexRelationKind kind, int offset, int length) {
// Ignore elements that can't be referenced outside of the unit.
if (element == null ||
+ element is FunctionElement &&
+ element.enclosingElement is ExecutableElement ||
+ element is LabelElement ||
element is LocalVariableElement ||
element is ParameterElement &&
element.parameterKind != ParameterKind.NAMED ||
- element is FunctionElement &&
- element.enclosingElement is ExecutableElement) {
+ element is PrefixElement ||
+ element is TypeParameterElement) {
return;
}
// Add the relation.
@@ -315,8 +340,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
// }
}
- void recordUriFileReference(UriBasedDirective directive) {
- Element element = directive.element;
+ void recordUriReference(Element element, UriBasedDirective directive) {
recordRelation(element, IndexRelationKind.IS_REFERENCED_BY, directive.uri);
}
@@ -395,11 +419,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
@override
visitExportDirective(ExportDirective node) {
ExportElement element = node.element;
- if (element != null) {
- LibraryElement expLibrary = element.exportedLibrary;
- recordLibraryReference(node, expLibrary);
- }
- recordUriFileReference(node);
+ recordUriReference(element?.exportedLibrary, node);
super.visitExportDirective(node);
}
@@ -420,11 +440,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
@override
visitImportDirective(ImportDirective node) {
ImportElement element = node.element;
- if (element != null) {
- LibraryElement impLibrary = element.importedLibrary;
- recordLibraryReference(node, impLibrary);
- }
- recordUriFileReference(node);
+ recordUriReference(element?.importedLibrary, node);
super.visitImportDirective(node);
}
@@ -452,9 +468,9 @@ class _IndexContributor extends GeneralizingAstVisitor {
element is PropertyAccessorElement ||
element is FunctionElement ||
element is VariableElement) {
- recordRelation(element, IndexRelationKind.IS_INVOKED_BY, node);
+ recordRelation(element, IndexRelationKind.IS_INVOKED_BY, name);
} else if (element is ClassElement) {
- recordRelation(element, IndexRelationKind.IS_REFERENCED_BY, node);
+ recordRelation(element, IndexRelationKind.IS_REFERENCED_BY, name);
}
node.target?.accept(this);
node.argumentList?.accept(this);
@@ -462,17 +478,12 @@ class _IndexContributor extends GeneralizingAstVisitor {
@override
visitPartDirective(PartDirective node) {
- recordRelation(node.element, IndexRelationKind.IS_REFERENCED_BY, node);
- recordUriFileReference(node);
+ Element element = node.element;
+ recordUriReference(element, node);
super.visitPartDirective(node);
}
@override
- visitPartOfDirective(PartOfDirective node) {
- recordRelation(node.element, IndexRelationKind.IS_REFERENCED_BY, node);
- }
-
- @override
visitPostfixExpression(PostfixExpression node) {
recordOperatorReference(node.operator, node.bestElement);
super.visitPostfixExpression(node);
@@ -532,6 +543,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
element is FunctionTypeAliasElement ||
element is LabelElement ||
element is MethodElement ||
+ element is ParameterElement ||
element is PrefixElement ||
element is PropertyAccessorElement ||
element is PropertyInducingElement ||

Powered by Google App Engine
This is Rietveld 408576698