@@ -849,10 +849,18 @@ private void checkForClassFilesChangesInModule(DevModeContext.ModuleInfo module,
849849 .collect (Collectors .toSet ());
850850
851851 for (Path classFilePath : classFilePaths ) {
852- final Path sourceFilePath = retrieveSourceFilePathForClassFile (classFilePath , moduleChangedSourceFiles ,
853- module , cuf , timestampSet );
854-
852+ Path sourceFilePath = retrieveSourceFilePathForClassFile (classFilePath , moduleChangedSourceFiles ,
853+ module , cuf , timestampSet , false );
855854 if (sourceFilePath != null ) {
855+ if (!sourceFilePath .toFile ().exists ()) {
856+ // We need to refresh this in case the source file has changed
857+ // This can happen if you rename a kotlin file, the same class will now be provided by a new file
858+ var updated = retrieveSourceFilePathForClassFile (classFilePath , moduleChangedSourceFiles ,
859+ module , cuf , timestampSet , true );
860+ if (updated != null ) {
861+ sourceFilePath = updated ;
862+ }
863+ }
856864 if (!sourceFilePath .toFile ().exists ()) {
857865 // Source file has been deleted. Delete class and restart
858866 cleanUpClassFile (classFilePath , timestampSet );
@@ -888,9 +896,9 @@ private void checkForClassFilesChangesInModule(DevModeContext.ModuleInfo module,
888896
889897 private Path retrieveSourceFilePathForClassFile (Path classFilePath , List <Path > moduleChangedSourceFiles ,
890898 DevModeContext .ModuleInfo module , Function <DevModeContext .ModuleInfo , DevModeContext .CompilationUnit > cuf ,
891- TimestampSet timestampSet ) {
899+ TimestampSet timestampSet , boolean forceRefresh ) {
892900 Path sourceFilePath = timestampSet .classFilePathToSourceFilePath .get (classFilePath );
893- if (sourceFilePath == null || moduleChangedSourceFiles .contains (sourceFilePath )) {
901+ if (sourceFilePath == null || moduleChangedSourceFiles .contains (sourceFilePath ) || forceRefresh ) {
894902 sourceFilePath = compiler .findSourcePath (classFilePath , cuf .apply (module ).getSourcePaths (),
895903 cuf .apply (module ).getClassesPath ());
896904 }
0 commit comments