use of org.jetbrains.plugins.cucumber.inspections.model.CreateStepDefinitionFileModel in project intellij-plugins by JetBrains.
the class CucumberCreateStepFixBase method askUserForFilePath.
@Nullable
private static CreateStepDefinitionFileModel askUserForFilePath(@NotNull final GherkinStep step) {
final InputValidator validator = new InputValidator() {
public boolean checkInput(final String filePath) {
return !StringUtil.isEmpty(filePath);
}
public boolean canClose(final String fileName) {
return true;
}
};
Map<BDDFrameworkType, String> supportedFileTypesAndDefaultFileNames = new HashMap<>();
Map<BDDFrameworkType, PsiDirectory> fileTypeToDefaultDirectoryMap = new HashMap<>();
for (CucumberJvmExtensionPoint e : Extensions.getExtensions(CucumberJvmExtensionPoint.EP_NAME)) {
if (e instanceof OptionalStepDefinitionExtensionPoint) {
// Skip if framework file creation support is optional
if (!((OptionalStepDefinitionExtensionPoint) e).participateInStepDefinitionCreation(step)) {
continue;
}
}
supportedFileTypesAndDefaultFileNames.put(e.getStepFileType(), e.getStepDefinitionCreator().getDefaultStepFileName(step));
fileTypeToDefaultDirectoryMap.put(e.getStepFileType(), e.getStepDefinitionCreator().getDefaultStepDefinitionFolder(step));
}
CreateStepDefinitionFileModel model = new CreateStepDefinitionFileModel(step.getProject(), supportedFileTypesAndDefaultFileNames, fileTypeToDefaultDirectoryMap);
CreateStepDefinitionFileDialog createStepDefinitionFileDialog = new CreateStepDefinitionFileDialog(step.getProject(), model, validator);
if (createStepDefinitionFileDialog.showAndGet()) {
return model;
} else {
return null;
}
}
use of org.jetbrains.plugins.cucumber.inspections.model.CreateStepDefinitionFileModel in project intellij-plugins by JetBrains.
the class CucumberCreateStepFixBase method createStepDefinitionFile.
private static void createStepDefinitionFile(final GherkinStep step) {
final PsiFile featureFile = step.getContainingFile();
assert featureFile != null;
final CreateStepDefinitionFileModel model = askUserForFilePath(step);
if (model == null) {
return;
}
String filePath = FileUtil.toSystemDependentName(model.getFilePath());
final BDDFrameworkType frameworkType = model.getSelectedFileType();
// show error if file already exists
Project project = step.getProject();
if (LocalFileSystem.getInstance().findFileByPath(filePath) == null) {
final String parentDirPath = model.getDirectory().getVirtualFile().getPath();
ApplicationManager.getApplication().invokeLater(() -> CommandProcessor.getInstance().executeCommand(project, () -> {
try {
VirtualFile parentDir = VfsUtil.createDirectories(parentDirPath);
PsiDirectory parentPsiDir = PsiManager.getInstance(project).findDirectory(parentDir);
assert parentPsiDir != null;
PsiFile newFile = CucumberStepsIndex.getInstance(project).createStepDefinitionFile(model.getDirectory(), model.getFileName(), frameworkType);
Pair<PsiFile, BDDFrameworkType> pair = Pair.create(newFile, frameworkType);
createStepDefinition(step, pair);
} catch (IOException e) {
LOG.error(e);
}
}, CucumberBundle.message("cucumber.quick.fix.create.step.command.name.create"), null));
} else {
Messages.showErrorDialog(project, CucumberBundle.message("cucumber.quick.fix.create.step.error.already.exist.msg", filePath), CucumberBundle.message("cucumber.quick.fix.create.step.file.name.title"));
}
}
Aggregations