@@ -223,22 +223,20 @@ private fun replaceYears(copyrightStatement: String): Pair<String, Set<Int>> {
223223 // Replace comma separated years.
224224 var matchResult = COMMA_SEPARATED_YEARS_REGEX .find(currentStatement)
225225
226- @Suppress(" UnsafeCallOnNullableType" )
227226 while (matchResult != null ) {
228- currentStatement = currentStatement.removeRange(matchResult.groups[ 2 ] !! .range)
229- currentStatement = currentStatement.replaceRange(matchResult.groups[ 1 ] !! .range, " $YEAR_PLACEHOLDER " )
230- resultYears + = matchResult.groups[ 1 ] !! .value.toInt()
227+ currentStatement = currentStatement.removeRange(matchResult.getGroup( 2 ) .range)
228+ currentStatement = currentStatement.replaceRange(matchResult.getGroup( 1 ) .range, " $YEAR_PLACEHOLDER " )
229+ resultYears + = matchResult.getGroup( 1 ) .value.toInt()
231230
232231 matchResult = COMMA_SEPARATED_YEARS_REGEX .find(currentStatement)
233232 }
234233
235234 // Replace single years.
236235 matchResult = SINGLE_YEARS_REGEX .find(currentStatement)
237236
238- @Suppress(" UnsafeCallOnNullableType" )
239237 while (matchResult != null ) {
240- currentStatement = currentStatement.replaceRange(matchResult.groups[ 1 ] !! .range, YEAR_PLACEHOLDER )
241- resultYears + = matchResult.groups[ 1 ] !! .value.toInt()
238+ currentStatement = currentStatement.replaceRange(matchResult.getGroup( 1 ) .range, YEAR_PLACEHOLDER )
239+ resultYears + = matchResult.getGroup( 1 ) .value.toInt()
242240
243241 matchResult = SINGLE_YEARS_REGEX .find(currentStatement)
244242 }
@@ -271,11 +269,10 @@ private fun replaceAllYearRanges(copyrightStatement: String): Pair<String, Set<I
271269 * string paired to the set of years.
272270 */
273271private fun replaceYearRange (copyrightStatement : String ): Pair <String , Set <Int >> {
274- @Suppress(" UnsafeCallOnNullableType" )
275272 YEAR_RANGE_REGEX .findAll(copyrightStatement).forEach { matchResult ->
276- val fromGroup = matchResult.groups[ 1 ] !!
277- val separatorGroup = matchResult.groups[ 2 ] !!
278- val toGroup = matchResult.groups[ 3 ] !!
273+ val fromGroup = matchResult.getGroup( 1 )
274+ val separatorGroup = matchResult.getGroup( 2 )
275+ val toGroup = matchResult.getGroup( 3 )
279276
280277 val fromYearString = fromGroup.value
281278 val fromYear = fromGroup.value.toInt()
@@ -314,3 +311,6 @@ private val Parts.key: String get() {
314311 val normalizedOwnerKey = owner.filter { it !in INVALID_OWNER_KEY_CHARS }.uppercase()
315312 return " $prefix :$normalizedOwnerKey "
316313}
314+
315+ @Suppress(" UnsafeCallOnNullableType" )
316+ private fun MatchResult.getGroup (index : Int ): MatchGroup = groups[index]!!
0 commit comments