@@ -23,28 +23,37 @@ export class ArgumentList {
2323}
2424
2525export class Parameter {
26- public name : string
27- public type : Type
28- constructor ( name : string , type : Type ) {
29- this . name = name
30- this . type = type
26+ private _name : string
27+ private _type : Type
28+ private _isVarargs : boolean
29+
30+ constructor ( name : string , type : Type , isVarargs : boolean = false ) {
31+ this . _name = name
32+ this . _type = type
33+ this . _isVarargs = isVarargs
3134 }
3235
3336 public canBeAssigned ( type : Type ) : boolean {
34- if ( type instanceof Parameter ) return this . type . canBeAssigned ( type . type )
35- return this . type . canBeAssigned ( type )
37+ if ( type instanceof Parameter ) return this . _type . canBeAssigned ( type . _type )
38+ return this . _type . canBeAssigned ( type )
3639 }
3740
3841 public equals ( object : unknown ) : boolean {
39- return object instanceof Parameter && this . name === object . name && this . type . equals ( object . type )
42+ return (
43+ object instanceof Parameter && this . _name === object . _name && this . _type . equals ( object . _type )
44+ )
4045 }
4146
4247 public getName ( ) : string {
43- return this . name
48+ return this . _name
4449 }
4550
4651 public getType ( ) : Type {
47- return this . type
52+ return this . _type
53+ }
54+
55+ public isVarargs ( ) : boolean {
56+ return this . _isVarargs
4857 }
4958}
5059
@@ -65,11 +74,23 @@ export class ParameterList {
6574 }
6675
6776 public matchesArguments ( args : ArgumentList ) : boolean {
68- if ( this . length ( ) !== args . length ( ) ) return false
77+ const isLastParameterVarargs = this . get ( this . length ( ) - 1 ) . isVarargs ( )
78+ if ( isLastParameterVarargs && args . length ( ) < this . length ( ) - 1 ) return false
79+ if ( ! isLastParameterVarargs && args . length ( ) !== this . length ( ) ) return false
6980 for ( let i = 0 ; i < this . length ( ) ; i ++ ) {
7081 const parameter = this . get ( i )
71- const argument = args . get ( i )
72- if ( ! parameter . canBeAssigned ( argument ) ) return false
82+ if ( ! parameter . isVarargs ( ) ) {
83+ const argument = args . get ( i )
84+ if ( ! parameter . canBeAssigned ( argument ) ) return false
85+ continue
86+ }
87+
88+ for ( let j = i ; j < args . length ( ) ; j ++ ) {
89+ const argument = args . get ( j )
90+ if ( ! parameter . canBeAssigned ( argument ) ) return false
91+ }
92+
93+ break
7394 }
7495 return true
7596 }
@@ -120,11 +141,11 @@ export class MethodSignature extends Type {
120141 return this . parameters . length ( )
121142 }
122143
123- public mapParameters < T > ( mapper : ( name : string , type : Type ) => T ) : T [ ] {
144+ public mapParameters < T > ( mapper : ( name : string , type : Type , isVarargs : boolean ) => T ) : T [ ] {
124145 const result : T [ ] = [ ]
125146 for ( let i = 0 ; i < this . parameterSize ( ) ; i ++ ) {
126147 const parameter = this . parameters . get ( i )
127- result . push ( mapper ( parameter . getName ( ) , parameter . getType ( ) ) )
148+ result . push ( mapper ( parameter . getName ( ) , parameter . getType ( ) , parameter . isVarargs ( ) ) )
128149 }
129150 return result
130151 }
0 commit comments