GitOrigin-RevId: f7e59ab91f9683baaf645f4e4d78c21a12df70ed
This commit is contained in:
Alexey Kudravtsev
2019-12-20 10:05:36 +00:00
committed by intellij-monorepo-bot
parent d9b6464592
commit 1e64e9d4be
4 changed files with 57 additions and 58 deletions
@@ -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<HighlightInfo.IntentionActionDescriptor, RangeMarker> marker = info.quickFixActionMarkers.get(0);
final Pair<HighlightInfo.IntentionActionDescriptor, TextRange> marker = info.quickFixActionRanges.get(0);
final PsiElement someElement = myFixture.getFile().findElementAt(0);
assertNotNull(someElement);
final List<IntentionAction> options = marker.getFirst().getOptions(someElement, myFixture.getEditor());
@@ -293,7 +293,7 @@ public class InspectionEngine {
}
@NotNull
private static Set<String> getLanguageWithDialects(@NotNull LocalInspectionToolWrapper wrapper, Language language) {
private static Set<String> getLanguageWithDialects(@NotNull LocalInspectionToolWrapper wrapper, @NotNull Language language) {
List<Language> dialects = language.getDialects();
boolean applyToDialects = wrapper.applyToDialects();
Set<String> 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<String> result) {
private static void addDialects(@NotNull Language language, @NotNull Set<? super String> result) {
for (Language dialect : language.getDialects()) {
result.add(dialect.getID());
addDialects(dialect, result);
@@ -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<Pair<HighlightInfo.IntentionActionDescriptor, TextRange>> ranges = info.quickFixActionRanges;
if (ranges != null) {
ranges.removeIf((pair) -> isContributedByPlugin(pair.first, pluginDescriptor));
ranges.removeIf(pair -> isContributedByPlugin(pair.first, pluginDescriptor));
}
List<Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker>> markers = info.quickFixActionMarkers;
if (markers != null) {
markers.removeIf((pair) -> isContributedByPlugin(pair.first, pluginDescriptor));
markers.removeIf(pair -> isContributedByPlugin(pair.first, pluginDescriptor));
}
}
}
@@ -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<? extends LocalInspectionToolWrapper> toolWrappers,
@NotNull InspectionManager iManager,
List<? extends PsiElement> inside,
List<? extends PsiElement> outside,
Set<String> elementDialectIds) {
@NotNull List<? extends PsiElement> inside,
@NotNull List<? extends PsiElement> outside,
@NotNull Set<String> 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<Map.Entry<LocalInspectionToolWrapper, Set<String>>> entries = new ArrayList<>(toolToSpecifiedLanguageIds.entrySet());
PsiFile file = session.getFile();
Processor<Map.Entry<LocalInspectionToolWrapper, Set<String>>> processor = pair ->
Processor<Map.Entry<LocalInspectionToolWrapper, Set<String>>> processor = entry ->
AstLoadingFilter.disallowTreeLoading(() -> AstLoadingFilter.<Boolean, RuntimeException>forceAllowTreeLoading(file, () -> {
LocalInspectionToolWrapper toolWrapper = pair.getKey();
Set<String> dialectIdsSpecifiedForTool = pair.getValue();
LocalInspectionToolWrapper toolWrapper = entry.getKey();
Set<String> 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<String> dialectIdsSpecifiedForTool,
@NotNull final InspectionManager iManager,
final boolean isOnTheFly,
@NotNull final ProgressIndicator indicator,
@NotNull final List<? extends PsiElement> elements,
@NotNull final LocalInspectionToolSession session,
@NotNull List<? super InspectionContext> init,
@NotNull Set<String> elementDialectIds) {
@Nullable Set<String> dialectIdsSpecifiedForTool,
@NotNull final InspectionManager iManager,
final boolean isOnTheFly,
@NotNull final ProgressIndicator indicator,
@NotNull final List<? extends PsiElement> elements,
@NotNull final LocalInspectionToolSession session,
@NotNull List<? super InspectionContext> init,
@NotNull Set<String> 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<PsiFile> inspectInjectedPsi(@NotNull final List<? extends PsiElement> elements,
final boolean onTheFly,
@NotNull final ProgressIndicator indicator,
@NotNull final InspectionManager iManager,
final boolean inVisibleRange,
@NotNull final List<? extends LocalInspectionToolWrapper> wrappers,
@NotNull Set<? extends PsiFile> alreadyVisitedInjected) {
private Set<PsiFile> inspectInjectedPsi(@NotNull final List<? extends PsiElement> elements,
final boolean onTheFly,
@NotNull final ProgressIndicator indicator,
@NotNull final InspectionManager iManager,
final boolean inVisibleRange,
@NotNull final List<? extends LocalInspectionToolWrapper> wrappers,
@NotNull Set<? extends PsiFile> alreadyVisitedInjected) {
if (!myInspectInjectedPsi) return Collections.emptySet();
Set<PsiFile> 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<IntentionAction> 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<ProblemDescriptor> descriptors, @NotNull LocalInspectionToolWrapper tool) {
private void appendDescriptors(@NotNull PsiFile file, @NotNull List<? extends ProblemDescriptor> 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<IntentionAction> getQuickFixes(@NotNull LocalInspectionToolWrapper tool,
@NotNull ProblemDescriptor descriptor,
@NotNull Set<? super Pair<TextRange, String>> emptyActionRegistered) {
@@ -676,20 +676,15 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
final FileViewProvider viewProvider = file.getViewProvider();
Set<Language> 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<? super Language> outProcessedLanguages, Set<? super String> outDialectIds) {
private static void appendDialects(@NotNull PsiElement element,
@NotNull Set<? super Language> outProcessedLanguages,
@NotNull Set<? super String> 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<ProblemDescriptor> foundProblems;
@NotNull
private final LocalInspectionToolWrapper tool;
@NotNull
private final List<? extends ProblemDescriptor> foundProblems;
private InspectionResult(@NotNull LocalInspectionToolWrapper tool, @NotNull List<ProblemDescriptor> foundProblems) {
private InspectionResult(@NotNull LocalInspectionToolWrapper tool, @NotNull List<? extends ProblemDescriptor> foundProblems) {
this.tool = tool;
this.foundProblems = new ArrayList<>(foundProblems);
}