private static @Nullable Location<PsiElement> calcLocation(@NotNull DataContext dataContext, Module module) {
    Location<?> location = Location.DATA_KEY.getData(dataContext);
    if (location != null) {
      //noinspection unchecked
      return (Location<PsiElement>)location;
    }
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
      return null;
    }
    PsiElement element = getSelectedPsiElement(dataContext, project);
    if (element == null) {
      return null;
    }
    return new PsiLocation<>(project, module, element);
  }
private static @Nullable Location<PsiElement> calcLocation(@NotNull DataContext dataContext, Module module)