Skip to content

Commit

Permalink
Minor improvements to metrics gathering
Browse files Browse the repository at this point in the history
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 <jwren@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
bwilkerson authored and commit-bot@chromium.org committed Feb 19, 2020
1 parent fa38644 commit 3dc8cb0
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions pkg/analysis_server/tool/completion_metrics/relevance_metrics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1309,9 +1309,18 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
/// Return the element kind of the element associated with the left-most
/// identifier that is a child of the [node].
ElementKind _leftMostKind(AstNode node) {
if (node is InstanceCreationExpression) {
return convertElementToElementKind(node.staticElement);
}
var element = _leftMostElement(node);
if (element == null) {
return ElementKind.UNKNOWN;
return null;
}
if (element is ClassElement) {
var parent = node.parent;
if (parent is Annotation && parent.arguments != null) {
element = parent.element;
}
}
return convertElementToElementKind(element);
}
Expand Down Expand Up @@ -1419,7 +1428,8 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
return -1;
}

/// Record information about the given [node] occurring the given [context].
/// Record information about the given [node] occurring in the given
/// [context].
void _recordDataForNode(String context, AstNode node,
{List<Keyword> allowedKeywords = noKeywords}) {
_recordElementKind(context, node);
Expand All @@ -1442,6 +1452,11 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
var kind = _leftMostKind(node);
if (kind != null) {
data.recordElementKind(context, kind);
if (node is Expression) {
data.recordElementKind('Expression', kind);
} else if (node is Statement) {
data.recordElementKind('Statement', kind);
}
}
}
}
Expand Down Expand Up @@ -1504,6 +1519,8 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
}

int superclassDepth = getSuperclassDepth();
// TODO(brianwilkerson) Consider cross referencing with the depth of the
// class containing the reference.
if (superclassDepth >= 0) {
_recordDistance('member (superclass)', superclassDepth);
} else {
Expand Down Expand Up @@ -1639,6 +1656,11 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
}
}
data.recordTokenType(context, type);
if (node is Expression) {
data.recordTokenType('Expression', type);
} else if (node is Statement) {
data.recordTokenType('Statement', type);
}
}
}
}
Expand Down

0 comments on commit 3dc8cb0

Please sign in to comment.