com.intellij.openapi.application.RunResult Java Examples
The following examples show how to use
com.intellij.openapi.application.RunResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NewClassAction.java From json2java4idea with Apache License 2.0 | 5 votes |
@Override public void onOk(@Nonnull NewClassDialog dialog) { final PsiDirectory directory = ideView.getOrChooseDirectory(); if (directory == null) { dialog.cancel(); return; } try { final CommandActionFactory actionFactory = commandActionFactoryProvider.get(); final JavaConverterFactory converterFactory = javaConverterFactoryProvider.get(); final NewClassCommandAction command = actionFactory.create( dialog.getClassName(), dialog.getJson(), directory, converterFactory.create(settings) ); final ProgressManager progressManager = ProgressManager.getInstance(); progressManager.runProcessWithProgressSynchronously(() -> { final ProgressIndicator indicator = progressManager.getProgressIndicator(); if (indicator != null) { indicator.setIndeterminate(true); indicator.setText(bundle.message("progress.text", dialog.getClassName())); } final RunResult<PsiFile> result = command.execute(); return result.getResultObject(); }, bundle.message("progress.title"), false, project); dialog.close(); } catch (RuntimeException e) { LOGGER.warn("Unable to create a class", e); onError(dialog, e.getCause()); } }
Example #2
Source File: DocGenerateAction.java From CodeMaker with Apache License 2.0 | 5 votes |
/** * Create doc for method. * * @param psiMethod the psi method * @param psiElementFactory the psi element factory */ private void createDocForMethod(PsiMethod psiMethod, PsiElementFactory psiElementFactory) { try { checkFilesAccess(psiMethod); PsiDocComment psiDocComment = psiMethod.getDocComment(); //return if the method has comment if (psiDocComment != null) { return; } String interfaceName = CodeMakerUtil.findClassNameOfSuperMethod(psiMethod); if (interfaceName == null) { return; } String methodName = psiMethod.getName(); Map<String, Object> map = Maps.newHashMap(); map.put("interface", interfaceName); map.put("method", methodName); map.put("paramsType", generateMethodParamsType(psiMethod)); String seeDoc = VelocityUtil.evaluate(seeDocTemplate, map); PsiDocComment seeDocComment = psiElementFactory.createDocCommentFromText(seeDoc); WriteCommandAction writeCommandAction = new DocWriteAction(psiMethod.getProject(), seeDocComment, psiMethod, psiMethod.getContainingFile()); RunResult result = writeCommandAction.execute(); if (result.hasException()) { LOGGER.error(result.getThrowable()); Messages.showErrorDialog("CodeMaker plugin is not available, cause: " + result.getThrowable().getMessage(), "CodeMaker plugin"); } } catch (Exception e) { LOGGER.error("Create @see Doc failed", e); } }
Example #3
Source File: GenerateViewHelperAction.java From idea-php-typo3-plugin with MIT License | 4 votes |
@Override protected void write(@NotNull Project project, @NotNull PsiDirectory extensionRootDirectory, @NotNull String className) { if (!className.endsWith("ViewHelper")) { className += "ViewHelper"; } final String finalClassName = className; RunResult<PsiElement> elementRunResult = new WriteCommandAction<PsiElement>(project) { @Override protected void run(@NotNull Result result) { PsiElement extensionFile; Map<String, String> context = new HashMap<>(); String calculatedNamespace = ExtensionUtility.findDefaultNamespace(extensionRootDirectory); if (calculatedNamespace == null) { result.setResult(null); return; } calculatedNamespace += "ViewHelpers"; context.put("namespace", calculatedNamespace); context.put("className", finalClassName); String majorVersion = null; if (TYPO3Utility.getTYPO3Version(project) != null && TYPO3Utility.isMajorMinorCmsVersion(project, "7.6")) { majorVersion = "7"; } else if (TYPO3Utility.getTYPO3Version(project) != null && TYPO3Utility.isMajorMinorCmsVersion(project, "8.7")) { majorVersion = "8"; } else if (TYPO3Utility.getTYPO3Version(project) != null && TYPO3Utility.getTYPO3Version(project).startsWith("9.")) { majorVersion = "9"; } if (majorVersion == null) { result.setResult(null); return; } try { extensionFile = ExtensionFileGenerationUtil.fromTemplate( "extension_file/" + majorVersion + "/ViewHelper.php", "Classes/ViewHelpers", finalClassName + ".php", extensionRootDirectory, context, project ); if (extensionFile != null) { result.setResult(extensionFile); } } catch (IncorrectOperationException e) { // file already exists } } }.execute(); if (elementRunResult.getResultObject() != null) { new OpenFileDescriptor(project, elementRunResult.getResultObject().getContainingFile().getVirtualFile(), 0).navigate(true); } else { Messages.showErrorDialog("Cannot create extension file", "Error"); } }
Example #4
Source File: GenerateExtbaseEntityAction.java From idea-php-typo3-plugin with MIT License | 4 votes |
@Override protected void write(@NotNull Project project, @NotNull PsiDirectory extensionRootDirectory, @NotNull String className) { final String finalClassName = className; RunResult<PsiElement> elementRunResult = new WriteCommandAction<PsiElement>(project) { @Override protected void run(@NotNull Result result) { PsiElement extensionFile; Map<String, String> context = new HashMap<>(); String calculatedNamespace = ExtensionUtility.findDefaultNamespace(extensionRootDirectory); if (calculatedNamespace == null) { result.setResult(null); return; } calculatedNamespace += "Domain\\Model"; context.put("namespace", calculatedNamespace); context.put("className", finalClassName); try { extensionFile = ExtensionFileGenerationUtil.fromTemplate( "extension_file/ExtbaseEntity.php", "Classes/Domain/Model", finalClassName + ".php", extensionRootDirectory, context, project ); if (extensionFile != null) { result.setResult(extensionFile); } } catch (IncorrectOperationException e) { // file already exists } } }.execute(); if (elementRunResult.getResultObject() != null) { new OpenFileDescriptor(project, elementRunResult.getResultObject().getContainingFile().getVirtualFile(), 0).navigate(true); } else { Messages.showErrorDialog("Cannot create extension file", "Error"); } }
Example #5
Source File: GenerateActionControllerAction.java From idea-php-typo3-plugin with MIT License | 4 votes |
@Override protected void write(@NotNull Project project, @NotNull PsiDirectory extensionRootDirectory, @NotNull String className) { if (!className.endsWith("Controller")) { className += "Controller"; } final String finalClassName = className; RunResult<PsiElement> elementRunResult = new WriteCommandAction<PsiElement>(project) { @Override protected void run(@NotNull Result result) { PsiElement extensionFile; Map<String, String> context = new HashMap<>(); String calculatedNamespace = ExtensionUtility.findDefaultNamespace(extensionRootDirectory); if (calculatedNamespace == null) { result.setResult(null); return; } calculatedNamespace += "Controller"; context.put("namespace", calculatedNamespace); context.put("className", finalClassName); try { extensionFile = ExtensionFileGenerationUtil.fromTemplate( "extension_file/ExtbaseActionController.php", "Classes/Controller", finalClassName + ".php", extensionRootDirectory, context, project ); if (extensionFile != null) { result.setResult(extensionFile); } } catch (IncorrectOperationException e) { // file already exists } } }.execute(); if (elementRunResult.getResultObject() != null) { new OpenFileDescriptor(project, elementRunResult.getResultObject().getContainingFile().getVirtualFile(), 0).navigate(true); } else { Messages.showErrorDialog("Cannot create extension file", "Error"); } }
Example #6
Source File: GenerateCodeFromApiTableAction.java From CodeMaker with Apache License 2.0 | 4 votes |
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getProject(); if (project == null) { return; } DumbService dumbService = DumbService.getInstance(project); if (dumbService.isDumb()) { dumbService .showDumbModeNotification("CodeMaker plugin is not available during indexing"); return; } PsiFile javaFile = e.getData(CommonDataKeys.PSI_FILE); Editor editor = e.getData(CommonDataKeys.EDITOR); if (javaFile == null || editor == null) { return; } Transferable transferable = CopyPasteManager.getInstance().getContents(); if (transferable == null) { return; } try { String table = (String) transferable.getTransferData(DataFlavor.stringFlavor); List<String> tableList = Splitter.onPattern("\n|\t|\r\n").splitToList(table); PsiElementFactory psiElementFactory = PsiElementFactory.SERVICE.getInstance(project); int mod = tableList.size() % 3; int end = tableList.size() - mod; for (int i = 0; i < end; i++) { String fieldName = tableList.get(i); String fieldType = tableList.get(++i); String fieldComment = tableList.get(++i); PsiField psiField = psiElementFactory.createField(fieldName, PsiType.getTypeByName(fieldType, project, GlobalSearchScope.allScope(project))); Map<String, Object> map = Maps.newHashMap(); map.put("comment", fieldComment); String vm = "/**\n" + " * ${comment}\n" + " */"; if (settings.getCodeTemplate("FieldComment.vm") != null) { vm = settings.getCodeTemplate("FieldComment.vm").getCodeTemplate(); } String fieldDocComment = VelocityUtil.evaluate(vm, map); PsiDocComment docComment = psiElementFactory .createDocCommentFromText(fieldDocComment); psiField.addBefore(docComment, psiField.getFirstChild()); WriteCommandAction writeCommandAction = new FieldWriteAction(project, CodeMakerUtil.getClasses(javaFile).get(0), psiField, javaFile); RunResult result = writeCommandAction.execute(); if (result.hasException()) { LOGGER.error(result.getThrowable()); Messages.showErrorDialog("CodeMaker plugin is not available, cause: " + result.getThrowable().getMessage(), "CodeMaker plugin"); } } } catch (Exception ex) { LOGGER.error(ex); } }
Example #7
Source File: DataWriter.java From GsonFormat with Apache License 2.0 | 4 votes |
@NotNull @Override @Deprecated() public RunResult execute() { return super.execute(); }