Skip to content

Commit 4b9a6a0

Browse files
scheglovCommit Queue
authored andcommitted
DeCo. Stop using isSynthetic in index.
There is no change in behavior. Index record relations between elements and locations, where the element is identified by a triplet of names (topLevelName, classMemberName, formalParameterName). Which is almost enough, but for field / getter / setter the names are the same, so we add the kind. It was more complicated than necessary, so I simplified it a little. Change-Id: If91b8881f89ffc7a8f41331ded9ef4b1b64136b8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465965 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 85e5c56 commit 4b9a6a0

File tree

2 files changed

+10
-53
lines changed

2 files changed

+10
-53
lines changed

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ testFineAfterLibraryAnalyzerHook;
108108
// TODO(scheglov): Clean up the list of implicitly analyzed files.
109109
class AnalysisDriver {
110110
/// The version of data format, should be incremented on every format change.
111-
static const int DATA_VERSION = 592;
111+
static const int DATA_VERSION = 593;
112112

113113
/// The number of exception contexts allowed to write. Once this field is
114114
/// zero, we stop writing any new exception contexts in this process.

pkg/analyzer/lib/src/dart/analysis/index.dart

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -173,55 +173,14 @@ class IndexElementInfo {
173173

174174
factory IndexElementInfo(Element element) {
175175
IndexSyntheticElementKind kind = IndexSyntheticElementKind.notSynthetic;
176-
ElementKind elementKind = element.kind;
177-
if (elementKind == ElementKind.LIBRARY ||
178-
elementKind == ElementKind.COMPILATION_UNIT) {
179-
kind = IndexSyntheticElementKind.unit;
180-
} else if (element.isSynthetic) {
181-
if (elementKind == ElementKind.CONSTRUCTOR) {
182-
kind = IndexSyntheticElementKind.constructor;
183-
element = element.enclosingElement!;
184-
} else if (element is TopLevelFunctionElement &&
185-
element.name == TopLevelFunctionElement.LOAD_LIBRARY_NAME) {
186-
kind = IndexSyntheticElementKind.loadLibrary;
187-
element = element.library;
188-
} else if (elementKind == ElementKind.FIELD) {
189-
var field = element as FieldElement;
190-
kind = IndexSyntheticElementKind.field;
191-
element = (field.getter ?? field.setter)!;
192-
} else if (elementKind == ElementKind.GETTER ||
193-
elementKind == ElementKind.SETTER) {
194-
var accessor = element as PropertyAccessorElement;
195-
var enclosing = element.enclosingElement;
196-
bool isEnumGetter = enclosing is EnumElement;
197-
if (isEnumGetter && accessor.name == 'index') {
198-
kind = IndexSyntheticElementKind.enumIndex;
199-
element = enclosing;
200-
} else if (isEnumGetter && accessor.name == 'values') {
201-
kind = IndexSyntheticElementKind.enumValues;
202-
element = enclosing;
203-
} else {
204-
kind = accessor is GetterElement
205-
? IndexSyntheticElementKind.getter
206-
: IndexSyntheticElementKind.setter;
207-
element = accessor.variable;
208-
}
209-
} else if (element is MethodElement) {
210-
var enclosing = element.enclosingElement;
211-
bool isEnumMethod = enclosing is EnumElement;
212-
if (isEnumMethod && element.name == 'toString') {
213-
kind = IndexSyntheticElementKind.enumToString;
214-
element = enclosing;
215-
}
216-
} else if (element is TopLevelVariableElement) {
217-
kind = IndexSyntheticElementKind.topLevelVariable;
218-
element = (element.getter ?? element.setter)!;
219-
} else {
220-
throw ArgumentError(
221-
'Unsupported synthetic element ${element.runtimeType}',
222-
);
223-
}
176+
if (element is GetterElement) {
177+
kind = IndexSyntheticElementKind.getter;
178+
element = element.variable;
179+
} else if (element is SetterElement) {
180+
kind = IndexSyntheticElementKind.setter;
181+
element = element.variable;
224182
}
183+
225184
return IndexElementInfo._(element, kind);
226185
}
227186

@@ -657,10 +616,8 @@ class _IndexContributor extends GeneralizingAstVisitor {
657616
}
658617
// Ignore named parameters of synthetic functions, e.g. created for LUB.
659618
// These functions are not bound to a source, we cannot index them.
660-
if (elementKind == ElementKind.PARAMETER &&
661-
element is FormalParameterElement) {
662-
var enclosingElement = element.enclosingElement;
663-
if (enclosingElement == null || enclosingElement.isSynthetic) {
619+
if (element is FormalParameterElement) {
620+
if (element.enclosingElement == null) {
664621
return;
665622
}
666623
}

0 commit comments

Comments
 (0)