mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
[java] SuppressManagerImpl: split into Service and EP
GitOrigin-RevId: 0a85fbd2e3594f5f99114f512abcaae1cdc1bee6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
16621ed8ec
commit
2b5ef8b70e
@@ -47,7 +47,7 @@
|
||||
<highlightingPassFactory implementation="com.intellij.codeInsight.daemon.impl.JavaTextBlockIndentPassFactory"/>
|
||||
<deadCode implementation="com.intellij.codeInspection.java19modules.Java9ModuleEntryPoint"/>
|
||||
<metaLanguage implementation="com.intellij.uast.UastMetaLanguage"/>
|
||||
<lang.inspectionSuppressor language="JAVA" implementationClass="com.intellij.codeInspection.SuppressManagerImpl"/>
|
||||
<lang.inspectionSuppressor language="JAVA" implementationClass="com.intellij.codeInspection.JavaInspectionSuppressor"/>
|
||||
<projectService serviceImplementation="com.intellij.codeInspection.bytecodeAnalysis.ProjectBytecodeAnalysis"/>
|
||||
<generatedSourcesFilter implementation="com.intellij.openapi.roots.JavaGeneratedSourcesFilter"/>
|
||||
<!--suppress PluginXmlCapitalization -->
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
final class JavaInspectionSuppressor implements InspectionSuppressor, RedundantSuppressionDetector {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(JavaInspectionSuppressor.class);
|
||||
|
||||
@Override
|
||||
public boolean isSuppressedFor(@NotNull PsiElement element, @NotNull String toolId) {
|
||||
return JavaSuppressionUtil.getElementToolSuppressedIn(element, toolId) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuppressQuickFix @NotNull [] getSuppressActions(@Nullable PsiElement element, @NotNull String toolId) {
|
||||
HighlightDisplayKey displayKey = HighlightDisplayKey.findById(toolId);
|
||||
LOG.assertTrue(displayKey != null, "Display key is null for `" + toolId + "` tool");
|
||||
return SuppressManager.getInstance().createBatchSuppressActions(displayKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSuppressionIds(@NotNull PsiElement element) {
|
||||
return JavaSuppressionUtil.getSuppressedInspectionIdsIn(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuppressionFor(@NotNull PsiElement elementWithSuppression, @NotNull PsiElement place, @NotNull String toolId) {
|
||||
PsiElement suppressionScope = JavaSuppressionUtil.getElementToolSuppressedIn(place, toolId);
|
||||
return suppressionScope != null && PsiTreeUtil.isAncestor(elementWithSuppression, suppressionScope, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TextRange getHighlightingRange(@NotNull PsiElement elementWithSuppression, @NotNull String toolId) {
|
||||
PsiElement annotationOrTagElement = elementWithSuppression instanceof PsiComment
|
||||
? null : SuppressManager.getInstance().getElementToolSuppressedIn(elementWithSuppression, toolId);
|
||||
if (annotationOrTagElement != null) {
|
||||
int shiftInParent = annotationOrTagElement.getTextRange().getStartOffset() - elementWithSuppression.getTextRange().getStartOffset();
|
||||
if (shiftInParent < 0) {
|
||||
return null; //non-normalized declaration
|
||||
}
|
||||
return Objects.requireNonNull(RedundantSuppressionDetector.super.getHighlightingRange(annotationOrTagElement, toolId))
|
||||
.shiftRight(shiftInParent);
|
||||
}
|
||||
return RedundantSuppressionDetector.super.getHighlightingRange(elementWithSuppression, toolId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull LocalQuickFix createRemoveRedundantSuppressionFix(@NotNull String toolId) {
|
||||
return new RemoveSuppressWarningAction(toolId);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,16 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiDocCommentOwner;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
final class SuppressManagerImpl extends SuppressManager {
|
||||
|
||||
public class SuppressManagerImpl extends SuppressManager implements RedundantSuppressionDetector {
|
||||
private static final Logger LOG = Logger.getInstance(SuppressManager.class);
|
||||
|
||||
@Override
|
||||
@@ -56,34 +52,4 @@ public class SuppressManagerImpl extends SuppressManager implements RedundantSup
|
||||
public boolean alreadyHas14Suppressions(@NotNull PsiDocCommentOwner commentOwner) {
|
||||
return JavaSuppressionUtil.alreadyHas14Suppressions(commentOwner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSuppressionIds(@NotNull PsiElement element) {
|
||||
return JavaSuppressionUtil.getSuppressedInspectionIdsIn(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuppressionFor(@NotNull PsiElement elementWithSuppression, @NotNull PsiElement place, @NotNull String toolId) {
|
||||
PsiElement suppressionScope = JavaSuppressionUtil.getElementToolSuppressedIn(place, toolId);
|
||||
return suppressionScope != null && PsiTreeUtil.isAncestor(elementWithSuppression, suppressionScope, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TextRange getHighlightingRange(@NotNull PsiElement elementWithSuppression, @NotNull String toolId) {
|
||||
PsiElement annotationOrTagElement = elementWithSuppression instanceof PsiComment ? null : getElementToolSuppressedIn(elementWithSuppression, toolId);
|
||||
if (annotationOrTagElement != null) {
|
||||
int shiftInParent = annotationOrTagElement.getTextRange().getStartOffset() - elementWithSuppression.getTextRange().getStartOffset();
|
||||
if (shiftInParent < 0) {
|
||||
return null; //non-normalized declaration
|
||||
}
|
||||
return Objects.requireNonNull(RedundantSuppressionDetector.super.getHighlightingRange(annotationOrTagElement, toolId)).shiftRight(shiftInParent);
|
||||
}
|
||||
return RedundantSuppressionDetector.super.getHighlightingRange(elementWithSuppression, toolId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull LocalQuickFix createRemoveRedundantSuppressionFix(@NotNull String toolId) {
|
||||
return new RemoveSuppressWarningAction(toolId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user