Skip to content

Commit

Permalink
Handle $ at the end of class names for better Scala support
Browse files Browse the repository at this point in the history
  • Loading branch information
dpolivaev committed Mar 21, 2024
1 parent 1ed20d5 commit 024a756
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ public static String ensureSimpleName(String name) {
int lastIndexOfDot = name.lastIndexOf('.');
String partAfterDot = lastIndexOfDot >= 0 ? name.substring(lastIndexOfDot + 1) : name;

int lastIndexOf$ = partAfterDot.lastIndexOf('$');
int lastFinalNon$ = partAfterDot.length() - 1;
while(lastFinalNon$ > 0 && partAfterDot.charAt(lastFinalNon$) == '$') {
lastFinalNon$--;
}
int lastIndexOf$ = lastFinalNon$ > 0 ? partAfterDot.lastIndexOf('$', lastFinalNon$ - 1): -1;
String simpleNameCandidate = lastIndexOf$ >= 0 ? partAfterDot.substring(lastIndexOf$ + 1) : partAfterDot;

for (int i = 0; i < simpleNameCandidate.length(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ public static Object[][] simple_name_test_cases() {
$("", ""),
$("Dummy", "Dummy"),
$("org.example.Dummy", "Dummy"),
$("org.example.Dummy$", "Dummy$"),
$("org.example.Dummy$$", "Dummy$$"),
$("org.example.Dummy$$$", "Dummy$$$"),
$("org.example.$$$", "$$$"),
$("org.example.Dummy$123", ""),
$("org.example.Dummy$NestedClass", "NestedClass"),
$("org.example.Dummy$NestedClass$", "NestedClass$"),
$("org.example.Dummy$NestedClass123", "NestedClass123"),
$("org.example.Dummy$NestedClass$123", ""),
$("org.example.Dummy$NestedClass$MoreNestedClass", "MoreNestedClass"),
Expand Down

0 comments on commit 024a756

Please sign in to comment.