Skip to content

Commit 297cad2

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Include FormalParameterFragment.typeParameters and formalParameters into text output.
Update _InfoBuilder to include offsets of these fragments. Change-Id: I4594b2c4f0e37477130c541e3c27a3ca33c96535 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439983 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 0c3de08 commit 297cad2

File tree

11 files changed

+168
-59
lines changed

11 files changed

+168
-59
lines changed

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

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

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

pkg/analyzer/lib/src/summary2/informative_data.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -964,19 +964,21 @@ class _InfoBuilder {
964964

965965
_InfoFormalParameter _buildFormalParameter(FormalParameter node) {
966966
var notDefault = node.notDefault;
967+
968+
var (typeParameters, parameters) = switch (notDefault) {
969+
FunctionTypedFormalParameter p => (p.typeParameters, p.parameters),
970+
FieldFormalParameter p => (p.typeParameters, p.parameters),
971+
SuperFormalParameter p => (p.typeParameters, p.parameters),
972+
_ => (null, null),
973+
};
974+
967975
return _InfoFormalParameter(
968976
firstTokenOffset: node.offset,
969977
codeOffset: node.offset,
970978
codeLength: node.length,
971979
nameOffset2: node.name?.offsetIfNotEmpty,
972-
typeParameters:
973-
notDefault is FunctionTypedFormalParameter
974-
? _buildTypeParameters(notDefault.typeParameters)
975-
: [],
976-
parameters:
977-
notDefault is FunctionTypedFormalParameter
978-
? _buildFormalParameters(notDefault.parameters)
979-
: [],
980+
typeParameters: _buildTypeParameters(typeParameters),
981+
parameters: _buildFormalParameters(parameters),
980982
);
981983
}
982984

pkg/analyzer/test/src/summary/element_text.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ class _Element2Writer extends _AbstractElementWriter {
719719
}
720720

721721
void _writeFormalParameterFragment(FormalParameterFragment f) {
722+
f as FormalParameterFragmentImpl;
722723
// if (f.isNamed && f.enclosingFragment is ExecutableFragment) {
723724
// expect(f.reference, isNotNull);
724725
// } else {
@@ -756,8 +757,18 @@ class _Element2Writer extends _AbstractElementWriter {
756757
// _writeType('type', f.type);
757758
_writeMetadata(f.metadata);
758759
// _writeCodeRange(f);
759-
// _writeTypeParameterElements(e.typeParameters);
760-
// _writeFragmentList('parameters', f, f.parameters2, _writeFormalParameterFragments);
760+
_writeFragmentList(
761+
'typeParameters',
762+
f,
763+
f.typeParameters,
764+
_writeTypeParameterFragment,
765+
);
766+
_writeFragmentList(
767+
'parameters',
768+
f,
769+
f.parameters,
770+
_writeFormalParameterFragment,
771+
);
761772
_writeVariableFragmentInitializer(f);
762773
// _writeNonSyntheticElement(e);
763774
// _writeFieldFormalParameterField(e);

pkg/analyzer/test/src/summary/elements/class_test.dart

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -543,15 +543,18 @@ library
543543
formalParameters
544544
#F4 this.x @28
545545
element: <testLibrary>::@class::C::@constructor::new::@formalParameter::x
546+
parameters
547+
#F5 b @37
548+
element: b@37
546549
getters
547-
#F5 synthetic x
550+
#F6 synthetic x
548551
element: <testLibrary>::@class::C::@getter::x
549552
returnType: dynamic
550553
setters
551-
#F6 synthetic x
554+
#F7 synthetic x
552555
element: <testLibrary>::@class::C::@setter::x
553556
formalParameters
554-
#F7 _x
557+
#F8 _x
555558
element: <testLibrary>::@class::C::@setter::x::@formalParameter::_x
556559
classes
557560
class C
@@ -574,21 +577,21 @@ library
574577
type: dynamic Function(double)
575578
formalParameters
576579
#E1 requiredPositional b
577-
firstFragment: #F8
580+
firstFragment: #F5
578581
type: double
579582
getters
580583
synthetic x
581584
reference: <testLibrary>::@class::C::@getter::x
582-
firstFragment: #F5
585+
firstFragment: #F6
583586
returnType: dynamic
584587
variable: <testLibrary>::@class::C::@field::x
585588
setters
586589
synthetic x
587590
reference: <testLibrary>::@class::C::@setter::x
588-
firstFragment: #F6
591+
firstFragment: #F7
589592
formalParameters
590593
#E2 requiredPositional _x
591-
firstFragment: #F7
594+
firstFragment: #F8
592595
type: dynamic
593596
returnType: void
594597
''');
@@ -621,15 +624,18 @@ library
621624
formalParameters
622625
#F4 this.x @32
623626
element: <testLibrary>::@class::C::@constructor::new::@formalParameter::x
627+
parameters
628+
#F5 b @41
629+
element: b@41
624630
getters
625-
#F5 synthetic x
631+
#F6 synthetic x
626632
element: <testLibrary>::@class::C::@getter::x
627633
returnType: dynamic
628634
setters
629-
#F6 synthetic x
635+
#F7 synthetic x
630636
element: <testLibrary>::@class::C::@setter::x
631637
formalParameters
632-
#F7 _x
638+
#F8 _x
633639
element: <testLibrary>::@class::C::@setter::x::@formalParameter::_x
634640
classes
635641
class C
@@ -652,21 +658,21 @@ library
652658
type: int Function(double)
653659
formalParameters
654660
#E1 requiredPositional b
655-
firstFragment: #F8
661+
firstFragment: #F5
656662
type: double
657663
getters
658664
synthetic x
659665
reference: <testLibrary>::@class::C::@getter::x
660-
firstFragment: #F5
666+
firstFragment: #F6
661667
returnType: dynamic
662668
variable: <testLibrary>::@class::C::@field::x
663669
setters
664670
synthetic x
665671
reference: <testLibrary>::@class::C::@setter::x
666-
firstFragment: #F6
672+
firstFragment: #F7
667673
formalParameters
668674
#E2 requiredPositional _x
669-
firstFragment: #F7
675+
firstFragment: #F8
670676
type: dynamic
671677
returnType: void
672678
''');
@@ -699,15 +705,23 @@ library
699705
formalParameters
700706
#F4 this.f @43
701707
element: <testLibrary>::@class::C::@constructor::new::@formalParameter::f
708+
typeParameters
709+
#F5 T @45
710+
element: #E0 T
711+
#F6 U @48
712+
element: #E1 U
713+
parameters
714+
#F7 t @53
715+
element: t@53
702716
getters
703-
#F5 synthetic f
717+
#F8 synthetic f
704718
element: <testLibrary>::@class::C::@getter::f
705719
returnType: dynamic Function()
706720
setters
707-
#F6 synthetic f
721+
#F9 synthetic f
708722
element: <testLibrary>::@class::C::@setter::f
709723
formalParameters
710-
#F7 _f
724+
#F10 _f
711725
element: <testLibrary>::@class::C::@setter::f::@formalParameter::_f
712726
classes
713727
class C
@@ -725,31 +739,31 @@ library
725739
reference: <testLibrary>::@class::C::@constructor::new
726740
firstFragment: #F3
727741
formalParameters
728-
#E0 requiredPositional final f
742+
#E2 requiredPositional final f
729743
firstFragment: #F4
730744
type: List<U> Function<T, U>(T)
731745
typeParameters
732-
#E1 T
733-
firstFragment: #F8
734-
#E2 U
735-
firstFragment: #F9
746+
#E0 T
747+
firstFragment: #F5
748+
#E1 U
749+
firstFragment: #F6
736750
formalParameters
737751
#E3 requiredPositional t
738-
firstFragment: #F10
752+
firstFragment: #F7
739753
type: T
740754
getters
741755
synthetic f
742756
reference: <testLibrary>::@class::C::@getter::f
743-
firstFragment: #F5
757+
firstFragment: #F8
744758
returnType: dynamic Function()
745759
variable: <testLibrary>::@class::C::@field::f
746760
setters
747761
synthetic f
748762
reference: <testLibrary>::@class::C::@setter::f
749-
firstFragment: #F6
763+
firstFragment: #F9
750764
formalParameters
751765
#E4 requiredPositional _f
752-
firstFragment: #F7
766+
firstFragment: #F10
753767
type: dynamic Function()
754768
returnType: void
755769
''');
@@ -2898,6 +2912,12 @@ library
28982912
formalParameters
28992913
#F6 super.a @63
29002914
element: <testLibrary>::@class::B::@constructor::new::@formalParameter::a
2915+
typeParameters
2916+
#F7 T @65
2917+
element: #E0 T
2918+
parameters
2919+
#F8 d @82
2920+
element: d@82
29012921
classes
29022922
class A
29032923
reference: <testLibrary>::@class::A
@@ -2907,7 +2927,7 @@ library
29072927
reference: <testLibrary>::@class::A::@constructor::new
29082928
firstFragment: #F2
29092929
formalParameters
2910-
#E0 requiredPositional a
2930+
#E1 requiredPositional a
29112931
firstFragment: #F3
29122932
type: Object?
29132933
class B
@@ -2919,11 +2939,11 @@ library
29192939
reference: <testLibrary>::@class::B::@constructor::new
29202940
firstFragment: #F5
29212941
formalParameters
2922-
#E1 requiredPositional final a
2942+
#E2 requiredPositional final a
29232943
firstFragment: #F6
29242944
type: int Function<T extends num>(T)?
29252945
typeParameters
2926-
#E2 T
2946+
#E0 T
29272947
firstFragment: #F7
29282948
bound: num
29292949
formalParameters
@@ -13187,6 +13207,9 @@ library
1318713207
formalParameters
1318813208
#F6 x @25
1318913209
element: <testLibrary>::@class::C::@method::f::@formalParameter::x
13210+
parameters
13211+
#F7 u @29
13212+
element: u@29
1319013213
classes
1319113214
class C
1319213215
reference: <testLibrary>::@class::C

pkg/analyzer/test/src/summary/elements/default_value_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ library
314314
formalParameters
315315
#F2 g @8
316316
element: <testLibrary>::@function::f::@formalParameter::g
317+
parameters
318+
#F3 a @11
319+
element: a@11
317320
functions
318321
f
319322
reference: <testLibrary>::@function::f

pkg/analyzer/test/src/summary/elements/enum_test.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -894,14 +894,17 @@ library
894894
formalParameters
895895
#F6 this.x @44
896896
element: <testLibrary>::@enum::E::@constructor::new::@formalParameter::x
897+
parameters
898+
#F7 a @53
899+
element: a@53
897900
getters
898-
#F7 synthetic v
901+
#F8 synthetic v
899902
element: <testLibrary>::@enum::E::@getter::v
900903
returnType: E
901-
#F8 synthetic values
904+
#F9 synthetic values
902905
element: <testLibrary>::@enum::E::@getter::values
903906
returnType: List<E>
904-
#F9 synthetic x
907+
#F10 synthetic x
905908
element: <testLibrary>::@enum::E::@getter::x
906909
returnType: dynamic
907910
enums
@@ -941,22 +944,22 @@ library
941944
type: int Function(double)
942945
formalParameters
943946
#E1 requiredPositional a
944-
firstFragment: #F10
947+
firstFragment: #F7
945948
type: double
946949
getters
947950
synthetic static v
948951
reference: <testLibrary>::@enum::E::@getter::v
949-
firstFragment: #F7
952+
firstFragment: #F8
950953
returnType: E
951954
variable: <testLibrary>::@enum::E::@field::v
952955
synthetic static values
953956
reference: <testLibrary>::@enum::E::@getter::values
954-
firstFragment: #F8
957+
firstFragment: #F9
955958
returnType: List<E>
956959
variable: <testLibrary>::@enum::E::@field::values
957960
synthetic x
958961
reference: <testLibrary>::@enum::E::@getter::x
959-
firstFragment: #F9
962+
firstFragment: #F10
960963
returnType: dynamic
961964
variable: <testLibrary>::@enum::E::@field::x
962965
''');

pkg/analyzer/test/src/summary/elements/formal_parameter_test.dart

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,11 @@ library
370370
formalParameters
371371
#F4 g @12
372372
element: <testLibrary>::@class::C::@method::f::@formalParameter::g
373+
parameters
374+
#F5 x @14
375+
element: x@14
376+
#F6 y @17
377+
element: y@17
373378
classes
374379
class C
375380
reference: <testLibrary>::@class::C
@@ -423,6 +428,9 @@ library
423428
formalParameters
424429
#F6 g @20
425430
element: <testLibrary>::@class::C::@method::f::@formalParameter::g
431+
parameters
432+
#F7 x @24
433+
element: x@24
426434
classes
427435
class C
428436
reference: <testLibrary>::@class::C
@@ -551,18 +559,26 @@ library
551559
formalParameters
552560
#F2 a @9
553561
element: <testLibrary>::@function::f::@formalParameter::a
562+
typeParameters
563+
#F3 T @11
564+
element: #E0 T
565+
#F4 U @14
566+
element: #E1 U
567+
parameters
568+
#F5 u @19
569+
element: u@19
554570
functions
555571
f
556572
reference: <testLibrary>::@function::f
557573
firstFragment: #F1
558574
formalParameters
559-
#E0 requiredPositional a
575+
#E2 requiredPositional a
560576
firstFragment: #F2
561577
type: T Function<T, U>(U)
562578
typeParameters
563-
#E1 T
579+
#E0 T
564580
firstFragment: #F3
565-
#E2 U
581+
#E1 U
566582
firstFragment: #F4
567583
formalParameters
568584
#E3 requiredPositional u

pkg/analyzer/test/src/summary/elements/function_type_annotation_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ library
149149
formalParameters
150150
#F2 p @37
151151
element: <testLibrary>::@function::f::@formalParameter::p
152+
parameters
153+
#F3 c @43
154+
element: c@43
152155
functions
153156
f
154157
reference: <testLibrary>::@function::f

0 commit comments

Comments
 (0)