Skip to content

Commit 3dc8cb0

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Minor improvements to metrics gathering
Differentiate between class references and constructor references when the class name comes first. Start gathering data for general cases (start of expression, start of statement) to determine whether we need fine-grained handling based on the context or whether all expressions (for example) follow the same distribution. Change-Id: Iec403474aa19a3468fd15c0b90ec26392bf040f8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136440 Reviewed-by: Jaime Wren <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent fa38644 commit 3dc8cb0

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

pkg/analysis_server/tool/completion_metrics/relevance_metrics.dart

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,9 +1309,18 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
13091309
/// Return the element kind of the element associated with the left-most
13101310
/// identifier that is a child of the [node].
13111311
ElementKind _leftMostKind(AstNode node) {
1312+
if (node is InstanceCreationExpression) {
1313+
return convertElementToElementKind(node.staticElement);
1314+
}
13121315
var element = _leftMostElement(node);
13131316
if (element == null) {
1314-
return ElementKind.UNKNOWN;
1317+
return null;
1318+
}
1319+
if (element is ClassElement) {
1320+
var parent = node.parent;
1321+
if (parent is Annotation && parent.arguments != null) {
1322+
element = parent.element;
1323+
}
13151324
}
13161325
return convertElementToElementKind(element);
13171326
}
@@ -1419,7 +1428,8 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
14191428
return -1;
14201429
}
14211430

1422-
/// Record information about the given [node] occurring the given [context].
1431+
/// Record information about the given [node] occurring in the given
1432+
/// [context].
14231433
void _recordDataForNode(String context, AstNode node,
14241434
{List<Keyword> allowedKeywords = noKeywords}) {
14251435
_recordElementKind(context, node);
@@ -1442,6 +1452,11 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
14421452
var kind = _leftMostKind(node);
14431453
if (kind != null) {
14441454
data.recordElementKind(context, kind);
1455+
if (node is Expression) {
1456+
data.recordElementKind('Expression', kind);
1457+
} else if (node is Statement) {
1458+
data.recordElementKind('Statement', kind);
1459+
}
14451460
}
14461461
}
14471462
}
@@ -1504,6 +1519,8 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
15041519
}
15051520

15061521
int superclassDepth = getSuperclassDepth();
1522+
// TODO(brianwilkerson) Consider cross referencing with the depth of the
1523+
// class containing the reference.
15071524
if (superclassDepth >= 0) {
15081525
_recordDistance('member (superclass)', superclassDepth);
15091526
} else {
@@ -1639,6 +1656,11 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
16391656
}
16401657
}
16411658
data.recordTokenType(context, type);
1659+
if (node is Expression) {
1660+
data.recordTokenType('Expression', type);
1661+
} else if (node is Statement) {
1662+
data.recordTokenType('Statement', type);
1663+
}
16421664
}
16431665
}
16441666
}

0 commit comments

Comments
 (0)