@Nullable protected DaemonCodeAnalyzerStatus getDaemonCodeAnalyzerStatus( boolean fillErrorsCount, SeverityRegistrar severityRegistrar) { if (myFile == null || myProject.isDisposed() || !myDaemonCodeAnalyzer.isHighlightingAvailable(myFile)) return null; List<String> noInspectionRoots = new ArrayList<String>(); List<String> noHighlightingRoots = new ArrayList<String>(); FileViewProvider provider = myFile.getViewProvider(); Set<Language> languages = provider.getLanguages(); for (Language language : languages) { PsiFile root = provider.getPsi(language); if (!HighlightLevelUtil.shouldHighlight(root)) { noHighlightingRoots.add(language.getID()); } else if (!HighlightLevelUtil.shouldInspect(root)) { noInspectionRoots.add(language.getID()); } } DaemonCodeAnalyzerStatus status = new DaemonCodeAnalyzerStatus(); status.noInspectionRoots = noInspectionRoots.isEmpty() ? null : ArrayUtil.toStringArray(noInspectionRoots); status.noHighlightingRoots = noHighlightingRoots.isEmpty() ? null : ArrayUtil.toStringArray(noHighlightingRoots); status.errorCount = errorCount.clone(); status.rootsNumber = languages.size(); fillDaemonCodeAnalyzerErrorsStatus(status, fillErrorsCount, severityRegistrar); List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(myDocument); status.passStati = passes.isEmpty() ? Collections.<ProgressableTextEditorHighlightingPass>emptyList() : new ArrayList<ProgressableTextEditorHighlightingPass>(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.enabled = myDaemonCodeAnalyzer.isUpdateByTimerEnabled(); return status; }
private void forceDaemonRestart() { final FileViewProvider viewProvider = myFile.getViewProvider(); for (Language language : mySliders.keySet()) { JSlider slider = mySliders.get(language); PsiElement root = viewProvider.getPsi(language); assert root != null : "No root in " + viewProvider + " for " + language; int value = slider.getValue(); if (value == 1) { HighlightLevelUtil.forceRootHighlighting(root, FileHighlightingSetting.SKIP_HIGHLIGHTING); } else if (value == 2) { HighlightLevelUtil.forceRootHighlighting(root, FileHighlightingSetting.SKIP_INSPECTION); } else { HighlightLevelUtil.forceRootHighlighting(root, FileHighlightingSetting.FORCE_HIGHLIGHTING); } } final DaemonCodeAnalyzer analyzer = DaemonCodeAnalyzer.getInstance(myFile.getProject()); analyzer.restart(); }
private boolean isModified() { final FileViewProvider viewProvider = myFile.getViewProvider(); for (Language language : mySliders.keySet()) { JSlider slider = mySliders.get(language); final PsiFile root = viewProvider.getPsi(language); if (root != null && getValue( HighlightLevelUtil.shouldHighlight(root), HighlightLevelUtil.shouldInspect(root)) != slider.getValue()) { return true; } } for (HectorComponentPanel panel : myAdditionalPanels) { if (panel.isModified()) { return true; } } return false; }
public static void divideInsideAndOutside( @NotNull PsiFile file, int startOffset, int endOffset, @NotNull TextRange range, @NotNull List<PsiElement> inside, @NotNull List<PsiElement> outside, @NotNull HighlightLevelUtil.AnalysisLevel level, boolean includeParents) { final FileViewProvider viewProvider = file.getViewProvider(); for (Language language : viewProvider.getLanguages()) { final PsiFile psiRoot = viewProvider.getPsi(language); if (HighlightLevelUtil.shouldAnalyse(psiRoot, level)) { divideInsideAndOutside( psiRoot, startOffset, endOffset, range, inside, outside, includeParents); } } }
public HectorComponent(@NotNull PsiFile file) { super(new GridBagLayout()); setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0)); myFile = file; mySliders = new HashMap<Language, JSlider>(); final Project project = myFile.getProject(); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); final VirtualFile virtualFile = myFile.getContainingFile().getVirtualFile(); LOG.assertTrue(virtualFile != null); final boolean notInLibrary = !fileIndex.isInLibrarySource(virtualFile) && !fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInContent(virtualFile); final FileViewProvider viewProvider = myFile.getViewProvider(); List<Language> languages = new ArrayList<Language>(viewProvider.getLanguages()); Collections.sort(languages, PsiUtilBase.LANGUAGE_COMPARATOR); for (Language language : languages) { @SuppressWarnings("UseOfObsoleteCollectionType") final Hashtable<Integer, JLabel> sliderLabels = new Hashtable<Integer, JLabel>(); sliderLabels.put(1, new JLabel(EditorBundle.message("hector.none.slider.label"))); sliderLabels.put(2, new JLabel(EditorBundle.message("hector.syntax.slider.label"))); if (notInLibrary) { sliderLabels.put(3, new JLabel(EditorBundle.message("hector.inspections.slider.label"))); } final JSlider slider = new JSlider(SwingConstants.VERTICAL, 1, notInLibrary ? 3 : 2, 1); if (UIUtil.isUnderGTKLookAndFeel()) { // default GTK+ slider UI is way too ugly slider.putClientProperty("Slider.paintThumbArrowShape", true); slider.setUI(new BasicSliderUI(slider)); } slider.setLabelTable(sliderLabels); UIUtil.setSliderIsFilled(slider, true); slider.setPaintLabels(true); slider.setSnapToTicks(true); slider.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int value = slider.getValue(); for (Enumeration<Integer> enumeration = sliderLabels.keys(); enumeration.hasMoreElements(); ) { Integer key = enumeration.nextElement(); sliderLabels .get(key) .setForeground( key.intValue() <= value ? UIUtil.getLabelForeground() : UIUtil.getLabelDisabledForeground()); } } }); final PsiFile psiRoot = viewProvider.getPsi(language); assert psiRoot != null : "No root in " + viewProvider + " for " + language; slider.setValue( getValue( HighlightLevelUtil.shouldHighlight(psiRoot), HighlightLevelUtil.shouldInspect(psiRoot))); mySliders.put(language, slider); } GridBagConstraints gc = new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0); JPanel panel = new JPanel(new GridBagLayout()); panel.setBorder(IdeBorderFactory.createTitledBorder(myTitle, false)); final boolean addLabel = mySliders.size() > 1; if (addLabel) { layoutVertical(panel); } else { layoutHorizontal(panel); } gc.gridx = 0; gc.gridy = 0; gc.weighty = 1.0; gc.fill = GridBagConstraints.BOTH; add(panel, gc); gc.gridy = GridBagConstraints.RELATIVE; gc.weighty = 0; final HyperlinkLabel configurator = new HyperlinkLabel("Configure inspections"); gc.insets.right = 5; gc.insets.bottom = 10; gc.weightx = 0; gc.fill = GridBagConstraints.NONE; gc.anchor = GridBagConstraints.EAST; add(configurator, gc); configurator.addHyperlinkListener( new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { final JBPopup hector = getOldHector(); if (hector != null) { hector.cancel(); } if (!DaemonCodeAnalyzer.getInstance(myFile.getProject()) .isHighlightingAvailable(myFile)) return; final Project project = myFile.getProject(); final ErrorsConfigurable errorsConfigurable = ErrorsConfigurable.SERVICE.createConfigurable(project); assert errorsConfigurable != null; ShowSettingsUtil.getInstance().editConfigurable(project, errorsConfigurable); } }); gc.anchor = GridBagConstraints.WEST; gc.weightx = 1.0; gc.insets.right = 0; gc.fill = GridBagConstraints.HORIZONTAL; myAdditionalPanels = new ArrayList<HectorComponentPanel>(); for (HectorComponentPanelsProvider provider : Extensions.getExtensions(HectorComponentPanelsProvider.EP_NAME, project)) { final HectorComponentPanel componentPanel = provider.createConfigurable(file); if (componentPanel != null) { myAdditionalPanels.add(componentPanel); add(componentPanel.createComponent(), gc); componentPanel.reset(); } } }