// return true if panel needs to be rebuilt boolean updatePanel(@NotNull DaemonCodeAnalyzerStatus status, Project project) { progressBarsEnabled = false; progressBarsCompleted = null; statistics = ""; passStatusesVisible = false; statusLabel = null; statusExtraLine = null; boolean result = false; if (!status.passStati.equals(new ArrayList<>(passes.keySet()))) { // passes set has changed rebuildPassesMap(status); result = true; } if (PowerSaveMode.isEnabled()) { statusLabel = "Code analysis is disabled in power save mode"; status.errorAnalyzingFinished = true; icon = AllIcons.General.SafeMode; return result; } if (status.reasonWhyDisabled != null) { statusLabel = "No analysis has been performed"; statusExtraLine = "(" + status.reasonWhyDisabled + ")"; passStatusesVisible = true; progressBarsCompleted = Boolean.FALSE; icon = AllIcons.General.InspectionsTrafficOff; return result; } if (status.reasonWhySuspended != null) { statusLabel = "Code analysis has been suspended"; statusExtraLine = "(" + status.reasonWhySuspended + ")"; passStatusesVisible = true; progressBarsCompleted = Boolean.FALSE; icon = AllIcons.General.InspectionsPause; return result; } Icon icon = AllIcons.General.InspectionsOK; for (int i = status.errorCount.length - 1; i >= 0; i--) { if (status.errorCount[i] != 0) { icon = SeverityRegistrar.getSeverityRegistrar(project).getRendererIconByIndex(i); break; } } if (status.errorAnalyzingFinished) { boolean isDumb = project != null && DumbService.isDumb(project); if (isDumb) { statusLabel = "Shallow analysis completed"; statusExtraLine = "Complete results will be available after indexing"; } else { statusLabel = DaemonBundle.message("analysis.completed"); } progressBarsCompleted = Boolean.TRUE; } else { statusLabel = DaemonBundle.message("performing.code.analysis"); passStatusesVisible = true; progressBarsEnabled = true; progressBarsCompleted = null; } int currentSeverityErrors = 0; @org.intellij.lang.annotations.Language("HTML") String text = ""; for (int i = status.errorCount.length - 1; i >= 0; i--) { if (status.errorCount[i] > 0) { final HighlightSeverity severity = SeverityRegistrar.getSeverityRegistrar(project).getSeverityByIndex(i); String name = status.errorCount[i] > 1 ? StringUtil.pluralize(severity.getName().toLowerCase()) : severity.getName().toLowerCase(); text += status.errorAnalyzingFinished ? DaemonBundle.message("errors.found", status.errorCount[i], name) : DaemonBundle.message("errors.found.so.far", status.errorCount[i], name); text += "<br>"; currentSeverityErrors += status.errorCount[i]; } } if (currentSeverityErrors == 0) { text += status.errorAnalyzingFinished ? DaemonBundle.message("no.errors.or.warnings.found") : DaemonBundle.message("no.errors.or.warnings.found.so.far") + "<br>"; } statistics = XmlStringUtil.wrapInHtml(text); this.icon = icon; return result; }
@NotNull protected DaemonCodeAnalyzerStatus getDaemonCodeAnalyzerStatus( @NotNull SeverityRegistrar severityRegistrar) { DaemonCodeAnalyzerStatus status = new DaemonCodeAnalyzerStatus(); if (myFile == null) { status.reasonWhyDisabled = "No file"; status.errorAnalyzingFinished = true; return status; } if (myProject != null && myProject.isDisposed()) { status.reasonWhyDisabled = "Project is disposed"; status.errorAnalyzingFinished = true; return status; } if (!myDaemonCodeAnalyzer.isHighlightingAvailable(myFile)) { if (!myFile.isPhysical()) { status.reasonWhyDisabled = "File is generated"; status.errorAnalyzingFinished = true; return status; } else if (myFile instanceof PsiCompiledElement) { status.reasonWhyDisabled = "File is decompiled"; status.errorAnalyzingFinished = true; return status; } final FileType fileType = myFile.getFileType(); if (fileType.isBinary()) { status.reasonWhyDisabled = "File is binary"; status.errorAnalyzingFinished = true; return status; } status.reasonWhyDisabled = "Highlighting is disabled for this file"; status.errorAnalyzingFinished = true; return status; } FileViewProvider provider = myFile.getViewProvider(); Set<Language> languages = provider.getLanguages(); HighlightingSettingsPerFile levelSettings = HighlightingSettingsPerFile.getInstance(myProject); boolean shouldHighlight = languages.isEmpty(); for (Language language : languages) { PsiFile root = provider.getPsi(language); FileHighlightingSetting level = levelSettings.getHighlightingSettingForRoot(root); shouldHighlight |= level != FileHighlightingSetting.SKIP_HIGHLIGHTING; } if (!shouldHighlight) { status.reasonWhyDisabled = "Highlighting level is None"; status.errorAnalyzingFinished = true; return status; } if (HeavyProcessLatch.INSTANCE.isRunning()) { status.reasonWhySuspended = StringUtil.defaultIfEmpty( HeavyProcessLatch.INSTANCE.getRunningOperationName(), "Heavy operation is running"); status.errorAnalyzingFinished = true; return status; } status.errorCount = errorCount.clone(); fillDaemonCodeAnalyzerErrorsStatus(status, severityRegistrar); List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(myDocument); status.passStati = passes.isEmpty() ? Collections.<ProgressableTextEditorHighlightingPass>emptyList() : new ArrayList<>(passes.size()); //noinspection ForLoopReplaceableByForEach for (int i = 0; i < passes.size(); i++) { TextEditorHighlightingPass tepass = passes.get(i); if (!(tepass instanceof ProgressableTextEditorHighlightingPass)) continue; ProgressableTextEditorHighlightingPass pass = (ProgressableTextEditorHighlightingPass) tepass; if (pass.getProgress() < 0) continue; status.passStati.add(pass); } status.errorAnalyzingFinished = myDaemonCodeAnalyzer.isAllAnalysisFinished(myFile); status.reasonWhySuspended = myDaemonCodeAnalyzer.isUpdateByTimerEnabled() ? null : "Highlighting is paused temporarily"; return status; }