@@ -275,6 +275,10 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
275275 /// The library containing the compilation unit being visited.
276276 LibraryElement enclosingLibrary;
277277
278+ /// A flag indicating whether we are currently in a context in which type
279+ /// parameters are visible.
280+ bool inGenericContext = false ;
281+
278282 /// The type provider associated with the current compilation unit.
279283 TypeProvider typeProvider;
280284
@@ -433,6 +437,8 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
433437
434438 @override
435439 void visitClassDeclaration (ClassDeclaration node) {
440+ var wasInGenericContext = inGenericContext;
441+ inGenericContext = inGenericContext || node.typeParameters != null ;
436442 data.recordPercentage (
437443 'Classes with type parameters' , node.typeParameters != null );
438444 var context = 'name' ;
@@ -453,10 +459,13 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
453459 allowedKeywords: memberKeywords);
454460 }
455461 super .visitClassDeclaration (node);
462+ inGenericContext = wasInGenericContext;
456463 }
457464
458465 @override
459466 void visitClassTypeAlias (ClassTypeAlias node) {
467+ var wasInGenericContext = inGenericContext;
468+ inGenericContext = inGenericContext || node.typeParameters != null ;
460469 _recordDataForNode ('ClassTypeAlias (superclass)' , node.superclass);
461470 var context = 'superclass' ;
462471 if (node.withClause != null ) {
@@ -465,6 +474,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
465474 }
466475 _recordTokenType ('ClassDeclaration ($context )' , node.implementsClause);
467476 super .visitClassTypeAlias (node);
477+ inGenericContext = wasInGenericContext;
468478 }
469479
470480 @override
@@ -660,6 +670,8 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
660670
661671 @override
662672 void visitExtensionDeclaration (ExtensionDeclaration node) {
673+ var wasInGenericContext = inGenericContext;
674+ inGenericContext = inGenericContext || node.typeParameters != null ;
663675 data.recordPercentage (
664676 'Extensions with type parameters' , node.typeParameters != null );
665677 _recordDataForNode ('ExtensionDeclaration (type)' , node.extendedType);
@@ -668,6 +680,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
668680 allowedKeywords: memberKeywords);
669681 }
670682 super .visitExtensionDeclaration (node);
683+ inGenericContext = wasInGenericContext;
671684 }
672685
673686 @override
@@ -787,8 +800,11 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
787800
788801 @override
789802 void visitFunctionTypeAlias (FunctionTypeAlias node) {
803+ var wasInGenericContext = inGenericContext;
804+ inGenericContext = inGenericContext || node.typeParameters != null ;
790805 // There are no completions.
791806 super .visitFunctionTypeAlias (node);
807+ inGenericContext = wasInGenericContext;
792808 }
793809
794810 @override
@@ -799,15 +815,21 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
799815
800816 @override
801817 void visitGenericFunctionType (GenericFunctionType node) {
818+ var wasInGenericContext = inGenericContext;
819+ inGenericContext = inGenericContext || node.typeParameters != null ;
802820 // There are no completions.
803821 super .visitGenericFunctionType (node);
822+ inGenericContext = wasInGenericContext;
804823 }
805824
806825 @override
807826 void visitGenericTypeAlias (GenericTypeAlias node) {
827+ var wasInGenericContext = inGenericContext;
828+ inGenericContext = inGenericContext || node.typeParameters != null ;
808829 _recordDataForNode ('GenericTypeAlias (functionType)' , node.functionType,
809830 allowedKeywords: [Keyword .FUNCTION ]);
810831 super .visitGenericTypeAlias (node);
832+ inGenericContext = wasInGenericContext;
811833 }
812834
813835 @override
@@ -957,6 +979,8 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
957979
958980 @override
959981 void visitMethodDeclaration (MethodDeclaration node) {
982+ var wasInGenericContext = inGenericContext;
983+ inGenericContext = inGenericContext || node.typeParameters != null ;
960984 // There are no completions.
961985 data.recordPercentage (
962986 'Methods with type parameters' , node.typeParameters != null );
@@ -976,6 +1000,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
9761000 }
9771001 }
9781002 super .visitMethodDeclaration (node);
1003+ inGenericContext = wasInGenericContext;
9791004 }
9801005
9811006 @override
@@ -1007,6 +1032,8 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
10071032
10081033 @override
10091034 void visitMixinDeclaration (MixinDeclaration node) {
1035+ var wasInGenericContext = inGenericContext;
1036+ inGenericContext = inGenericContext || node.typeParameters != null ;
10101037 data.recordPercentage (
10111038 'Mixins with type parameters' , node.typeParameters != null );
10121039 var context = 'name' ;
@@ -1023,6 +1050,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
10231050 allowedKeywords: memberKeywords);
10241051 }
10251052 super .visitMixinDeclaration (node);
1053+ inGenericContext = wasInGenericContext;
10261054 }
10271055
10281056 @override
@@ -1573,6 +1601,11 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
15731601 void _recordDataForNode (String context, AstNode node,
15741602 {List <Keyword > allowedKeywords = noKeywords}) {
15751603 _recordElementKind (context, node);
1604+ if (inGenericContext) {
1605+ _recordElementKind (context + ' - generic' , node);
1606+ } else {
1607+ _recordElementKind (context + ' - non-generic' , node);
1608+ }
15761609 _recordReferenceDepth (node);
15771610 _recordTokenDistance (node);
15781611 _recordTokenType (context, node, allowedKeywords: allowedKeywords);
0 commit comments