List of usage examples for com.intellij.openapi.ui Messages getErrorIcon
@NotNull public static Icon getErrorIcon()
From source file:com.intellij.codeInspection.export.HTMLExportUtil.java
License:Apache License
public static void writeFile(final String folder, @NonNls final String fileName, CharSequence buf, final Project project) { try {/*from w ww .ja v a2 s . c o m*/ HTMLExporter.writeFileImpl(folder, fileName, buf); } catch (IOException e) { Runnable showError = new Runnable() { @Override public void run() { final String fullPath = folder + File.separator + fileName; Messages.showMessageDialog(project, InspectionsBundle.message("inspection.export.error.writing.to", fullPath), InspectionsBundle.message("inspection.export.results.error.title"), Messages.getErrorIcon()); } }; ApplicationManager.getApplication().invokeLater(showError, ModalityState.NON_MODAL); throw new ProcessCanceledException(); } }
From source file:com.intellij.codeInspection.export.HTMLExportUtil.java
License:Apache License
public static void runExport(final Project project, @NotNull ThrowableRunnable<IOException> runnable) { try {//from ww w . java 2s . c o m runnable.run(); } catch (IOException e) { Runnable showError = new Runnable() { @Override public void run() { Messages.showMessageDialog(project, InspectionsBundle.message("inspection.export.error.writing.to", "export file"), InspectionsBundle.message("inspection.export.results.error.title"), Messages.getErrorIcon()); } }; ApplicationManager.getApplication().invokeLater(showError, ModalityState.NON_MODAL); throw new ProcessCanceledException(); } }
From source file:com.intellij.codeInspection.i18n.JavaI18nizeQuickFixDialog.java
License:Apache License
public static boolean isAvailable(PsiFile file) { final Project project = file.getProject(); final String title = CodeInsightBundle.message("i18nize.dialog.error.jdk.title"); try {// w w w . j av a 2 s . c o m return ResourceBundleManager.getManager(file) != null; } catch (ResourceBundleManager.ResourceBundleNotFoundException e) { final IntentionAction fix = e.getFix(); if (fix != null) { if (Messages.showOkCancelDialog(project, e.getMessage(), title, Messages.getErrorIcon()) == OK_EXIT_CODE) { try { fix.invoke(project, null, file); return false; } catch (IncorrectOperationException e1) { LOG.error(e1); } } } Messages.showErrorDialog(project, e.getMessage(), title); return false; } }
From source file:com.intellij.codeInspection.inferNullity.InferNullityAnnotationsAction.java
License:Apache License
@Override protected void analyze(@NotNull final Project project, final AnalysisScope scope) { final ProgressManager progressManager = ProgressManager.getInstance(); final int totalFiles = scope.getFileCount(); final Set<Module> modulesWithoutAnnotations = new HashSet<Module>(); final Set<Module> modulesWithLL = new HashSet<Module>(); if (!progressManager.runProcessWithProgressSynchronously(new Runnable() { @Override//w w w.j ava 2 s. c o m public void run() { scope.accept(new PsiElementVisitor() { private int myFileCount = 0; final private Set<Module> processed = new HashSet<Module>(); @Override public void visitFile(PsiFile file) { myFileCount++; final ProgressIndicator progressIndicator = ProgressManager.getInstance() .getProgressIndicator(); if (progressIndicator != null) { final VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile != null) { progressIndicator .setText2(ProjectUtil.calcRelativeToProjectPath(virtualFile, project)); } progressIndicator.setFraction(((double) myFileCount) / totalFiles); } final Module module = ModuleUtil.findModuleForPsiElement(file); if (module != null && !processed.contains(module)) { processed.add(module); if (JavaPsiFacade.getInstance(project).findClass( NullableNotNullManager.getInstance(project).getDefaultNullable(), GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)) == null) { modulesWithoutAnnotations.add(module); } if (PsiUtil.getLanguageLevel(file).compareTo(LanguageLevel.JDK_1_5) < 0) { modulesWithLL.add(module); } } } }); } }, "Check applicability...", true, project)) { return; } if (!modulesWithLL.isEmpty()) { Messages.showErrorDialog(project, "Infer Nullity Annotations requires the project language level be set to 1.5 or greater.", INFER_NULLITY_ANNOTATIONS); return; } if (!modulesWithoutAnnotations.isEmpty()) { final Library annotationsLib = LibraryUtil .findLibraryByClass(NullableNotNullManager.getInstance(project).getDefaultNullable(), project); if (annotationsLib != null) { String message = "Module" + (modulesWithoutAnnotations.size() == 1 ? " " : "s "); message += StringUtil.join(modulesWithoutAnnotations, new Function<Module, String>() { @Override public String fun(Module module) { return module.getName(); } }, ", "); message += (modulesWithoutAnnotations.size() == 1 ? " doesn't" : " don't"); message += " refer to the existing '" + annotationsLib.getName() + "' library with IDEA nullity annotations. Would you like to add the dependenc"; message += (modulesWithoutAnnotations.size() == 1 ? "y" : "ies") + " now?"; if (Messages.showOkCancelDialog(project, message, INFER_NULLITY_ANNOTATIONS, Messages.getErrorIcon()) == DialogWrapper.OK_EXIT_CODE) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { for (Module module : modulesWithoutAnnotations) { ModuleRootModificationUtil.addDependency(module, annotationsLib); } } }); } } else if (Messages.showOkCancelDialog(project, "Infer Nullity Annotations requires that the nullity annotations" + " be available in all your project sources.\n\nYou will need to add annotations.jar as a library. " + "It is possible to configure custom jar in e.g. Constant Conditions & Exceptions inspection or use JetBrains annotations available in installation. " + " IntelliJ IDEA nullity annotations are freely usable and redistributable under the Apache 2.0 license. Would you like to do it now?", INFER_NULLITY_ANNOTATIONS, Messages.getErrorIcon()) == DialogWrapper.OK_EXIT_CODE) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { final LocateLibraryDialog dialog = new LocateLibraryDialog( modulesWithoutAnnotations.iterator().next(), PathManager.getLibPath(), "annotations.jar", QuickFixBundle.message("add.library.annotations.description")); dialog.show(); if (dialog.isOK()) { final String path = dialog.getResultingLibraryPath(); new WriteCommandAction(project) { @Override protected void run(final Result result) throws Throwable { for (Module module : modulesWithoutAnnotations) { OrderEntryFix.addBundledJarToRoots(project, null, module, null, AnnotationUtil.NOT_NULL, path); } } }.execute(); } } }); } return; } if (scope.checkScopeWritable(project)) return; PsiDocumentManager.getInstance(project).commitAllDocuments(); final NullityInferrer inferrer = new NullityInferrer(myAnnotateLocalVariablesCb.isSelected(), project); final PsiManager psiManager = PsiManager.getInstance(project); if (!progressManager.runProcessWithProgressSynchronously(new Runnable() { @Override public void run() { scope.accept(new PsiElementVisitor() { int myFileCount = 0; @Override public void visitFile(final PsiFile file) { myFileCount++; final VirtualFile virtualFile = file.getVirtualFile(); final FileViewProvider viewProvider = psiManager.findViewProvider(virtualFile); final Document document = viewProvider == null ? null : viewProvider.getDocument(); if (document == null || virtualFile.getFileType().isBinary()) return; //do not inspect binary files final ProgressIndicator progressIndicator = ProgressManager.getInstance() .getProgressIndicator(); if (progressIndicator != null) { if (virtualFile != null) { progressIndicator .setText2(ProjectUtil.calcRelativeToProjectPath(virtualFile, project)); } progressIndicator.setFraction(((double) myFileCount) / totalFiles); } if (file instanceof PsiJavaFile) { inferrer.collect(file); } } }); } }, INFER_NULLITY_ANNOTATIONS, true, project)) { return; } final Runnable applyRunnable = new Runnable() { @Override public void run() { new WriteCommandAction(project, INFER_NULLITY_ANNOTATIONS) { @Override protected void run(Result result) throws Throwable { if (!inferrer.nothingFoundMessage(project)) { final SequentialModalProgressTask progressTask = new SequentialModalProgressTask( project, INFER_NULLITY_ANNOTATIONS, false); progressTask.setMinIterationTime(200); progressTask.setTask(new AnnotateTask(project, inferrer, progressTask)); ProgressManager.getInstance().run(progressTask); } } }.execute(); } }; SwingUtilities.invokeLater(applyRunnable); }
From source file:com.intellij.codeInspection.MoveToPackageFix.java
License:Apache License
private void chooseDirectoryAndMove(Project project, PsiFile myFile) { try {/*from w w w .j ava 2 s .com*/ PsiDirectory directory = MoveClassesOrPackagesUtil.chooseDestinationPackage(project, myTargetPackage, myFile.getContainingDirectory()); if (directory == null) { return; } String error = RefactoringMessageUtil.checkCanCreateFile(directory, myFile.getName()); if (error != null) { Messages.showMessageDialog(project, error, CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } new MoveClassesOrPackagesProcessor(project, ((PsiJavaFile) myFile).getClasses(), new SingleSourceRootMoveDestination( PackageWrapper.create(JavaDirectoryService.getInstance().getPackage(directory)), directory), false, false, null).run(); } catch (IncorrectOperationException e) { LOG.error(e); } }
From source file:com.intellij.compiler.impl.CompileDriver.java
License:Apache License
private boolean validateCompilerConfiguration(final CompileScope scope, boolean checkOutputAndSourceIntersection) { try {//from w w w .j ava 2s . c o m final Module[] scopeModules = scope .getAffectedModules()/*ModuleManager.getInstance(myProject).getModules()*/; final List<String> modulesWithoutOutputPathSpecified = new ArrayList<String>(); boolean isProjectCompilePathSpecified = true; final Set<File> nonExistingOutputPaths = new HashSet<File>(); final CompilerManager compilerManager = CompilerManager.getInstance(myProject); for (final Module module : scopeModules) { if (!compilerManager.isValidationEnabled(module)) { continue; } boolean isEmpty = true; for (ContentFolderTypeProvider contentFolderType : ContentFolderTypeProvider .filter(ContentFolderScopes.productionAndTest())) { if (hasContent(module, contentFolderType)) { isEmpty = false; break; } } if (isEmpty) { continue; } for (ContentFolderTypeProvider contentFolderType : ContentFolderTypeProvider .filter(ContentFolderScopes.productionAndTest())) { if (hasContent(module, contentFolderType)) { final String outputPath = getModuleOutputPath(module, contentFolderType); if (outputPath != null) { final File file = new File(FileUtil.toSystemDependentName(outputPath)); if (!file.exists()) { nonExistingOutputPaths.add(file); } } else { modulesWithoutOutputPathSpecified.add(module.getName()); } } } for (AdditionalOutputDirectoriesProvider provider : AdditionalOutputDirectoriesProvider.EP_NAME .getExtensions()) { for (String path : provider.getOutputDirectories(myProject, module)) { if (path == null) { final CompilerConfiguration extension = CompilerConfiguration .getInstance(module.getProject()); if (extension.getCompilerOutputUrl() == null) { isProjectCompilePathSpecified = false; } else { modulesWithoutOutputPathSpecified.add(module.getName()); } } else { final File file = new File(path); if (!file.exists()) { nonExistingOutputPaths.add(file); } } } } } if (!isProjectCompilePathSpecified) { final String message = CompilerBundle.message("error.project.output.not.specified"); if (ApplicationManager.getApplication().isUnitTestMode()) { LOG.error(message); } Messages.showMessageDialog(myProject, message, CommonBundle.getErrorTitle(), Messages.getErrorIcon()); ProjectSettingsService.getInstance(myProject).openProjectSettings(); return false; } if (!modulesWithoutOutputPathSpecified.isEmpty()) { showNotSpecifiedError("error.output.not.specified", modulesWithoutOutputPathSpecified, ContentEntriesEditor.NAME); return false; } if (!nonExistingOutputPaths.isEmpty()) { for (File file : nonExistingOutputPaths) { final boolean succeeded = file.mkdirs(); if (!succeeded) { if (file.exists()) { // for overlapping paths, this one might have been created as an intermediate path on a previous iteration continue; } Messages.showMessageDialog(myProject, CompilerBundle.message("error.failed.to.create.directory", file.getPath()), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return false; } } final Boolean refreshSuccess = new WriteAction<Boolean>() { @Override protected void run(Result<Boolean> result) throws Throwable { LocalFileSystem.getInstance().refreshIoFiles(nonExistingOutputPaths); Boolean res = Boolean.TRUE; for (File file : nonExistingOutputPaths) { if (LocalFileSystem.getInstance().findFileByIoFile(file) == null) { res = Boolean.FALSE; break; } } result.setResult(res); } }.execute().getResultObject(); if (!refreshSuccess.booleanValue()) { return false; } dropScopesCaches(); } if (checkOutputAndSourceIntersection && myShouldClearOutputDirectory) { if (!validateOutputAndSourcePathsIntersection()) { return false; } // myShouldClearOutputDirectory may change in validateOutputAndSourcePathsIntersection() CompilerPathsEx.CLEAR_ALL_OUTPUTS_KEY.set(scope, myShouldClearOutputDirectory); } else { CompilerPathsEx.CLEAR_ALL_OUTPUTS_KEY.set(scope, false); } final Compiler[] allCompilers = compilerManager.getCompilers(Compiler.class); for (Compiler compiler : allCompilers) { if (!compiler.validateConfiguration(scope)) { LOG.info("Validation with compiler " + compiler.getDescription() + " is failed."); return false; } } return true; } catch (Throwable e) { LOG.info(e); return false; } }
From source file:com.intellij.compiler.impl.CompileDriver.java
License:Apache License
private void showNotSpecifiedError(@NonNls final String resourceId, List<String> modules, String editorNameToSelect) { String nameToSelect = null;//from w w w . jav a 2 s .com final StringBuilder names = StringBuilderSpinAllocator.alloc(); final String message; try { final int maxModulesToShow = 10; for (String name : modules.size() > maxModulesToShow ? modules.subList(0, maxModulesToShow) : modules) { if (nameToSelect == null) { nameToSelect = name; } if (names.length() > 0) { names.append(",\n"); } names.append("\""); names.append(name); names.append("\""); } if (modules.size() > maxModulesToShow) { names.append(",\n..."); } message = CompilerBundle.message(resourceId, modules.size(), names.toString()); } finally { StringBuilderSpinAllocator.dispose(names); } if (ApplicationManager.getApplication().isUnitTestMode()) { LOG.error(message); } Messages.showMessageDialog(myProject, message, CommonBundle.getErrorTitle(), Messages.getErrorIcon()); showConfigurationDialog(nameToSelect, editorNameToSelect); }
From source file:com.intellij.compiler.impl.javaCompiler.AnnotationProcessingCompiler.java
License:Apache License
private void showCyclesNotSupportedForAnnotationProcessors(Module[] modulesInChunk) { LOGGER.assertTrue(modulesInChunk.length > 0); String moduleNameToSelect = modulesInChunk[0].getName(); final String moduleNames = getModulesString(modulesInChunk); Messages.showMessageDialog(myProject, CompilerBundle.message("error.annotation.processing.not.supported.for.module.cycles", moduleNames), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); showConfigurationDialog(moduleNameToSelect, null); }
From source file:com.intellij.compiler.impl.javaCompiler.javac.JavacCompiler.java
License:Apache License
@Override public boolean checkCompiler(final CompileScope scope) { final Module[] modules = scope.getAffectedModules(); final Set<Sdk> checkedJdks = new HashSet<Sdk>(); for (final Module module : modules) { JavaModuleExtension extension = ModuleUtilCore.getExtension(module, JavaModuleExtension.class); if (extension == null) { continue; }//from w w w . j a v a2s.c o m final Sdk javaSdk = JavaCompilerUtil.getSdkForCompilation(module); if (javaSdk == null) { Messages.showMessageDialog(myProject, JavaCompilerBundle.message("javac.error.jdk.is.not.set.for.module", module.getName()), JavaCompilerBundle.message("compiler.javac.name"), Messages.getErrorIcon()); return false; } if (checkedJdks.contains(javaSdk)) { continue; } checkedJdks.add(javaSdk); final SdkTypeId sdkType = javaSdk.getSdkType(); assert sdkType instanceof JavaSdkType; final VirtualFile homeDirectory = javaSdk.getHomeDirectory(); if (homeDirectory == null) { Messages.showMessageDialog(myProject, JavaCompilerBundle.message("javac.error.jdk.home.missing", javaSdk.getHomePath()), JavaCompilerBundle.message("compiler.javac" + ".name"), Messages.getErrorIcon()); return false; } final String toolsJarPath = ((JavaSdkType) sdkType).getToolsPath(javaSdk); if (toolsJarPath == null) { Messages.showMessageDialog(myProject, JavaCompilerBundle.message("javac.error.tools.jar.missing", javaSdk.getName()), JavaCompilerBundle.message("compiler.javac.name"), Messages.getErrorIcon()); return false; } final String versionString = javaSdk.getVersionString(); if (versionString == null) { Messages.showMessageDialog(myProject, JavaCompilerBundle.message("javac.error.unknown.jdk.version", javaSdk.getName()), JavaCompilerBundle.message("compiler.javac.name"), Messages.getErrorIcon()); return false; } if (CompilerUtil.isOfVersion(versionString, "1.0")) { Messages.showMessageDialog(myProject, JavaCompilerBundle.message("javac.error.1_0_compilation.not.supported"), JavaCompilerBundle.message("compiler.javac.name"), Messages.getErrorIcon()); return false; } } return true; }
From source file:com.intellij.debugger.actions.ExportThreadsAction.java
License:Apache License
public void actionPerformed(AnActionEvent e) { Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) { return;/*from ww w . ja v a 2 s .c o m*/ } DebuggerContextImpl context = (DebuggerManagerEx.getInstanceEx(project)).getContext(); if (context.getDebuggerSession() != null) { String destinationDirectory = ""; final VirtualFile baseDir = project.getBaseDir(); if (baseDir != null) destinationDirectory = baseDir.getPresentableUrl(); ExportDialog dialog = new ExportDialog(context.getDebugProcess(), destinationDirectory); dialog.show(); if (dialog.isOK()) { try { File file = new File(dialog.getFilePath()); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); try { String text = StringUtil.convertLineSeparators(dialog.getTextToSave(), SystemProperties.getLineSeparator()); writer.write(text); } finally { writer.close(); } } catch (IOException ex) { Messages.showMessageDialog(project, ex.getMessage(), ActionsBundle.actionText(DebuggerActions.EXPORT_THREADS), Messages.getErrorIcon()); } } } }