@ -22,6 +22,8 @@ import java.io.IOException;
@@ -22,6 +22,8 @@ import java.io.IOException;
import java.io.InputStreamReader ;
import java.io.StringReader ;
import java.nio.charset.StandardCharsets ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
import com.thoughtworks.qdox.JavaProjectBuilder ;
import com.thoughtworks.qdox.model.JavaClass ;
@ -189,7 +191,30 @@ public final class SourceFile extends DynamicFile implements AssertProvider<Sour
@@ -189,7 +191,30 @@ public final class SourceFile extends DynamicFile implements AssertProvider<Sour
}
private static String makeRecordsLookLikeClasses ( String content ) {
return content . replaceAll ( "record\\s(\\S+)\\(\\X+?\\)" , "class $1" ) ;
Pattern pattern = Pattern . compile ( "record\\s(\\S+)\\(" ) ;
Matcher matcher = pattern . matcher ( content ) ;
if ( matcher . find ( ) ) {
StringBuilder result = new StringBuilder ( ) ;
result . append ( content . substring ( 0 , matcher . start ( ) ) + "class" ) ;
result . append ( content . substring ( matcher . start ( ) + 6 , matcher . end ( ) - 1 ) ) ;
int parenthesesCount = 1 ;
for ( int i = matcher . end ( ) ; i < content . length ( ) ; i + + ) {
char ch = content . charAt ( i ) ;
if ( parenthesesCount > 0 ) {
if ( ch = = '(' ) {
parenthesesCount + + ;
}
else if ( ch = = ')' ) {
parenthesesCount - - ;
}
}
else {
result . append ( ch ) ;
}
}
return makeRecordsLookLikeClasses ( result . toString ( ) ) ;
}
return content ;
}
/ * *