@Override
    public <E extends PsiElement> E getWritable(E element) {
      if (element == null) return null;
      if (element instanceof PsiDirectory dir) {
        VirtualFile file = dir.getVirtualFile();
        if (file instanceof ChangedVirtualDirectory) return element;
        ChangedDirectoryInfo directory = myChangedDirectories.computeIfAbsent(file, f -> ChangedDirectoryInfo.create(dir));
        @SuppressWarnings("unchecked") E result = (E)directory.psiDirectory;
        return result;
      }
      PsiFile file = element.getContainingFile();
      if (file.getViewProvider().getVirtualFile() instanceof ChangedVirtualDirectory.AddedVirtualFile) {
        return element;
      }
      PsiFile originalFile = ObjectUtils.coalesce(file.getUserData(ORIGINAL_FILE_FOR_INJECTION), file.getOriginalFile());
      if (originalFile != file) {
        FileTracker tracker = tracker(originalFile);
        if (tracker.myCopyFile == file) {
          return element;
        }
      }
      return tracker(file).getCopy(element);
    }
@Override
    public <E extends PsiElement> E getWritable(E element)