@@ -170,11 +170,22 @@ public void started(TaskEvent event) {
170
170
* if no source file was found for the given name
171
171
*/
172
172
byte [] compileJavaFileByName (String name ) {
173
+ // Initially, determine existing directory from class name.
174
+ // [pack$age . ] na$me [ $ enclo$ed [$ dee$per] ]
175
+ var lastDot = name .lastIndexOf ("." );
176
+ var packageName = lastDot == -1 ? "" : name .substring (0 , lastDot );
177
+ var packagePath = descriptor .sourceRootPath ().resolve (packageName .replace ('.' , '/' ));
178
+ // Trivial case: no matching directory exists
179
+ if (!Files .isDirectory (packagePath )) return null ;
180
+
173
181
// Determine source file from class name.
174
- var firstDollarSign = name .indexOf ('$' ); // [package . ] name [ $ enclosed [$ deeper] ]
175
- var packageAndClassName = firstDollarSign == -1 ? name : name .substring (0 , firstDollarSign );
176
- var path = packageAndClassName .replace ('.' , '/' ) + ".java" ;
177
- var file = descriptor .sourceRootPath ().resolve (path );
182
+ var candidate = name .substring (lastDot + 1 , name .length ()); // "na$me$enclo$ed$dee$per"
183
+ // For each `$` in the name try to find the first matching compilation unit.
184
+ while (candidate .contains ("$" )) {
185
+ if (Files .exists (packagePath .resolve (candidate + ".java" ))) break ;
186
+ candidate = candidate .substring (0 , candidate .lastIndexOf ("$" ));
187
+ }
188
+ var file = packagePath .resolve (candidate + ".java" );
178
189
179
190
// Trivial case: no matching source file exists
180
191
if (!Files .exists (file )) return null ;
0 commit comments