public Signature collect ( String newName , String oldPattern ) { int start = - 1 ; int newCount = 0 ; int gatherCount = 0 ; Class < ? > type = null ; Pattern pattern = Pattern . compile ( oldPattern ) ; MethodType newType = type ( ) ; for ( int i = 0 ; i < argNames . length ; i ++ ) { if ( pattern . matcher ( argName ( i ) ) . matches ( ) ) { gatherCount ++ ; newType = newType . dropParameterTypes ( newCount , newCount + 1 ) ; Class < ? > argType = argType ( i ) ; if ( start == - 1 ) start = i ; if ( type == null ) { type = argType ; } else { if ( argType != type ) { throw new InvalidTransformException ( "arguments matching " + pattern + " are not all of the same type" ) ; } } } else { newCount ++ ; } } if ( start != - 1 ) { String [ ] newNames = new String [ newCount + 1 ] ; // pre System . arraycopy ( argNames , 0 , newNames , 0 , start ) ; // vararg newNames [ start ] = newName ; newType = newType . insertParameterTypes ( start , Array . newInstance ( type , 0 ) . getClass ( ) ) ; // post if ( newCount + 1 > start ) { // args not at end System . arraycopy ( argNames , start + gatherCount , newNames , start + 1 , newCount - start ) ; } return new Signature ( newType , newNames ) ; } return this ; }
Collect sequential arguments matching pattern into an array . They must have the same type .