switch off inspection profile setting for editor

This commit is contained in:
Anna Kozlova
2005-02-07 22:31:36 +03:00
parent c78873829b
commit ccd6f6e81a
11 changed files with 128 additions and 71 deletions

View File

@@ -1,22 +1,29 @@
package com.intellij.codeInsight.daemon;
import com.intellij.util.containers.HashMap;
import com.intellij.ui.DocumentAdapter;
import javax.swing.event.DocumentEvent;
import java.util.Map;
public class HighlightDisplayKey {
private static final HashMap<String,HighlightDisplayKey> ourMap = new HashMap<String, 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_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 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");
public static final HighlightDisplayKey UNCHECKED_ASSIGNMENT = register("UNCHECKED_ASSIGNMENT", "Unchecked assignment");
public static final HighlightDisplayKey DEPRECATED_SYMBOL = register("DEPRECATED_SYMBOL");
public static final HighlightDisplayKey UNUSED_IMPORT = register("UNUSED_IMPORT");
public static final HighlightDisplayKey UNUSED_SYMBOL = register("UNUSED_SYMBOL");
public static final HighlightDisplayKey UNUSED_THROWS_DECL = register("UNUSED_THROWS");
public static final HighlightDisplayKey SILLY_ASSIGNMENT = register("SILLY_ASSIGNMENT");
public static final HighlightDisplayKey ACCESS_STATIC_VIA_INSTANCE = register("ACCESS_STATIC_VIA_INSTANCE");
public static final HighlightDisplayKey WRONG_PACKAGE_STATEMENT = register("WRONG_PACKAGE_STATEMENT");
public static final HighlightDisplayKey JAVADOC_ERROR = register("JAVADOC_ERROR");
public static final HighlightDisplayKey UNKNOWN_JAVADOC_TAG = register("UNKNOWN_JAVADOC_TAG");
public static final HighlightDisplayKey EJB_ERROR = register("EJB_ERROR");
public static final HighlightDisplayKey EJB_WARNING = register("EJB_WARNING");
public static final HighlightDisplayKey ILLEGAL_DEPENDENCY = register("ILLEGAL_DEPENDENCY");
private final String myName;
@@ -29,6 +36,17 @@ public class HighlightDisplayKey {
return new HighlightDisplayKey(name);
}
public static HighlightDisplayKey register(String name, String displayName){
if (find(name) != null) throw new IllegalArgumentException("Key already registered");
final HighlightDisplayKey highlightDisplayKey = new HighlightDisplayKey(name);
ourKeyToDisplayNameMap.put(highlightDisplayKey, displayName);
return highlightDisplayKey;
}
public static String getDisplayNameByKey(HighlightDisplayKey key){
return ourKeyToDisplayNameMap.get(key);
}
private HighlightDisplayKey(String name) {
myName = name;
ourMap.put(myName, this);

View File

@@ -3,10 +3,12 @@ package com.intellij.codeInsight.daemon.impl;
import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInsight.CodeInsightColors;
import com.intellij.codeInsight.CodeInsightUtil;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
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.j2ee.J2EERolesUtil;
import com.intellij.j2ee.ejb.EjbUtil;
import com.intellij.j2ee.ejb.role.EjbImplMethodRole;
@@ -15,6 +17,7 @@ import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.markup.SeparatorPlacement;
@@ -24,14 +27,21 @@ import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.packageDependencies.DependenciesBuilder;
import com.intellij.packageDependencies.DependencyRule;
import com.intellij.packageDependencies.DependencyValidationManager;
import com.intellij.packageDependencies.ForwardDependenciesBuilder;
import com.intellij.packageDependencies.ui.DependencyConfigurable;
import com.intellij.psi.*;
import com.intellij.psi.search.PsiSearchHelper;
import com.intellij.psi.search.TodoItem;
import com.intellij.psi.util.PsiSuperMethodUtil;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.util.IncorrectOperationException;
import com.intellij.application.options.ErrorHighlightingPanel;
import com.intellij.application.options.ErrorHighlightingOptions;
import com.intellij.uiDesigner.quickFixes.QuickFixManager;
import gnu.trove.THashSet;
import javax.swing.*;
@@ -284,6 +294,8 @@ public class GeneralHighlightingPass extends TextEditorHighlightingPass {
"\"");
if (info != null) {
list.add(info);
QuickFixAction.registerQuickFixAction(info, new EditDependencyRulesAction(rule));
QuickFixAction.registerQuickFixAction(info, new SwitchOffToolAction(HighlightDisplayKey.ILLEGAL_DEPENDENCY));
}
}
}
@@ -385,4 +397,31 @@ public class GeneralHighlightingPass extends TextEditorHighlightingPass {
}
return 0;
}
}
private static class EditDependencyRulesAction implements IntentionAction {
private DependencyRule myRule;
public EditDependencyRulesAction(final DependencyRule rule) {
myRule = rule;
}
public String getText() {
return "Edit dependency rule \"" + myRule.getDisplayText() + " \"";
}
public String getFamilyName() {
return "Edit dependency rules";
}
public boolean isAvailable(Project project, Editor editor, PsiFile file) {
return true;
}
public void invoke(Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
ShowSettingsUtil.getInstance().editConfigurable(project, new DependencyConfigurable(project));
}
public boolean startInWriteAction() {
return false;
}
}
}

View File

@@ -20,6 +20,7 @@ public interface HighlightInfoType {
HighlightInfoType EJB_WARNING = new HighlightInfoTypeSeverityByKeyAttrBySeverity(HighlightDisplayKey.EJB_WARNING);
HighlightInfoType ILLEGAL_DEPENDENCY = new HighlightInfoTypeSeverityByKeyAttrBySeverity(HighlightDisplayKey.ILLEGAL_DEPENDENCY);
HighlightInfoType UNCHECKED_ASSIGNMENT = new HighlightInfoTypeSeverityByKeyAttrBySeverity(HighlightDisplayKey.UNCHECKED_ASSIGNMENT);
HighlightInfoType WRONG_ELEMENT_NAME = new HighlightInfoTypeImpl(HighlightSeverity.ERROR, CodeInsightColors.ERRORS_ATTRIBUTES);

View File

@@ -233,38 +233,4 @@ public class LocalInspectionsPass extends TextEditorHighlightingPass {
return message;
}
private static class SwitchOffToolAction implements IntentionAction {
private final LocalInspectionTool myTool;
public SwitchOffToolAction(LocalInspectionTool tool) {
myTool = tool;
}
public String getText() {
return "Edit options of \"" + myTool.getDisplayName() + "\"";
}
public String getFamilyName() {
return "Edit options of reporter inspection";
}
public boolean isAvailable(Project project, Editor editor, PsiFile file) {
return true;
}
public void invoke(Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
Runnable selectTool = new Runnable() {
public void run() {
final ErrorHighlightingPanel panel = ErrorHighlightingOptions.getInstance().getPanel();
panel.selectInspectionTool(myTool.getShortName());
}
};
ShowSettingsUtil.getInstance().editConfigurable(project, ErrorHighlightingOptions.getInstance(), selectTool);
}
public boolean startInWriteAction() {
return false;
}
}
}

View File

@@ -196,28 +196,30 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
private HighlightInfo processIdentifier(PsiIdentifier identifier) {
if (!mySettings.getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNUSED_SYMBOL)) return null;
HighlightInfo info;
PsiElement parent = identifier.getParent();
if (PsiUtil.hasErrorElementChild(parent)) return null;
if (parent instanceof PsiLocalVariable) {
return processLocalVariable((PsiLocalVariable)parent);
info = processLocalVariable((PsiLocalVariable)parent);
}
else if (parent instanceof PsiField) {
return processField((PsiField)parent);
info = processField((PsiField)parent);
}
else if (parent instanceof PsiParameter) {
return processParameter((PsiParameter)parent);
info = processParameter((PsiParameter)parent);
}
else if (parent instanceof PsiMethod) {
return processMethod((PsiMethod)parent);
info = processMethod((PsiMethod)parent);
}
else if (parent instanceof PsiClass && identifier.equals(((PsiClass)parent).getNameIdentifier())) {
return processClass((PsiClass)parent);
info = processClass((PsiClass)parent);
}
else {
return null;
}
QuickFixAction.registerQuickFixAction(info, new SwitchOffToolAction(HighlightDisplayKey.UNUSED_SYMBOL));
return info;
}
private HighlightInfo processLocalVariable(PsiLocalVariable variable) {
@@ -450,6 +452,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.UNUSED_IMPORT, importStatement, "Unused import statement");
QuickFixAction.registerQuickFixAction(info, new OptimizeImportsFix());
QuickFixAction.registerQuickFixAction(info, new EnableOptimizeImportsOnTheFlyFix());
QuickFixAction.registerQuickFixAction(info, new SwitchOffToolAction(HighlightDisplayKey.UNUSED_IMPORT));
myHasRedundantImports = true;
return info;
}

View File

@@ -1,8 +1,10 @@
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.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.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
@@ -393,11 +395,15 @@ public abstract class GenericsHighlightUtil {
if (!isGenericToRaw(lType, rType)) return null;
String description = MessageFormat.format("Unchecked assignment: ''{0}'' to ''{1}''",
new Object[]{HighlightUtil.formatType(rType), HighlightUtil.formatType(lType)});
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.WARNING,
elementToHighlight,
description);
QuickFixAction.registerQuickFixAction(highlightInfo, new GenerifyFileFix(elementToHighlight.getContainingFile()));
return highlightInfo;
if (DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNCHECKED_ASSIGNMENT)){
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.UNCHECKED_ASSIGNMENT,
elementToHighlight,
description);
QuickFixAction.registerQuickFixAction(highlightInfo, new GenerifyFileFix(elementToHighlight.getContainingFile()));
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.UNCHECKED_ASSIGNMENT));
return highlightInfo;
}
return null;
}
private static boolean isGenericToRaw(PsiType lType, PsiType rType) {
@@ -421,11 +427,14 @@ public abstract class GenericsHighlightUtil {
if (isUncheckedTypeCast(castType, exprType)) {
String description = MessageFormat.format("Unchecked cast: ''{0}'' to ''{1}''",
new Object[]{HighlightUtil.formatType(exprType), HighlightUtil.formatType(castType)});
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.WARNING,
typeCast,
description);
QuickFixAction.registerQuickFixAction(highlightInfo, new GenerifyFileFix(expression.getContainingFile()));
return highlightInfo;
if (DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNCHECKED_ASSIGNMENT)){
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.UNCHECKED_ASSIGNMENT,
typeCast,
description);
QuickFixAction.registerQuickFixAction(highlightInfo, new GenerifyFileFix(expression.getContainingFile()));
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.UNCHECKED_ASSIGNMENT));
return highlightInfo;
}
}
return null;
}
@@ -530,9 +539,12 @@ public abstract class GenericsHighlightUtil {
String description = MessageFormat.format("Unchecked call to ''{0}'' as a member of raw type ''{1}''",
new Object[]{HighlightUtil.formatMethod(method), HighlightUtil.formatType(type)});
PsiElement element = call instanceof PsiMethodCallExpression ? (PsiElement)((PsiMethodCallExpression)call).getMethodExpression() : call;
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.WARNING, element, description);
QuickFixAction.registerQuickFixAction(highlightInfo, new GenerifyFileFix(element.getContainingFile()));
return highlightInfo;
if (DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNCHECKED_ASSIGNMENT)){
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.UNCHECKED_ASSIGNMENT, element, description);
QuickFixAction.registerQuickFixAction(highlightInfo, new GenerifyFileFix(element.getContainingFile()));
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.UNCHECKED_ASSIGNMENT));
return highlightInfo;
}
}
}
return null;

View File

@@ -11,6 +11,7 @@ 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.quickfix.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
@@ -460,6 +461,7 @@ public class HighlightClassUtil {
description);
if (classPackage != null) QuickFixAction.registerQuickFixAction(highlightInfo, new MoveToPackageFix(file, classPackage));
QuickFixAction.registerQuickFixAction(highlightInfo, new AdjustPackageNameFix(file, statement, dirPackage));
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.WRONG_PACKAGE_STATEMENT));
return highlightInfo;
}
return null;
@@ -495,6 +497,7 @@ public class HighlightClassUtil {
textRange,
description);
QuickFixAction.registerQuickFixAction(highlightInfo, new AdjustPackageNameFix(javaFile, null, dirPackage));
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.WRONG_PACKAGE_STATEMENT));
return highlightInfo;
}
return null;

View File

@@ -11,6 +11,7 @@ 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.quickfix.*;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Comparing;
@@ -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 SwitchOffToolAction(HighlightDisplayKey.UNUSED_THROWS_DECL));
return errorResult;
}
@@ -1142,7 +1144,9 @@ public class HighlightMethodUtil {
if (superMethod.isDeprecated()) {
String description = MessageFormat.format("Overrides deprecated method in ''{0}''", new Object[]{
HighlightMessageUtil.getSymbolName(aClass, PsiSubstitutor.EMPTY)});
return HighlightInfo.createHighlightInfo(HighlightInfoType.DEPRECATED, methodName, description);
final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.DEPRECATED, methodName, description);
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.DEPRECATED_SYMBOL));
return highlightInfo;
}
}
return null;

View File

@@ -15,6 +15,7 @@ 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.quickfix.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Comparing;
@@ -1570,9 +1571,11 @@ public class HighlightUtil {
final PsiReferenceExpression rRef = (PsiReferenceExpression)rExpression;
final PsiManager manager = assignment.getManager();
if (!sameInstanceReferences(lRef, rRef, manager)) return null;
return HighlightInfo.createHighlightInfo(HighlightInfoType.SILLY_ASSIGNMENT,
assignment,
"Silly assignment");
final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.SILLY_ASSIGNMENT,
assignment,
"Silly assignment");
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.SILLY_ASSIGNMENT));
return highlightInfo;
}
/**
@@ -1791,6 +1794,7 @@ public class HighlightUtil {
expr,
description);
QuickFixAction.registerQuickFixAction(highlightInfo, new AccessStaticViaInstanceFix(expr, result));
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.ACCESS_STATIC_VIA_INSTANCE));
return highlightInfo;
}
@@ -1943,6 +1947,7 @@ public class HighlightUtil {
return null;
}
type = HighlightInfoType.JAVADOC_WRONG_REF;
QuickFixAction.registerQuickFixAction(HighlightInfo.createHighlightInfo(type, refName, description), new SwitchOffToolAction(HighlightDisplayKey.JAVADOC_ERROR));
}
PsiElement parent = PsiTreeUtil.getParentOfType(ref, new Class[]{PsiNewExpression.class, PsiMethod.class});
@@ -2042,6 +2047,8 @@ public class HighlightUtil {
String description = MessageFormat.format("''{0}'' is deprecated", new Object[]{
HighlightMessageUtil.getSymbolName(refElement, PsiSubstitutor.EMPTY)});
return HighlightInfo.createHighlightInfo(HighlightInfoType.DEPRECATED, elementToHighlight, description);
final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.DEPRECATED, elementToHighlight, description);
QuickFixAction.registerQuickFixAction(highlightInfo, new SwitchOffToolAction(HighlightDisplayKey.DEPRECATED_SYMBOL));
return highlightInfo;
}
}

View File

@@ -253,6 +253,7 @@ public class InspectionProfileImpl implements InspectionProfile.ModifiableModel,
myDisplayLevelMap.put(HighlightDisplayKey.EJB_ERROR, new ToolState(HighlightDisplayLevel.ERROR));
myDisplayLevelMap.put(HighlightDisplayKey.EJB_WARNING, new ToolState(HighlightDisplayLevel.WARNING));
myDisplayLevelMap.put(HighlightDisplayKey.ILLEGAL_DEPENDENCY, new ToolState(HighlightDisplayLevel.WARNING));
myDisplayLevelMap.put(HighlightDisplayKey.UNCHECKED_ASSIGNMENT, new ToolState(HighlightDisplayLevel.WARNING));
}
public String getName() {

View File

@@ -1,6 +1,7 @@
package com.intellij.codeInspection.ex;
import com.intellij.codeInspection.InspectionToolProvider;
import com.intellij.codeInspection.dependencyViolation.DependencyViolationInspection;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.codeInsight.i18n.StringI18nInspection;
@@ -45,6 +46,8 @@ public class StandardInspectionToolsProvider implements InspectionToolProvider,
StringI18nInspection.class,
DependencyViolationInspection.class
};
}
}