use of org.jetbrains.java.generate.config.ConflictResolutionPolicy in project intellij-community by JetBrains.
the class GenerateToStringActionHandlerImpl method doExecuteAction.
private static void doExecuteAction(@NotNull final Project project, @NotNull final PsiClass clazz, final Editor editor) {
if (!FileModificationService.getInstance().preparePsiElementsForWrite(clazz)) {
return;
}
logger.debug("+++ doExecuteAction - START +++");
if (logger.isDebugEnabled()) {
logger.debug("Current project " + project.getName());
}
final PsiElementClassMember[] dialogMembers = buildMembersToShow(clazz);
final MemberChooserHeaderPanel header = new MemberChooserHeaderPanel(clazz);
logger.debug("Displaying member chooser dialog");
final MemberChooser<PsiElementClassMember> chooser = new MemberChooser<PsiElementClassMember>(dialogMembers, true, true, project, PsiUtil.isLanguageLevel5OrHigher(clazz), header) {
@Nullable
@Override
protected String getHelpId() {
return "editing.altInsert.tostring";
}
};
//noinspection DialogTitleCapitalization
chooser.setTitle("Generate toString()");
chooser.setCopyJavadocVisible(false);
chooser.selectElements(getPreselection(clazz, dialogMembers));
header.setChooser(chooser);
chooser.show();
if (DialogWrapper.OK_EXIT_CODE == chooser.getExitCode()) {
Collection<PsiMember> selectedMembers = GenerationUtil.convertClassMembersToPsiMembers(chooser.getSelectedElements());
final TemplateResource template = header.getSelectedTemplate();
ToStringTemplatesManager.getInstance().setDefaultTemplate(template);
if (template.isValidTemplate()) {
final GenerateToStringWorker worker = new GenerateToStringWorker(clazz, editor, chooser.isInsertOverrideAnnotation());
// decide what to do if the method already exists
ConflictResolutionPolicy resolutionPolicy = worker.exitsMethodDialog(template);
WriteAction.run(() -> {
try {
worker.execute(selectedMembers, template, resolutionPolicy);
} catch (Exception e) {
GenerationUtil.handleException(project, e);
}
});
} else {
HintManager.getInstance().showErrorHint(editor, "toString() template '" + template.getFileName() + "' is invalid");
}
}
logger.debug("+++ doExecuteAction - END +++");
}
Aggregations