mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
suppress non-inspections in editor
This commit is contained in:
@@ -9,14 +9,14 @@ public class HighlightDisplayKey {
|
||||
private static final Map<HighlightDisplayKey, String> ourKeyToDisplayNameMap = new HashMap<HighlightDisplayKey, String>();
|
||||
|
||||
public static final HighlightDisplayKey DEPRECATED_SYMBOL = register("DEPRECATED_SYMBOL", "Deprecated symbol");
|
||||
public static final HighlightDisplayKey UNUSED_IMPORT = register("UNUSED_IMPORT", "Unused import");
|
||||
public static final HighlightDisplayKey UNUSED_IMPORT = register("UNUSED_IMPORT", "Unused import"); //no suppress
|
||||
public static final HighlightDisplayKey UNUSED_SYMBOL = register("UNUSED_SYMBOL", "Unused symbol");
|
||||
public static final HighlightDisplayKey UNUSED_THROWS_DECL = register("UNUSED_THROWS", "Unused throws declaration");
|
||||
public static final HighlightDisplayKey SILLY_ASSIGNMENT = register("SILLY_ASSIGNMENT", "Silly assignment");
|
||||
public static final HighlightDisplayKey ACCESS_STATIC_VIA_INSTANCE = register("ACCESS_STATIC_VIA_INSTANCE", "Access static member via instance reference");
|
||||
public static final HighlightDisplayKey WRONG_PACKAGE_STATEMENT = register("WRONG_PACKAGE_STATEMENT", "Wrong package statement");
|
||||
public static final HighlightDisplayKey JAVADOC_ERROR = register("JAVADOC_ERROR", "JavaDoc errors");
|
||||
public static final HighlightDisplayKey UNKNOWN_JAVADOC_TAG = register("UNKNOWN_JAVADOC_TAG", "Unknown javadoc tags");
|
||||
public static final HighlightDisplayKey WRONG_PACKAGE_STATEMENT = register("WRONG_PACKAGE_STATEMENT", "Wrong package statement"); //no suppress
|
||||
public static final HighlightDisplayKey JAVADOC_ERROR = register("JAVADOC_ERROR", "JavaDoc errors"); //no suppress
|
||||
public static final HighlightDisplayKey UNKNOWN_JAVADOC_TAG = register("UNKNOWN_JAVADOC_TAG", "Unknown javadoc tags"); //no suppress
|
||||
public static final HighlightDisplayKey EJB_ERROR = register("EJB_ERROR", "EJB errors");
|
||||
public static final HighlightDisplayKey EJB_WARNING = register("EJB_WARNING", "EJB warnings");
|
||||
public static final HighlightDisplayKey ILLEGAL_DEPENDENCY = register("ILLEGAL_DEPENDENCY", "Illegal package dependencies");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
@@ -12,18 +13,27 @@ import com.intellij.util.IncorrectOperationException;
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
class AddNoInspectionCommentAction implements IntentionAction {
|
||||
LocalInspectionTool myTool;
|
||||
public class AddNoInspectionCommentAction implements IntentionAction {
|
||||
PsiElement myContext;
|
||||
private static final String COMMENT_START_TEXT = "//noinspection ";
|
||||
|
||||
private String myDisplayName;
|
||||
private String myID;
|
||||
|
||||
public AddNoInspectionCommentAction(LocalInspectionTool tool, PsiElement context) {
|
||||
myTool = tool;
|
||||
myDisplayName = tool.getDisplayName();
|
||||
myID = tool.getID();
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
public AddNoInspectionCommentAction(HighlightDisplayKey key, PsiElement context) {
|
||||
myID = key.toString();
|
||||
myDisplayName = HighlightDisplayKey.getDisplayNameByKey(key);
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return "Suppress '" + myTool.getID() + "' for statement";
|
||||
return "Suppress '" + myDisplayName + "' for statement";
|
||||
}
|
||||
|
||||
private PsiStatement getContainer() {
|
||||
@@ -46,12 +56,12 @@ class AddNoInspectionCommentAction implements IntentionAction {
|
||||
if (prev instanceof PsiComment) {
|
||||
String text = prev.getText();
|
||||
if (text.startsWith(COMMENT_START_TEXT)) {
|
||||
prev.replace(factory.createCommentFromText(text + "," + myTool.getID(), null));
|
||||
prev.replace(factory.createCommentFromText(text + "," + myID, null));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
container.addAfter(factory.createCommentFromText(COMMENT_START_TEXT + myTool.getID(), null), null);
|
||||
container.getParent().addBefore(factory.createCommentFromText(COMMENT_START_TEXT + myID, null), container);
|
||||
QuickFixAction.markDocumentForUndo(file);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.ex.InspectionManagerEx;
|
||||
@@ -14,12 +15,20 @@ import com.intellij.util.IncorrectOperationException;
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
class AddNoInspectionDocTagAction implements IntentionAction {
|
||||
LocalInspectionTool myTool;
|
||||
PsiElement myContext;
|
||||
public class AddNoInspectionDocTagAction implements IntentionAction {
|
||||
private String myDisplayName;
|
||||
private String myID;
|
||||
private PsiElement myContext;
|
||||
|
||||
public AddNoInspectionDocTagAction(LocalInspectionTool tool, PsiElement context) {
|
||||
myTool = tool;
|
||||
myDisplayName = tool.getDisplayName();
|
||||
myID = tool.getID();
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
public AddNoInspectionDocTagAction(HighlightDisplayKey key, PsiElement context) {
|
||||
myDisplayName = HighlightDisplayKey.getDisplayNameByKey(key);
|
||||
myID = key.toString();
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
@@ -27,7 +36,7 @@ class AddNoInspectionDocTagAction implements IntentionAction {
|
||||
PsiDocCommentOwner container = getContainer();
|
||||
|
||||
String subj = container instanceof PsiClass ? "class" : container instanceof PsiMethod ? "method" : "field";
|
||||
return "Suppress '" + myTool.getDisplayName() + "' for " + subj;
|
||||
return "Suppress '" + myDisplayName + "' for " + subj;
|
||||
}
|
||||
|
||||
private PsiDocCommentOwner getContainer() {
|
||||
@@ -53,7 +62,7 @@ class AddNoInspectionDocTagAction implements IntentionAction {
|
||||
PsiDocComment docComment = container.getDocComment();
|
||||
PsiManager manager = myContext.getManager();
|
||||
if (docComment == null) {
|
||||
String commentText = "/** @" + InspectionManagerEx.SUPPRESS_INSPECTIONS_TAG_NAME + " "+ myTool.getID() + "*/";
|
||||
String commentText = "/** @" + InspectionManagerEx.SUPPRESS_INSPECTIONS_TAG_NAME + " "+ myID + "*/";
|
||||
docComment = manager.getElementFactory().createDocCommentFromText(commentText, null);
|
||||
manager.getCodeStyleManager().reformat(docComment);
|
||||
PsiElement firstChild = container.getFirstChild();
|
||||
@@ -67,10 +76,10 @@ class AddNoInspectionDocTagAction implements IntentionAction {
|
||||
PsiDocTag noInspectionTag = docComment.findTagByName(InspectionManagerEx.SUPPRESS_INSPECTIONS_TAG_NAME);
|
||||
if (noInspectionTag != null) {
|
||||
String tagText = "@" + InspectionManagerEx.SUPPRESS_INSPECTIONS_TAG_NAME + " "
|
||||
+ noInspectionTag.getValueElement().getText() + ","+ myTool.getID();
|
||||
+ noInspectionTag.getValueElement().getText() + ","+ myID;
|
||||
noInspectionTag.replace(manager.getElementFactory().createDocTagFromText(tagText, null));
|
||||
} else {
|
||||
String tagText = "@" + InspectionManagerEx.SUPPRESS_INSPECTIONS_TAG_NAME + " " + myTool.getID();
|
||||
String tagText = "@" + InspectionManagerEx.SUPPRESS_INSPECTIONS_TAG_NAME + " " + myID;
|
||||
docComment.add(manager.getElementFactory().createDocTagFromText(tagText, null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.ex.InspectionManagerEx;
|
||||
import com.intellij.j2ee.J2EERolesUtil;
|
||||
import com.intellij.j2ee.ejb.EjbUtil;
|
||||
import com.intellij.j2ee.ejb.role.EjbImplMethodRole;
|
||||
@@ -282,6 +284,8 @@ public class GeneralHighlightingPass extends TextEditorHighlightingPass {
|
||||
builder.analyzeFileDependencies(myFile, new DependenciesBuilder.DependencyProcessor() {
|
||||
public void process(PsiElement place, PsiElement dependency) {
|
||||
PsiFile dependencyFile = dependency.getContainingFile();
|
||||
final InspectionManagerEx iManager = ((InspectionManagerEx)InspectionManager.getInstance(place.getProject()));
|
||||
if (iManager.inspectionResultSuppressed(place, HighlightDisplayKey.ILLEGAL_DEPENDENCY.toString())) return;
|
||||
if (dependencyFile != null && dependencyFile.isPhysical() && dependencyFile.getVirtualFile() != null) {
|
||||
final DependencyRule[] rules = validationManager.getViolatorDependencyRules(myFile, dependencyFile);
|
||||
if (rules.length > 0) {
|
||||
@@ -293,6 +297,7 @@ public class GeneralHighlightingPass extends TextEditorHighlightingPass {
|
||||
for (int i = 0; i < rules.length; i++) {
|
||||
QuickFixAction.registerQuickFixAction(info, new EditDependencyRulesAction(rules[i]));
|
||||
}
|
||||
QuickFixAction.registerQuickFixAction(info, new AddNoInspectionCommentAction(HighlightDisplayKey.ILLEGAL_DEPENDENCY, place));
|
||||
QuickFixAction.registerQuickFixAction(info, new SwitchOffToolAction(HighlightDisplayKey.ILLEGAL_DEPENDENCY));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +134,27 @@ public class LocalInspectionsPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
}
|
||||
|
||||
//for tests only
|
||||
public HighlightInfo[] getHighlights() {
|
||||
final ArrayList<HighlightInfo> highlights = new ArrayList<HighlightInfo>();
|
||||
for (int i = 0; i < myDescriptors.size(); i++) {
|
||||
ProblemDescriptor problemDescriptor = myDescriptors.get(i);
|
||||
final String message = renderDescriptionMessage(problemDescriptor);
|
||||
final PsiElement psiElement = problemDescriptor.getPsiElement();
|
||||
final HighlightInfo highlightInfo =
|
||||
HighlightInfo.createHighlightInfo(HighlightInfoType.WARNING, psiElement, message, message);
|
||||
highlights.add(highlightInfo);
|
||||
if (problemDescriptor.getFix() != null) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new QuickFixWrapper(problemDescriptor));
|
||||
}
|
||||
final LocalInspectionTool tool = myTools.get(i);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new AddNoInspectionCommentAction(tool, psiElement));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new AddNoInspectionDocTagAction(tool, psiElement));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(tool));
|
||||
}
|
||||
return highlights.toArray(new HighlightInfo[highlights.size()]);
|
||||
}
|
||||
|
||||
private void appendDescriptors(ProblemDescriptor[] problemDescriptors, LocalInspectionTool tool) {
|
||||
ProgressManager.getInstance().checkCanceled();
|
||||
|
||||
@@ -144,7 +165,7 @@ public class LocalInspectionsPass extends TextEditorHighlightingPass {
|
||||
HighlightDisplayLevel.ERROR;
|
||||
for (int i = 0; i < problemDescriptors.length; i++) {
|
||||
ProblemDescriptor problemDescriptor = problemDescriptors[i];
|
||||
if (!manager.inspectionResultSuppressed(problemDescriptor.getPsiElement(), tool)) {
|
||||
if (!manager.inspectionResultSuppressed(problemDescriptor.getPsiElement(), tool.getID())) {
|
||||
myDescriptors.add(problemDescriptor);
|
||||
ProblemHighlightType highlightType = problemDescriptor.getHighlightType();
|
||||
HighlightInfoType type = null;
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightMessageUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.*;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.ex.InspectionManagerEx;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
@@ -196,6 +198,9 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
|
||||
private HighlightInfo processIdentifier(PsiIdentifier identifier) {
|
||||
if (!mySettings.getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNUSED_SYMBOL)) return null;
|
||||
final InspectionManagerEx manager = ((InspectionManagerEx)InspectionManager.getInstance(myProject));
|
||||
if (manager.inspectionResultSuppressed(identifier, HighlightDisplayKey.UNUSED_SYMBOL.toString())) return null;
|
||||
if (!manager.isToCheckMember(identifier, HighlightDisplayKey.UNUSED_SYMBOL.toString())) return null;
|
||||
HighlightInfo info;
|
||||
PsiElement parent = identifier.getParent();
|
||||
if (PsiUtil.hasErrorElementChild(parent)) return null;
|
||||
@@ -218,6 +223,10 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
QuickFixAction.registerQuickFixAction(info, new AddNoInspectionCommentAction(HighlightDisplayKey.UNUSED_SYMBOL,
|
||||
identifier));
|
||||
QuickFixAction.registerQuickFixAction(info, new AddNoInspectionDocTagAction(HighlightDisplayKey.UNUSED_SYMBOL,
|
||||
identifier));
|
||||
QuickFixAction.registerQuickFixAction(info, new SwitchOffToolAction(HighlightDisplayKey.UNUSED_SYMBOL));
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.impl.AddNoInspectionCommentAction;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInsight.daemon.impl.SwitchOffToolAction;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.*;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.ex.InspectionManagerEx;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
@@ -396,10 +399,13 @@ public abstract class GenericsHighlightUtil {
|
||||
String description = MessageFormat.format("Unchecked assignment: ''{0}'' to ''{1}''",
|
||||
new Object[]{HighlightUtil.formatType(rType), HighlightUtil.formatType(lType)});
|
||||
if (DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNCHECKED_WARNING)){
|
||||
final InspectionManagerEx iManager = ((InspectionManagerEx)InspectionManager.getInstance(elementToHighlight.getProject()));
|
||||
if (iManager.inspectionResultSuppressed(elementToHighlight, HighlightDisplayKey.UNCHECKED_WARNING.toString())) return null;
|
||||
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.UNCHECKED_WARNING,
|
||||
elementToHighlight,
|
||||
description);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new GenerifyFileFix(elementToHighlight.getContainingFile()));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new AddNoInspectionCommentAction(HighlightDisplayKey.UNCHECKED_WARNING, elementToHighlight));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.UNCHECKED_WARNING));
|
||||
return highlightInfo;
|
||||
}
|
||||
@@ -428,10 +434,14 @@ public abstract class GenericsHighlightUtil {
|
||||
String description = MessageFormat.format("Unchecked cast: ''{0}'' to ''{1}''",
|
||||
new Object[]{HighlightUtil.formatType(exprType), HighlightUtil.formatType(castType)});
|
||||
if (DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNCHECKED_WARNING)){
|
||||
final InspectionManagerEx iManager = ((InspectionManagerEx)InspectionManager.getInstance(expression.getProject()));
|
||||
if (iManager.inspectionResultSuppressed(expression, HighlightDisplayKey.UNCHECKED_WARNING.toString())) return null;
|
||||
|
||||
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.UNCHECKED_WARNING,
|
||||
typeCast,
|
||||
description);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new GenerifyFileFix(expression.getContainingFile()));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new AddNoInspectionCommentAction(HighlightDisplayKey.UNCHECKED_WARNING, expression));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.UNCHECKED_WARNING));
|
||||
return highlightInfo;
|
||||
}
|
||||
@@ -540,8 +550,11 @@ public abstract class GenericsHighlightUtil {
|
||||
new Object[]{HighlightUtil.formatMethod(method), HighlightUtil.formatType(type)});
|
||||
PsiElement element = call instanceof PsiMethodCallExpression ? (PsiElement)((PsiMethodCallExpression)call).getMethodExpression() : call;
|
||||
if (DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNCHECKED_WARNING)){
|
||||
final InspectionManagerEx iManager = ((InspectionManagerEx)InspectionManager.getInstance(call.getProject()));
|
||||
if (iManager.inspectionResultSuppressed(call, HighlightDisplayKey.UNCHECKED_WARNING.toString())) return null;
|
||||
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.UNCHECKED_WARNING, element, description);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new GenerifyFileFix(element.getContainingFile()));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new AddNoInspectionCommentAction(HighlightDisplayKey.UNCHECKED_WARNING, call));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.UNCHECKED_WARNING));
|
||||
return highlightInfo;
|
||||
}
|
||||
|
||||
@@ -8,11 +8,10 @@ package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
import com.intellij.codeInsight.ExceptionUtil;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInsight.daemon.impl.RefCountHolder;
|
||||
import com.intellij.codeInsight.daemon.impl.SwitchOffToolAction;
|
||||
import com.intellij.codeInsight.daemon.impl.*;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.*;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.ex.InspectionManagerEx;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -298,6 +297,8 @@ public class HighlightMethodUtil {
|
||||
if (!(referenceList.getParent() instanceof PsiMethod)) return null;
|
||||
final PsiMethod method = (PsiMethod)referenceList.getParent();
|
||||
if (referenceList != method.getThrowsList()) return null;
|
||||
final InspectionManagerEx iManager = ((InspectionManagerEx)InspectionManager.getInstance(method.getProject()));
|
||||
if (!iManager.isToCheckMember(method, HighlightDisplayKey.UNUSED_THROWS_DECL.toString())) return null;
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
if (aClass == null) return null;
|
||||
|
||||
@@ -346,6 +347,7 @@ public class HighlightMethodUtil {
|
||||
HighlightInfo errorResult = HighlightInfo.createHighlightInfo(HighlightInfoType.UNUSED_THROWS_DECL, referenceElement, description);
|
||||
|
||||
QuickFixAction.registerQuickFixAction(errorResult, new MethodThrowsFix(method, exceptionType, false));
|
||||
QuickFixAction.registerQuickFixAction(errorResult, new AddNoInspectionDocTagAction(HighlightDisplayKey.UNUSED_THROWS_DECL, method.getBody()));
|
||||
QuickFixAction.registerQuickFixAction(errorResult, new SwitchOffToolAction(HighlightDisplayKey.UNUSED_THROWS_DECL));
|
||||
return errorResult;
|
||||
}
|
||||
@@ -1126,6 +1128,8 @@ public class HighlightMethodUtil {
|
||||
List<MethodSignatureBackedByPsiMethod> superMethodSignatures,
|
||||
DaemonCodeAnalyzerSettings settings) {
|
||||
if (!settings.getInspectionProfile().isToolEnabled(HighlightDisplayKey.DEPRECATED_SYMBOL)) return null;
|
||||
final InspectionManagerEx manager = ((InspectionManagerEx)InspectionManager.getInstance(methodSignature.getMethod().getProject()));
|
||||
if (!manager.isToCheckMember(methodSignature.getMethod(), HighlightDisplayKey.DEPRECATED_SYMBOL.toString())) return null;
|
||||
final PsiMethod method = methodSignature.getMethod();
|
||||
PsiElement methodName = method.getNameIdentifier();
|
||||
for (int i = 0; i < superMethodSignatures.size(); i++) {
|
||||
@@ -1139,6 +1143,7 @@ public class HighlightMethodUtil {
|
||||
String description = MessageFormat.format("Overrides deprecated method in ''{0}''", new Object[]{
|
||||
HighlightMessageUtil.getSymbolName(aClass, PsiSubstitutor.EMPTY)});
|
||||
final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.DEPRECATED, methodName, description);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new AddNoInspectionDocTagAction(HighlightDisplayKey.DEPRECATED_SYMBOL, method));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.DEPRECATED_SYMBOL));
|
||||
return highlightInfo;
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ import com.intellij.codeInsight.CodeInsightColors;
|
||||
import com.intellij.codeInsight.ExceptionUtil;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInsight.daemon.impl.SwitchOffToolAction;
|
||||
import com.intellij.codeInsight.daemon.impl.*;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.*;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.ex.InspectionManagerEx;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
@@ -1557,6 +1557,8 @@ public class HighlightUtil {
|
||||
if (!DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.SILLY_ASSIGNMENT)) {
|
||||
return null;
|
||||
}
|
||||
final InspectionManagerEx iManager = ((InspectionManagerEx)InspectionManager.getInstance(assignment.getProject()));
|
||||
if (iManager.inspectionResultSuppressed(assignment, HighlightDisplayKey.SILLY_ASSIGNMENT.toString())) return null;
|
||||
|
||||
if (assignment.getOperationSign().getTokenType() != JavaTokenType.EQ) return null;
|
||||
PsiExpression lExpression = assignment.getLExpression();
|
||||
@@ -1572,6 +1574,7 @@ public class HighlightUtil {
|
||||
final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.SILLY_ASSIGNMENT,
|
||||
assignment,
|
||||
"Silly assignment");
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new AddNoInspectionCommentAction(HighlightDisplayKey.SILLY_ASSIGNMENT, assignment));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.SILLY_ASSIGNMENT));
|
||||
return highlightInfo;
|
||||
}
|
||||
@@ -1770,6 +1773,8 @@ public class HighlightUtil {
|
||||
if (!DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.ACCESS_STATIC_VIA_INSTANCE)) {
|
||||
return null;
|
||||
}
|
||||
final InspectionManagerEx manager = ((InspectionManagerEx)InspectionManager.getInstance(expr.getProject()));
|
||||
if (manager.inspectionResultSuppressed(expr, HighlightDisplayKey.ACCESS_STATIC_VIA_INSTANCE.toString())) return null;
|
||||
|
||||
if (!(resolved instanceof PsiMember)) return null;
|
||||
final PsiExpression qualifierExpression = expr.getQualifierExpression();
|
||||
@@ -1788,6 +1793,7 @@ public class HighlightUtil {
|
||||
|
||||
final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ACCESS_STATIC_VIA_INSTANCE, expr, description);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new AccessStaticViaInstanceFix(expr, result));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new AddNoInspectionCommentAction(HighlightDisplayKey.ACCESS_STATIC_VIA_INSTANCE, expr));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.ACCESS_STATIC_VIA_INSTANCE));
|
||||
return highlightInfo;
|
||||
}
|
||||
@@ -2034,15 +2040,22 @@ public class HighlightUtil {
|
||||
PsiElement elementToHighlight,
|
||||
DaemonCodeAnalyzerSettings settings) {
|
||||
if (!settings.getInspectionProfile().isToolEnabled(HighlightDisplayKey.DEPRECATED_SYMBOL)) return null;
|
||||
|
||||
if (!(refElement instanceof PsiDocCommentOwner)) return null;
|
||||
if (!((PsiDocCommentOwner)refElement).isDeprecated()) return null;
|
||||
|
||||
final InspectionManagerEx manager = ((InspectionManagerEx)InspectionManager.getInstance(elementToHighlight.getProject()));
|
||||
if (!manager.isToCheckMember(elementToHighlight, HighlightDisplayKey.DEPRECATED_SYMBOL.toString())) return null;
|
||||
if (manager.inspectionResultSuppressed(elementToHighlight, HighlightDisplayKey.DEPRECATED_SYMBOL.toString())) return null;
|
||||
|
||||
String description = MessageFormat.format("''{0}'' is deprecated", new Object[]{
|
||||
HighlightMessageUtil.getSymbolName(refElement, PsiSubstitutor.EMPTY)});
|
||||
|
||||
TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES);
|
||||
final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.DEPRECATED, elementToHighlight.getTextRange(), description,attributes);
|
||||
if (elementToHighlight instanceof PsiDocCommentOwner){
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new AddNoInspectionDocTagAction(HighlightDisplayKey.DEPRECATED_SYMBOL, elementToHighlight));
|
||||
}
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new AddNoInspectionCommentAction(HighlightDisplayKey.DEPRECATED_SYMBOL, elementToHighlight));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.DEPRECATED_SYMBOL));
|
||||
return highlightInfo;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ProblemHighlightType;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.codeInspection.ui.InspectCodePanel;
|
||||
import com.intellij.codeInspection.ui.InspectionResultsView;
|
||||
@@ -187,8 +190,15 @@ public class InspectionManagerEx extends InspectionManager implements JDOMExtern
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isToCheckMember(PsiDocCommentOwner member, String inspectionToolID) {
|
||||
PsiDocComment docComment = member.getDocComment();
|
||||
public boolean isToCheckMember(PsiElement member, String inspectionToolID) {
|
||||
PsiDocCommentOwner owner;
|
||||
if (member instanceof PsiDocCommentOwner){
|
||||
owner = (PsiDocCommentOwner)member;
|
||||
} else {
|
||||
owner = PsiTreeUtil.getParentOfType(member, PsiDocCommentOwner.class);
|
||||
}
|
||||
if (owner == null) return false;
|
||||
PsiDocComment docComment = owner.getDocComment();
|
||||
if (docComment != null) {
|
||||
PsiDocTag inspectionTag = docComment.findTagByName(SUPPRESS_INSPECTIONS_TAG_NAME);
|
||||
if (inspectionTag != null) {
|
||||
@@ -198,7 +208,7 @@ public class InspectionManagerEx extends InspectionManager implements JDOMExtern
|
||||
}
|
||||
}
|
||||
|
||||
PsiModifierList modifierList = member.getModifierList();
|
||||
PsiModifierList modifierList = owner.getModifierList();
|
||||
if (modifierList != null) {
|
||||
PsiAnnotation annotation = modifierList.findAnnotation(SUPPRESS_INSPECTIONS_ANNOTATION_NAME);
|
||||
if (annotation != null) {
|
||||
@@ -218,7 +228,7 @@ public class InspectionManagerEx extends InspectionManager implements JDOMExtern
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean inspectionResultSuppressed(PsiElement place, LocalInspectionTool tool) {
|
||||
public boolean inspectionResultSuppressed(PsiElement place, String id) {
|
||||
PsiStatement statement = PsiTreeUtil.getParentOfType(place, PsiStatement.class);
|
||||
if (statement != null) {
|
||||
PsiElement prev = PsiTreeUtil.skipSiblingsBackward(statement, new Class[]{PsiWhiteSpace.class});
|
||||
@@ -226,7 +236,7 @@ public class InspectionManagerEx extends InspectionManager implements JDOMExtern
|
||||
String text = prev.getText();
|
||||
Matcher matcher = SUPPRESS_PATTERN.matcher(text);
|
||||
if (matcher.matches()) {
|
||||
return isInspectionToolIdMentioned(matcher.group(1), tool.getID());
|
||||
return isInspectionToolIdMentioned(matcher.group(1), id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public final class LocalInspectionToolWrapper extends DescriptorProviderInspecti
|
||||
if (getManager().isToCheckMember(field, myTool.getID())) {
|
||||
ProblemDescriptor[] problemDescriptions = myTool.checkField(field, getManager(), false);
|
||||
if (problemDescriptions != null) {
|
||||
problemDescriptions = filterUnsuppressedPeoblemDescriptions(problemDescriptions);
|
||||
problemDescriptions = filterUnsuppressedProblemDescriptions(problemDescriptions);
|
||||
RefManager refManager = getManager().getRefManager();
|
||||
RefElement refElement = refManager.getReference(field);
|
||||
if (refElement != null) {
|
||||
@@ -55,11 +55,11 @@ public final class LocalInspectionToolWrapper extends DescriptorProviderInspecti
|
||||
}
|
||||
}
|
||||
|
||||
private ProblemDescriptor[] filterUnsuppressedPeoblemDescriptions(ProblemDescriptor[] problemDescriptions) {
|
||||
private ProblemDescriptor[] filterUnsuppressedProblemDescriptions(ProblemDescriptor[] problemDescriptions) {
|
||||
Set<ProblemDescriptor> set = null;
|
||||
for (int i = 0; i < problemDescriptions.length; i++) {
|
||||
ProblemDescriptor description = problemDescriptions[i];
|
||||
if (getManager().inspectionResultSuppressed(description.getPsiElement(), myTool)) {
|
||||
if (getManager().inspectionResultSuppressed(description.getPsiElement(), myTool.getID())) {
|
||||
if (set == null) set = new LinkedHashSet<ProblemDescriptor>(Arrays.asList(problemDescriptions));
|
||||
set.remove(description);
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public final class LocalInspectionToolWrapper extends DescriptorProviderInspecti
|
||||
if (getManager().isToCheckMember(aClass, myTool.getID()) && !(aClass instanceof PsiTypeParameter)) {
|
||||
ProblemDescriptor[] problemDescriptions = myTool.checkClass(aClass, getManager(), false);
|
||||
if (problemDescriptions != null) {
|
||||
problemDescriptions = filterUnsuppressedPeoblemDescriptions(problemDescriptions);
|
||||
problemDescriptions = filterUnsuppressedProblemDescriptions(problemDescriptions);
|
||||
RefManager refManager = getManager().getRefManager();
|
||||
RefElement refElement = refManager.getReference(aClass);
|
||||
if (refElement != null) {
|
||||
@@ -88,7 +88,7 @@ public final class LocalInspectionToolWrapper extends DescriptorProviderInspecti
|
||||
if (getManager().isToCheckMember(method, myTool.getID())) {
|
||||
ProblemDescriptor[] problemDescriptions = myTool.checkMethod(method, getManager(), false);
|
||||
if (problemDescriptions != null) {
|
||||
problemDescriptions = filterUnsuppressedPeoblemDescriptions(problemDescriptions);
|
||||
problemDescriptions = filterUnsuppressedProblemDescriptions(problemDescriptions);
|
||||
RefManager refManager = getManager().getRefManager();
|
||||
RefElement refElement = refManager.getReference(method);
|
||||
if (refElement != null) {
|
||||
|
||||
Reference in New Issue
Block a user