mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-26 19:06:24 +07:00
Introduced BatchSuppressableTool which, unlike CustomSuppressableInspectionTool, provides SuppressQuickFixes, not SuppressIntentionActions.
SuppressQuickFix doesn't need Editor so it can work in batches. These fixes are available via BatchSuppressManager. Reworked some inspections to extend BatchSuppressableTool instead of CustomSuppressableInspectionTool since they don't need Editor anyway. Similarly, instead of BaseJavaLocalInspectionTool there is BaseJavaBatchLocalInspectionTool.
This commit is contained in:
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class AbstractBaseJavaLocalInspectionTool extends LocalInspectionTool {
|
||||
/**
|
||||
* Override this to report problems at method level.
|
||||
*
|
||||
* @param method to check.
|
||||
* @param manager InspectionManager to ask for ProblemDescriptors from.
|
||||
* @param isOnTheFly true if called during on the fly editor highlighting. Called from Inspect Code action otherwise.
|
||||
* @return <code>null</code> if no problems found or not applicable at method level.
|
||||
*/
|
||||
@Nullable
|
||||
public ProblemDescriptor[] checkMethod(@NotNull PsiMethod method, @NotNull InspectionManager manager, boolean isOnTheFly) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to report problems at class level.
|
||||
*
|
||||
* @param aClass to check.
|
||||
* @param manager InspectionManager to ask for ProblemDescriptors from.
|
||||
* @param isOnTheFly true if called during on the fly editor highlighting. Called from Inspect Code action otherwise.
|
||||
* @return <code>null</code> if no problems found or not applicable at class level.
|
||||
*/
|
||||
@Nullable
|
||||
public ProblemDescriptor[] checkClass(@NotNull PsiClass aClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to report problems at field level.
|
||||
*
|
||||
* @param field to check.
|
||||
* @param manager InspectionManager to ask for ProblemDescriptors from.
|
||||
* @param isOnTheFly true if called during on the fly editor highlighting. Called from Inspect Code action otherwise.
|
||||
* @return <code>null</code> if no problems found or not applicable at field level.
|
||||
*/
|
||||
@Nullable
|
||||
public ProblemDescriptor[] checkField(@NotNull PsiField field, @NotNull InspectionManager manager, boolean isOnTheFly) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to report problems at file level.
|
||||
*
|
||||
* @param file to check.
|
||||
* @param manager InspectionManager to ask for ProblemDescriptors from.
|
||||
* @param isOnTheFly true if called during on the fly editor highlighting. Called from Inspect Code action otherwise.
|
||||
* @return <code>null</code> if no problems found or not applicable at file level.
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
|
||||
return new JavaElementVisitor() {
|
||||
@Override public void visitMethod(PsiMethod method) {
|
||||
addDescriptors(checkMethod(method, holder.getManager(), isOnTheFly));
|
||||
}
|
||||
|
||||
@Override public void visitClass(PsiClass aClass) {
|
||||
addDescriptors(checkClass(aClass, holder.getManager(), isOnTheFly));
|
||||
}
|
||||
|
||||
@Override public void visitField(PsiField field) {
|
||||
addDescriptors(checkField(field, holder.getManager(), isOnTheFly));
|
||||
}
|
||||
|
||||
@Override public void visitFile(PsiFile file) {
|
||||
addDescriptors(checkFile(file, holder.getManager(), isOnTheFly));
|
||||
}
|
||||
private void addDescriptors(final ProblemDescriptor[] descriptors) {
|
||||
if (descriptors != null) {
|
||||
for (ProblemDescriptor descriptor : descriptors) {
|
||||
holder.registerProblem(descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiNamedElement getProblemElement(final PsiElement psiElement) {
|
||||
return PsiTreeUtil.getNonStrictParentOfType(psiElement, PsiFile.class, PsiClass.class, PsiMethod.class, PsiField.class);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class BaseJavaBatchLocalInspectionTool extends AbstractBaseJavaLocalInspectionTool implements BatchSuppressableTool {
|
||||
@NotNull
|
||||
@Override
|
||||
public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) {
|
||||
return SuppressQuickFix.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuppressedFor(@NotNull PsiElement element) {
|
||||
return isSuppressedFor(element, this);
|
||||
}
|
||||
|
||||
public static boolean isSuppressedFor(@NotNull PsiElement element, @NotNull LocalInspectionTool tool) {
|
||||
final BatchSuppressManager manager = BatchSuppressManager.SERVICE.getInstance();
|
||||
String alternativeId;
|
||||
String id;
|
||||
return manager.isSuppressedFor(element, id = tool.getID()) ||
|
||||
(alternativeId = tool.getAlternativeID()) != null &&
|
||||
!alternativeId.equals(id) &&
|
||||
manager.isSuppressedFor(element, alternativeId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.psi.PsiDocCommentOwner;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface BatchSuppressManager {
|
||||
class SERVICE {
|
||||
public static BatchSuppressManager getInstance() {
|
||||
return ServiceManager.getService(BatchSuppressManager.class);
|
||||
}
|
||||
}
|
||||
@NotNull
|
||||
SuppressQuickFix[] createBatchSuppressActions(@NotNull HighlightDisplayKey key);
|
||||
|
||||
boolean isSuppressedFor(@NotNull PsiElement element, String toolId);
|
||||
|
||||
PsiElement getElementMemberSuppressedIn(@NotNull PsiDocCommentOwner owner, String inspectionToolID);
|
||||
|
||||
@Nullable
|
||||
PsiElement getAnnotationMemberSuppressedIn(@NotNull PsiModifierListOwner owner, String inspectionToolID);
|
||||
|
||||
@Nullable
|
||||
PsiElement getDocCommentToolSuppressedIn(@NotNull PsiDocCommentOwner owner, String inspectionToolID);
|
||||
|
||||
@NotNull
|
||||
Collection<String> getInspectionIdsSuppressedInAnnotation(@NotNull PsiModifierListOwner owner);
|
||||
|
||||
@Nullable
|
||||
String getSuppressedInspectionIdsIn(@NotNull PsiElement element);
|
||||
|
||||
@Nullable
|
||||
PsiElement getElementToolSuppressedIn(@NotNull PsiElement place, String toolId);
|
||||
|
||||
boolean canHave15Suppressions(@NotNull PsiElement file);
|
||||
|
||||
boolean alreadyHas14Suppressions(@NotNull PsiDocCommentOwner commentOwner);
|
||||
}
|
||||
Reference in New Issue
Block a user