public CSTNode set ( int index , CSTNode element ) { if ( elements == null ) { throw new GroovyBugError ( "attempt to set() on a EMPTY Reduction" ) ; } if ( index == 0 && ! ( element instanceof Token ) ) { // // It's not the greatest of design that the interface allows this, but it // is a tradeoff with convenience, and the convenience is more important. throw new GroovyBugError ( "attempt to set() a non-Token as root of a Reduction" ) ; } // // Fill slots with nulls, if necessary. int count = elements . size ( ) ; if ( index >= count ) { for ( int i = count ; i <= index ; i ++ ) { elements . add ( null ) ; } } // // Then set in the element. elements . set ( index , element ) ; return element ; }
Sets an element in at the specified index .