@@ -275,6 +275,10 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
275
275
/// The library containing the compilation unit being visited.
276
276
LibraryElement enclosingLibrary;
277
277
278
+ /// A flag indicating whether we are currently in a context in which type
279
+ /// parameters are visible.
280
+ bool inGenericContext = false ;
281
+
278
282
/// The type provider associated with the current compilation unit.
279
283
TypeProvider typeProvider;
280
284
@@ -433,6 +437,8 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
433
437
434
438
@override
435
439
void visitClassDeclaration (ClassDeclaration node) {
440
+ var wasInGenericContext = inGenericContext;
441
+ inGenericContext = inGenericContext || node.typeParameters != null ;
436
442
data.recordPercentage (
437
443
'Classes with type parameters' , node.typeParameters != null );
438
444
var context = 'name' ;
@@ -453,10 +459,13 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
453
459
allowedKeywords: memberKeywords);
454
460
}
455
461
super .visitClassDeclaration (node);
462
+ inGenericContext = wasInGenericContext;
456
463
}
457
464
458
465
@override
459
466
void visitClassTypeAlias (ClassTypeAlias node) {
467
+ var wasInGenericContext = inGenericContext;
468
+ inGenericContext = inGenericContext || node.typeParameters != null ;
460
469
_recordDataForNode ('ClassTypeAlias (superclass)' , node.superclass);
461
470
var context = 'superclass' ;
462
471
if (node.withClause != null ) {
@@ -465,6 +474,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
465
474
}
466
475
_recordTokenType ('ClassDeclaration ($context )' , node.implementsClause);
467
476
super .visitClassTypeAlias (node);
477
+ inGenericContext = wasInGenericContext;
468
478
}
469
479
470
480
@override
@@ -660,6 +670,8 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
660
670
661
671
@override
662
672
void visitExtensionDeclaration (ExtensionDeclaration node) {
673
+ var wasInGenericContext = inGenericContext;
674
+ inGenericContext = inGenericContext || node.typeParameters != null ;
663
675
data.recordPercentage (
664
676
'Extensions with type parameters' , node.typeParameters != null );
665
677
_recordDataForNode ('ExtensionDeclaration (type)' , node.extendedType);
@@ -668,6 +680,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
668
680
allowedKeywords: memberKeywords);
669
681
}
670
682
super .visitExtensionDeclaration (node);
683
+ inGenericContext = wasInGenericContext;
671
684
}
672
685
673
686
@override
@@ -787,8 +800,11 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
787
800
788
801
@override
789
802
void visitFunctionTypeAlias (FunctionTypeAlias node) {
803
+ var wasInGenericContext = inGenericContext;
804
+ inGenericContext = inGenericContext || node.typeParameters != null ;
790
805
// There are no completions.
791
806
super .visitFunctionTypeAlias (node);
807
+ inGenericContext = wasInGenericContext;
792
808
}
793
809
794
810
@override
@@ -799,15 +815,21 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
799
815
800
816
@override
801
817
void visitGenericFunctionType (GenericFunctionType node) {
818
+ var wasInGenericContext = inGenericContext;
819
+ inGenericContext = inGenericContext || node.typeParameters != null ;
802
820
// There are no completions.
803
821
super .visitGenericFunctionType (node);
822
+ inGenericContext = wasInGenericContext;
804
823
}
805
824
806
825
@override
807
826
void visitGenericTypeAlias (GenericTypeAlias node) {
827
+ var wasInGenericContext = inGenericContext;
828
+ inGenericContext = inGenericContext || node.typeParameters != null ;
808
829
_recordDataForNode ('GenericTypeAlias (functionType)' , node.functionType,
809
830
allowedKeywords: [Keyword .FUNCTION ]);
810
831
super .visitGenericTypeAlias (node);
832
+ inGenericContext = wasInGenericContext;
811
833
}
812
834
813
835
@override
@@ -957,6 +979,8 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
957
979
958
980
@override
959
981
void visitMethodDeclaration (MethodDeclaration node) {
982
+ var wasInGenericContext = inGenericContext;
983
+ inGenericContext = inGenericContext || node.typeParameters != null ;
960
984
// There are no completions.
961
985
data.recordPercentage (
962
986
'Methods with type parameters' , node.typeParameters != null );
@@ -976,6 +1000,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
976
1000
}
977
1001
}
978
1002
super .visitMethodDeclaration (node);
1003
+ inGenericContext = wasInGenericContext;
979
1004
}
980
1005
981
1006
@override
@@ -1007,6 +1032,8 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
1007
1032
1008
1033
@override
1009
1034
void visitMixinDeclaration (MixinDeclaration node) {
1035
+ var wasInGenericContext = inGenericContext;
1036
+ inGenericContext = inGenericContext || node.typeParameters != null ;
1010
1037
data.recordPercentage (
1011
1038
'Mixins with type parameters' , node.typeParameters != null );
1012
1039
var context = 'name' ;
@@ -1023,6 +1050,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
1023
1050
allowedKeywords: memberKeywords);
1024
1051
}
1025
1052
super .visitMixinDeclaration (node);
1053
+ inGenericContext = wasInGenericContext;
1026
1054
}
1027
1055
1028
1056
@override
@@ -1573,6 +1601,11 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
1573
1601
void _recordDataForNode (String context, AstNode node,
1574
1602
{List <Keyword > allowedKeywords = noKeywords}) {
1575
1603
_recordElementKind (context, node);
1604
+ if (inGenericContext) {
1605
+ _recordElementKind (context + ' - generic' , node);
1606
+ } else {
1607
+ _recordElementKind (context + ' - non-generic' , node);
1608
+ }
1576
1609
_recordReferenceDepth (node);
1577
1610
_recordTokenDistance (node);
1578
1611
_recordTokenType (context, node, allowedKeywords: allowedKeywords);
0 commit comments