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

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

Issue 1829463002: Issue 26063. Index declarations in even partically analyzed units. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 b239d5caa2e62ac2cf1e423e36488ba85312b5e1..610fba4f8c3df46b9ccbb76340159f2ae2fee7c1 100644
--- a/pkg/analyzer/lib/src/summary/index_unit.dart
+++ b/pkg/analyzer/lib/src/summary/index_unit.dart
@@ -13,11 +13,6 @@ import 'package:analyzer/src/summary/format.dart';
import 'package:analyzer/src/summary/idl.dart';
/**
- * TODO(scheglov) add to the `meta` package.
- */
-const visibleForTesting = const Object();
-
-/**
* Information about an element referenced in index.
*/
class ElementInfo {
@@ -90,7 +85,7 @@ class PackageIndexAssembler {
/**
* Assemble a new [PackageIndexBuilder] using the information gathered by
- * [index].
+ * [indexDeclarations] or [indexUnit].
*/
PackageIndexBuilder assemble() {
// sort strings end set IDs
@@ -120,9 +115,19 @@ class PackageIndexAssembler {
}
/**
+ * Index declarations in the given partially resolved [unit].
+ */
+ void indexDeclarations(CompilationUnit unit) {
+ int unitId = _getUnitId(unit.element);
+ _UnitIndexAssembler assembler = new _UnitIndexAssembler(this, unitId);
+ _units.add(assembler);
+ unit.accept(new _IndexDeclarationContributor(assembler));
+ }
+
+ /**
* Index the given fully resolved [unit].
*/
- void index(CompilationUnit unit) {
+ void indexUnit(CompilationUnit unit) {
int unitId = _getUnitId(unit.element);
_UnitIndexAssembler assembler = new _UnitIndexAssembler(this, unitId);
_units.add(assembler);
@@ -291,26 +296,8 @@ class _ElementRelationInfo {
/**
* Visits a resolved AST and adds relationships into [_UnitIndexAssembler].
*/
-class _IndexContributor extends GeneralizingAstVisitor {
- final _UnitIndexAssembler assembler;
-
- _IndexContributor(this.assembler);
-
- /**
- * Record definition of the given [element].
- */
- void recordDefinedElement(Element element) {
- if (element != null) {
- String name = element.displayName;
- int offset = element.nameOffset;
- Element enclosing = element.enclosingElement;
- if (enclosing is CompilationUnitElement) {
- assembler.defineName(name, IndexNameKind.topLevel, offset);
- } else if (enclosing is ClassElement) {
- assembler.defineName(name, IndexNameKind.classMember, offset);
- }
- }
- }
+class _IndexContributor extends _IndexDeclarationContributor {
+ _IndexContributor(_UnitIndexAssembler assembler) : super(assembler);
void recordIsAncestorOf(Element descendant) {
_recordIsAncestorOf(descendant, descendant, false, <ClassElement>[]);
@@ -566,12 +553,13 @@ class _IndexContributor extends GeneralizingAstVisitor {
@override
visitSimpleIdentifier(SimpleIdentifier node) {
- Element element = node.bestElement;
// name in declaration
if (node.inDeclarationContext()) {
+ Element element = node.staticElement;
recordDefinedElement(element);
return;
}
+ Element element = node.bestElement;
// record unresolved name reference
bool isQualified = _isQualified(node);
if (element == null) {
@@ -704,6 +692,40 @@ class _IndexContributor extends GeneralizingAstVisitor {
}
/**
+ * Visits a resolved AST and adds relationships into [_UnitIndexAssembler].
+ */
+class _IndexDeclarationContributor extends GeneralizingAstVisitor {
+ final _UnitIndexAssembler assembler;
+
+ _IndexDeclarationContributor(this.assembler);
+
+ /**
+ * Record definition of the given [element].
+ */
+ void recordDefinedElement(Element element) {
+ if (element != null) {
+ String name = element.displayName;
+ int offset = element.nameOffset;
+ Element enclosing = element.enclosingElement;
+ if (enclosing is CompilationUnitElement) {
+ assembler.defineName(name, IndexNameKind.topLevel, offset);
+ } else if (enclosing is ClassElement) {
+ assembler.defineName(name, IndexNameKind.classMember, offset);
+ }
+ }
+ }
+
+ @override
+ visitSimpleIdentifier(SimpleIdentifier node) {
+ if (node.inDeclarationContext()) {
+ Element element = node.staticElement;
+ recordDefinedElement(element);
+ return;
+ }
+ }
+}
+
+/**
* Information about a single name relation. Any [_NameRelationInfo] is always
* part of a [_UnitIndexAssembler], so [offset] should be understood within the
* context of the compilation unit pointed to by the [_UnitIndexAssembler].
« no previous file with comments | « pkg/analysis_server/test/services/index/index_test.dart ('k') | pkg/analyzer/test/src/summary/index_unit_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698