@Override
    public @Nullable PsiElement resolve() {
      PsiFile file = getContainingFile();
      VirtualFile dir = getDirectory();
      if (dir == null) return null;
      VirtualFile targetFile;
      String lastComponent = getRangeInElement().substring(getText());
      if (myExtension == null) {
        targetFile = dir.findChild(lastComponent);
      }
      else {
        targetFile = dir.findChild(lastComponent + '.' + myExtension);
        if (targetFile == null) {
          // Extension with another case?
          targetFile = ContainerUtil.find(
            dir.getChildren(),
            f -> f.getNameWithoutExtension().equals(lastComponent) && myExtension.equalsIgnoreCase(f.getExtension()));
        }
      }
      if (targetFile == null) return null;
      return file.getManager().findFile(targetFile);
    }
@Override
    public @Nullable PsiElement resolve()