From 1e64e9d4bea925df48b6802c7bf5ce66e0a655ec Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 20 Dec 2019 12:41:13 +0300 Subject: [PATCH] cleanup GitOrigin-RevId: f7e59ab91f9683baaf645f4e4d78c21a12df70ed --- .../inspections/GuavaInspectionTest.java | 4 +- .../codeInspection/InspectionEngine.java | 4 +- .../daemon/impl/DaemonListeners.java | 6 +- .../daemon/impl/LocalInspectionsPass.java | 101 +++++++++--------- 4 files changed, 57 insertions(+), 58 deletions(-) diff --git a/java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java b/java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java index a8ae8bfdfa68..e13c92e79280 100644 --- a/java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java +++ b/java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java @@ -4,8 +4,8 @@ package com.intellij.codeInsight.inspections; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.actions.CleanupInspectionIntention; -import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.TextRange; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethodCallExpression; @@ -319,7 +319,7 @@ public class GuavaInspectionTest extends JavaCodeInsightFixtureTestCase { myFixture.enableInspections(new GuavaInspection()); for (HighlightInfo info : myFixture.doHighlighting()) if (GuavaInspection.PROBLEM_DESCRIPTION.equals(info.getDescription())) { - final Pair marker = info.quickFixActionMarkers.get(0); + final Pair marker = info.quickFixActionRanges.get(0); final PsiElement someElement = myFixture.getFile().findElementAt(0); assertNotNull(someElement); final List options = marker.getFirst().getOptions(someElement, myFixture.getEditor()); diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/InspectionEngine.java b/platform/analysis-impl/src/com/intellij/codeInspection/InspectionEngine.java index aec949e8c9c7..ee0c8366ad3e 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/InspectionEngine.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/InspectionEngine.java @@ -293,7 +293,7 @@ public class InspectionEngine { } @NotNull - private static Set getLanguageWithDialects(@NotNull LocalInspectionToolWrapper wrapper, Language language) { + private static Set getLanguageWithDialects(@NotNull LocalInspectionToolWrapper wrapper, @NotNull Language language) { List dialects = language.getDialects(); boolean applyToDialects = wrapper.applyToDialects(); Set result = applyToDialects && !dialects.isEmpty() ? new THashSet<>(1 + dialects.size()) : new SmartHashSet<>(); @@ -304,7 +304,7 @@ public class InspectionEngine { return result; } - private static void addDialects(@NotNull Language language, @NotNull Set result) { + private static void addDialects(@NotNull Language language, @NotNull Set result) { for (Language dialect : language.getDialects()) { result.add(dialect.getID()); addDialects(dialect, result); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java index f2476b5bcb62..016d7295a149 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java @@ -171,7 +171,7 @@ public final class DaemonListeners implements Disposable { myActiveEditors = activeEditors; // do not stop daemon if idea loses/gains focus - DaemonListeners.this.stopDaemon(true, "Active editor change"); + stopDaemon(true, "Active editor change"); if (ApplicationManager.getApplication().isDispatchThread() && LaterInvocator.isInModalContext()) { // editor appear in modal context, re-enable the daemon myDaemonCodeAnalyzer.setUpdateByTimerEnabled(true); @@ -660,11 +660,11 @@ public final class DaemonListeners implements Disposable { if (info == null) continue; List> ranges = info.quickFixActionRanges; if (ranges != null) { - ranges.removeIf((pair) -> isContributedByPlugin(pair.first, pluginDescriptor)); + ranges.removeIf(pair -> isContributedByPlugin(pair.first, pluginDescriptor)); } List> markers = info.quickFixActionMarkers; if (markers != null) { - markers.removeIf((pair) -> isContributedByPlugin(pair.first, pluginDescriptor)); + markers.removeIf(pair -> isContributedByPlugin(pair.first, pluginDescriptor)); } } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java index a2c9f691dfd4..4e90f87ef2b9 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java @@ -90,7 +90,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass final KeymapManager keymapManager = KeymapManager.getInstance(); if (keymapManager != null) { final Keymap keymap = keymapManager.getActiveKeymap(); - myShortcutText = keymap == null ? "" : "(" + KeymapUtil.getShortcutsText(keymap.getShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)) + ")"; + myShortcutText = "(" + KeymapUtil.getShortcutsText(keymap.getShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)) + ")"; } else { myShortcutText = ""; @@ -213,9 +213,9 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass private void highlightRedundantSuppressions(@NotNull List toolWrappers, @NotNull InspectionManager iManager, - List inside, - List outside, - Set elementDialectIds) { + @NotNull List inside, + @NotNull List outside, + @NotNull Set elementDialectIds) { HighlightDisplayKey key = HighlightDisplayKey.find(RedundantSuppressInspection.SHORT_NAME); final InspectionProfileImpl inspectionProfile = myProfileWrapper.getInspectionProfile(); if (key != null && inspectionProfile.isToolEnabled(key, getFile())) { @@ -269,27 +269,28 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass List>> entries = new ArrayList<>(toolToSpecifiedLanguageIds.entrySet()); PsiFile file = session.getFile(); - Processor>> processor = pair -> + Processor>> processor = entry -> AstLoadingFilter.disallowTreeLoading(() -> AstLoadingFilter.forceAllowTreeLoading(file, () -> { - LocalInspectionToolWrapper toolWrapper = pair.getKey(); - Set dialectIdsSpecifiedForTool = pair.getValue(); + LocalInspectionToolWrapper toolWrapper = entry.getKey(); + Set dialectIdsSpecifiedForTool = entry.getValue(); runToolOnElements(toolWrapper, dialectIdsSpecifiedForTool, iManager, isOnTheFly, indicator, elements, session, init, elementDialectIds); return true; })); - boolean result = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(entries, indicator, processor); - if (!result) throw new ProcessCanceledException(); + if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(entries, indicator, processor)) { + throw new ProcessCanceledException(); + } return init; } private void runToolOnElements(@NotNull final LocalInspectionToolWrapper toolWrapper, - Set dialectIdsSpecifiedForTool, - @NotNull final InspectionManager iManager, - final boolean isOnTheFly, - @NotNull final ProgressIndicator indicator, - @NotNull final List elements, - @NotNull final LocalInspectionToolSession session, - @NotNull List init, - @NotNull Set elementDialectIds) { + @Nullable Set dialectIdsSpecifiedForTool, + @NotNull final InspectionManager iManager, + final boolean isOnTheFly, + @NotNull final ProgressIndicator indicator, + @NotNull final List elements, + @NotNull final LocalInspectionToolSession session, + @NotNull List init, + @NotNull Set elementDialectIds) { ProgressManager.checkCanceled(); ApplicationManager.getApplication().assertReadAccessAllowed(); @@ -343,20 +344,19 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass } return true; }; - boolean result = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(init, indicator, processor); - if (!result) { + if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(init, indicator, processor)) { throw new ProcessCanceledException(); } } @NotNull - Set inspectInjectedPsi(@NotNull final List elements, - final boolean onTheFly, - @NotNull final ProgressIndicator indicator, - @NotNull final InspectionManager iManager, - final boolean inVisibleRange, - @NotNull final List wrappers, - @NotNull Set alreadyVisitedInjected) { + private Set inspectInjectedPsi(@NotNull final List elements, + final boolean onTheFly, + @NotNull final ProgressIndicator indicator, + @NotNull final InspectionManager iManager, + final boolean inVisibleRange, + @NotNull final List wrappers, + @NotNull Set alreadyVisitedInjected) { if (!myInspectInjectedPsi) return Collections.emptySet(); Set injected = new THashSet<>(); for (PsiElement element : elements) { @@ -388,12 +388,12 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass private HighlightInfo highlightInfoFromDescriptor(@NotNull ProblemDescriptor problemDescriptor, @NotNull HighlightInfoType highlightInfoType, @NotNull String message, - String toolTip, - PsiElement psiElement, + @Nullable String toolTip, + @NotNull PsiElement psiElement, @NotNull List quickFixes, - LocalInspectionTool tool) { + @NotNull LocalInspectionTool tool) { TextRange textRange = ((ProblemDescriptorBase)problemDescriptor).getTextRange(); - if (textRange == null || psiElement == null) return null; + if (textRange == null) return null; boolean isFileLevel = psiElement instanceof PsiFile && textRange.equals(psiElement.getTextRange()); final HighlightSeverity severity = highlightInfoType.getSeverity(psiElement); @@ -454,7 +454,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass }, __->myProject.isDisposed() || indicator.isCanceled()); } - private void appendDescriptors(@NotNull PsiFile file, @NotNull List descriptors, @NotNull LocalInspectionToolWrapper tool) { + private void appendDescriptors(@NotNull PsiFile file, @NotNull List descriptors, @NotNull LocalInspectionToolWrapper tool) { for (ProblemDescriptor descriptor : descriptors) { if (descriptor == null) { LOG.error("null descriptor. all descriptors(" + descriptors.size() +"): " + @@ -568,16 +568,15 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass context + "\nInspection invoked for file: " + myContext + "\n"; PluginException.logPluginError(LOG, errorMessage, null, tool.getClass()); } - boolean isInjected = myInspectInjectedPsi && file != getFile(); - if (!isInjected) { + boolean isOutsideInjected = !myInspectInjectedPsi || file == getFile(); + if (isOutsideInjected) { outInfos.add(info); return; } injectToHost(outInfos, ilManager, file, documentRange, toolWrapper, element, fixes, info); } - private void registerSuppressedElements(@NotNull LocalInspectionToolWrapper toolWrapper, - @NotNull PsiElement element) { + private void registerSuppressedElements(@NotNull LocalInspectionToolWrapper toolWrapper, @NotNull PsiElement element) { mySuppressedElements.computeIfAbsent(toolWrapper.getID(), shortName -> new HashSet<>()).add(element); String alternativeID = toolWrapper.getAlternativeID(); if (alternativeID != null) { @@ -640,6 +639,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass } } + @NotNull private static List getQuickFixes(@NotNull LocalInspectionToolWrapper tool, @NotNull ProblemDescriptor descriptor, @NotNull Set> emptyActionRegistered) { @@ -676,20 +676,15 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass final FileViewProvider viewProvider = file.getViewProvider(); Set processedLanguages = new SmartHashSet<>(); final PsiElementVisitor visitor = new PsiRecursiveElementVisitor() { - @Override public void visitElement(@NotNull PsiElement element) { + @Override + public void visitElement(@NotNull PsiElement element) { ProgressManager.checkCanceled(); PsiElement child = element.getFirstChild(); - if (child == null) { - // leaf element - } - else { - // composite element - while (child != null) { - outElements.add(child); - child.accept(this); - appendDialects(child, processedLanguages, outDialects); - child = child.getNextSibling(); - } + while (child != null) { + outElements.add(child); + child.accept(this); + appendDialects(child, processedLanguages, outDialects); + child = child.getNextSibling(); } } }; @@ -704,7 +699,9 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass } } - private static void appendDialects(PsiElement element, Set outProcessedLanguages, Set outDialectIds) { + private static void appendDialects(@NotNull PsiElement element, + @NotNull Set outProcessedLanguages, + @NotNull Set outDialectIds) { Language language = element.getLanguage(); outDialectIds.add(language.getID()); if (outProcessedLanguages.add(language)) { @@ -796,10 +793,12 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass } private static class InspectionResult { - @NotNull private final LocalInspectionToolWrapper tool; - @NotNull private final List foundProblems; + @NotNull + private final LocalInspectionToolWrapper tool; + @NotNull + private final List foundProblems; - private InspectionResult(@NotNull LocalInspectionToolWrapper tool, @NotNull List foundProblems) { + private InspectionResult(@NotNull LocalInspectionToolWrapper tool, @NotNull List foundProblems) { this.tool = tool; this.foundProblems = new ArrayList<>(foundProblems); }