mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
unused inspection settings: allow to configure visibility for members to check
This commit is contained in:
+26
-6
@@ -51,8 +51,11 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.impl.PsiClassImplUtil;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.SuperMethodsSearch;
|
||||
import com.intellij.psi.util.PropertyUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.containers.ConcurrentFactoryMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -212,22 +215,40 @@ class PostHighlightingVisitor {
|
||||
if (parent instanceof PsiLocalVariable && myUnusedSymbolInspection.LOCAL_VARIABLE) {
|
||||
return processLocalVariable((PsiLocalVariable)parent, identifier, progress);
|
||||
}
|
||||
if (parent instanceof PsiField && myUnusedSymbolInspection.FIELD) {
|
||||
if (parent instanceof PsiField && compareVisibilities((PsiModifierListOwner)parent, myUnusedSymbolInspection.getFieldVisibility())) {
|
||||
return processField(myProject, (PsiField)parent, identifier, progress, helper);
|
||||
}
|
||||
if (parent instanceof PsiParameter && myUnusedSymbolInspection.PARAMETER) {
|
||||
if (parent instanceof PsiParameter && compareVisibilities((PsiModifierListOwner)parent, myUnusedSymbolInspection.getParameterVisibility())) {
|
||||
if (SuppressionUtil.isSuppressed(identifier, UnusedSymbolLocalInspectionBase.UNUSED_PARAMETERS_SHORT_NAME)) return null;
|
||||
return processParameter(myProject, (PsiParameter)parent, identifier, progress);
|
||||
}
|
||||
if (parent instanceof PsiMethod && myUnusedSymbolInspection.METHOD) {
|
||||
return processMethod(myProject, (PsiMethod)parent, identifier, progress, helper);
|
||||
if (parent instanceof PsiMethod) {
|
||||
final boolean propertyAccessor = PropertyUtil.isSimplePropertyAccessor((PsiMethod)parent);
|
||||
if (propertyAccessor && myUnusedSymbolInspection.isIgnoreAccessors()) {
|
||||
return null;
|
||||
}
|
||||
if (compareVisibilities((PsiModifierListOwner)parent, myUnusedSymbolInspection.getMethodVisibility())) {
|
||||
return processMethod(myProject, (PsiMethod)parent, identifier, progress, helper);
|
||||
}
|
||||
}
|
||||
if (parent instanceof PsiClass && myUnusedSymbolInspection.CLASS) {
|
||||
if (parent instanceof PsiClass && compareVisibilities((PsiModifierListOwner)parent, myUnusedSymbolInspection.getClassVisibility())) {
|
||||
return processClass(myProject, (PsiClass)parent, identifier, progress, helper);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean compareVisibilities(PsiModifierListOwner listOwner, final String visibility) {
|
||||
if (visibility != null) {
|
||||
while (listOwner != null) {
|
||||
if (VisibilityUtil.compare(VisibilityUtil.getVisibilityModifier(listOwner.getModifierList()), visibility) >= 0) {
|
||||
return true;
|
||||
}
|
||||
listOwner = PsiTreeUtil.getParentOfType(listOwner, PsiModifierListOwner.class, true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private HighlightInfo processLocalVariable(@NotNull PsiLocalVariable variable,
|
||||
@NotNull PsiIdentifier identifier,
|
||||
@@ -357,7 +378,6 @@ class PostHighlightingVisitor {
|
||||
method.hasModifierProperty(PsiModifier.PRIVATE) ||
|
||||
method.hasModifierProperty(PsiModifier.STATIC) ||
|
||||
!method.hasModifierProperty(PsiModifier.ABSTRACT) &&
|
||||
myUnusedSymbolInspection.REPORT_PARAMETER_FOR_PUBLIC_METHODS &&
|
||||
!isOverriddenOrOverrides(method)) &&
|
||||
!method.hasModifierProperty(PsiModifier.NATIVE) &&
|
||||
!JavaHighlightUtil.isSerializationRelatedMethod(method, method.getContainingClass()) &&
|
||||
|
||||
+119
-1
@@ -19,10 +19,14 @@ import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInspection.BaseJavaLocalInspectionTool;
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase;
|
||||
import com.intellij.codeInspection.ex.PairedUnfairLocalInspectionTool;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import org.intellij.lang.annotations.Pattern;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class UnusedSymbolLocalInspectionBase extends BaseJavaLocalInspectionTool {
|
||||
@NonNls public static final String SHORT_NAME = HighlightInfoType.UNUSED_SYMBOL_SHORT_NAME;
|
||||
@@ -36,6 +40,67 @@ public class UnusedSymbolLocalInspectionBase extends BaseJavaLocalInspectionTool
|
||||
public boolean PARAMETER = true;
|
||||
public boolean REPORT_PARAMETER_FOR_PUBLIC_METHODS = true;
|
||||
|
||||
private String myClassVisibility = PsiModifier.PUBLIC;
|
||||
private String myFieldVisibility = PsiModifier.PUBLIC;
|
||||
private String myMethodVisibility = PsiModifier.PUBLIC;
|
||||
private String myParameterVisibility = PsiModifier.PUBLIC;
|
||||
private boolean myIgnoreAccessors = false;
|
||||
|
||||
|
||||
@PsiModifier.ModifierConstant
|
||||
@Nullable
|
||||
public String getClassVisibility() {
|
||||
if (!CLASS || "none".equals(myClassVisibility)) return null;
|
||||
return myClassVisibility;
|
||||
}
|
||||
@PsiModifier.ModifierConstant
|
||||
@Nullable
|
||||
public String getFieldVisibility() {
|
||||
if (!FIELD || "none".equals(myFieldVisibility)) return null;
|
||||
return myFieldVisibility;
|
||||
}
|
||||
@PsiModifier.ModifierConstant
|
||||
@Nullable
|
||||
public String getMethodVisibility() {
|
||||
if (!METHOD || "none".equals(myMethodVisibility)) return null;
|
||||
return myMethodVisibility;
|
||||
}
|
||||
|
||||
@PsiModifier.ModifierConstant
|
||||
@Nullable
|
||||
public String getParameterVisibility() {
|
||||
if (!PARAMETER || "none".equals(myParameterVisibility)) return null;
|
||||
return myParameterVisibility;
|
||||
}
|
||||
|
||||
public void setClassVisibility(String classVisibility) {
|
||||
CLASS = !"none".equals(classVisibility);
|
||||
this.myClassVisibility = classVisibility;
|
||||
}
|
||||
|
||||
public void setFieldVisibility(String fieldVisibility) {
|
||||
FIELD = !"none".equals(fieldVisibility);
|
||||
this.myFieldVisibility = fieldVisibility;
|
||||
}
|
||||
|
||||
public void setMethodVisibility(String methodVisibility) {
|
||||
METHOD = !"none".equals(methodVisibility);
|
||||
this.myMethodVisibility = methodVisibility;
|
||||
}
|
||||
|
||||
public void setParameterVisibility(String parameterVisibility) {
|
||||
PARAMETER = !"none".equals(parameterVisibility);
|
||||
REPORT_PARAMETER_FOR_PUBLIC_METHODS = PsiModifier.PUBLIC.equals(parameterVisibility);
|
||||
this.myParameterVisibility = parameterVisibility;
|
||||
}
|
||||
|
||||
public boolean isIgnoreAccessors() {
|
||||
return myIgnoreAccessors;
|
||||
}
|
||||
|
||||
public void setIgnoreAccessors(boolean ignoreAccessors) {
|
||||
myIgnoreAccessors = ignoreAccessors;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -74,4 +139,57 @@ public class UnusedSymbolLocalInspectionBase extends BaseJavaLocalInspectionTool
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSettings(@NotNull Element node) throws WriteExternalException {
|
||||
writeVisibility(node, myClassVisibility, "inner_class");
|
||||
writeVisibility(node, myFieldVisibility, "field");
|
||||
writeVisibility(node, myMethodVisibility, "method");
|
||||
writeVisibility(node, "parameter", myParameterVisibility, getParameterDefaultVisibility());
|
||||
if (myIgnoreAccessors) {
|
||||
node.setAttribute("ignoreAccessors", Boolean.toString(true));
|
||||
}
|
||||
super.writeSettings(node);
|
||||
}
|
||||
|
||||
private static void writeVisibility(Element node, String visibility, String type) {
|
||||
writeVisibility(node, type, visibility, PsiModifier.PUBLIC);
|
||||
}
|
||||
|
||||
private static void writeVisibility(Element node,
|
||||
String type,
|
||||
String visibility,
|
||||
String defaultVisibility) {
|
||||
if (!defaultVisibility.equals(visibility)) {
|
||||
node.setAttribute(type, visibility);
|
||||
}
|
||||
}
|
||||
|
||||
private String getParameterDefaultVisibility() {
|
||||
return REPORT_PARAMETER_FOR_PUBLIC_METHODS ? PsiModifier.PUBLIC : PsiModifier.PRIVATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSettings(@NotNull Element node) throws InvalidDataException {
|
||||
super.readSettings(node);
|
||||
myClassVisibility = readVisibility(node, "inner_class");
|
||||
myFieldVisibility = readVisibility(node, "field");
|
||||
myMethodVisibility = readVisibility(node, "method");
|
||||
myParameterVisibility = readVisibility(node, "parameter", getParameterDefaultVisibility());
|
||||
final String ignoreAccessors = node.getAttributeValue("ignoreAccessors");
|
||||
myIgnoreAccessors = ignoreAccessors != null && Boolean.parseBoolean(ignoreAccessors);
|
||||
}
|
||||
|
||||
private static String readVisibility(@NotNull Element node, final String type) {
|
||||
return readVisibility(node, type, PsiModifier.PUBLIC);
|
||||
}
|
||||
|
||||
private static String readVisibility(@NotNull Element node,
|
||||
final String type,
|
||||
final String defaultVisibility) {
|
||||
final String visibility = node.getAttributeValue(type);
|
||||
if (visibility == null) {
|
||||
return defaultVisibility;
|
||||
}
|
||||
return visibility;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +1,94 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection.OptionsPanel">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="2">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="7" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="2">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="394" height="400"/>
|
||||
<xy x="357" y="305" width="299" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="empty" title=""/>
|
||||
<children>
|
||||
<component id="b6cc3" class="javax.swing.JCheckBox" binding="myCheckLocalVariablesCheckBox" default-binding="true">
|
||||
<vspacer id="eb5d4">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="172" height="22"/>
|
||||
</grid>
|
||||
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="c6c56" class="com.intellij.openapi.ui.ComboBox" binding="myCheckClassesCheckBox">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="d4721" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="c6c56"/>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.classes"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="4e0ea" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="5954e"/>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.fields"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5954e" class="com.intellij.openapi.ui.ComboBox" binding="myCheckFieldsCheckBox">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="c9f09" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="74fa3"/>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.methods"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="74fa3" class="com.intellij.openapi.ui.ComboBox" binding="myCheckMethodsCheckBox">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="2b841" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="96ef2"/>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.parameters"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="96ef2" class="com.intellij.openapi.ui.ComboBox" binding="myCheckParametersCheckBox">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="38d94" class="javax.swing.JCheckBox" binding="myCheckLocalVariablesCheckBox" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.localvars"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6664b" class="javax.swing.JCheckBox" binding="myCheckParametersCheckBox" default-binding="true">
|
||||
<component id="168d8" class="javax.swing.JCheckBox" binding="myCheckGettersSettersCheckBox" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="172" height="22"/>
|
||||
</grid>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.parameters"/>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.accessors"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c49dc" class="javax.swing.JCheckBox" binding="myCheckMethodsCheckBox" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="172" height="22"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.methods"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2077d" class="javax.swing.JCheckBox" binding="myReportUnusedParametersInPublics" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.public.method.parameters"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b2b9f" class="javax.swing.JCheckBox" binding="myCheckFieldsCheckBox" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.fields"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="bcd0d" class="javax.swing.JCheckBox" binding="myCheckClassesCheckBox" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.classes"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="eb5d4">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
+37
-19
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.intellij.codeInspection.unusedSymbol;
|
||||
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.ui.ListCellRendererWrapper;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -37,34 +40,49 @@ public class UnusedSymbolLocalInspection extends UnusedSymbolLocalInspectionBase
|
||||
|
||||
public class OptionsPanel {
|
||||
private JCheckBox myCheckLocalVariablesCheckBox;
|
||||
private JCheckBox myCheckClassesCheckBox;
|
||||
private JCheckBox myCheckFieldsCheckBox;
|
||||
private JCheckBox myCheckMethodsCheckBox;
|
||||
private JCheckBox myCheckParametersCheckBox;
|
||||
private JCheckBox myReportUnusedParametersInPublics;
|
||||
private JComboBox<String> myCheckClassesCheckBox;
|
||||
private JComboBox<String> myCheckFieldsCheckBox;
|
||||
private JComboBox<String> myCheckMethodsCheckBox;
|
||||
private JComboBox<String> myCheckParametersCheckBox;
|
||||
private JPanel myPanel;
|
||||
private JCheckBox myCheckGettersSettersCheckBox;
|
||||
|
||||
public OptionsPanel() {
|
||||
myCheckLocalVariablesCheckBox.setSelected(LOCAL_VARIABLE);
|
||||
myCheckClassesCheckBox.setSelected(CLASS);
|
||||
myCheckFieldsCheckBox.setSelected(FIELD);
|
||||
myCheckMethodsCheckBox.setSelected(METHOD);
|
||||
myCheckGettersSettersCheckBox.setSelected(!isIgnoreAccessors());
|
||||
String[] visibilities = new String[] {"none", PsiModifier.PUBLIC, PsiModifier.PROTECTED, PsiModifier.PACKAGE_LOCAL, PsiModifier.PRIVATE};
|
||||
myCheckClassesCheckBox.setModel(new DefaultComboBoxModel<>(visibilities));
|
||||
myCheckFieldsCheckBox.setModel(new DefaultComboBoxModel<>(visibilities));
|
||||
myCheckMethodsCheckBox.setModel(new DefaultComboBoxModel<>(visibilities));
|
||||
myCheckParametersCheckBox.setModel(new DefaultComboBoxModel<>(visibilities));
|
||||
|
||||
myCheckParametersCheckBox.setSelected(PARAMETER);
|
||||
myReportUnusedParametersInPublics.setSelected(REPORT_PARAMETER_FOR_PUBLIC_METHODS);
|
||||
myReportUnusedParametersInPublics.setEnabled(PARAMETER);
|
||||
final ListCellRendererWrapper<String> renderer = new ListCellRendererWrapper<String>() {
|
||||
@Override
|
||||
public void customize(JList list, String value, int index, boolean selected, boolean hasFocus) {
|
||||
if (value != null && !"none".equals(value)) {
|
||||
setText(VisibilityUtil.toPresentableText(value));
|
||||
}
|
||||
}
|
||||
};
|
||||
myCheckClassesCheckBox.setRenderer(renderer);
|
||||
myCheckMethodsCheckBox.setRenderer(renderer);
|
||||
myCheckFieldsCheckBox.setRenderer(renderer);
|
||||
myCheckParametersCheckBox.setRenderer(renderer);
|
||||
|
||||
myCheckClassesCheckBox.setSelectedItem(getClassVisibility());
|
||||
myCheckFieldsCheckBox.setSelectedItem(getFieldVisibility());
|
||||
myCheckMethodsCheckBox.setSelectedItem(getMethodVisibility());
|
||||
myCheckParametersCheckBox.setSelectedItem(getParameterVisibility());
|
||||
|
||||
final ActionListener listener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LOCAL_VARIABLE = myCheckLocalVariablesCheckBox.isSelected();
|
||||
CLASS = myCheckClassesCheckBox.isSelected();
|
||||
FIELD = myCheckFieldsCheckBox.isSelected();
|
||||
METHOD = myCheckMethodsCheckBox.isSelected();
|
||||
|
||||
PARAMETER = myCheckParametersCheckBox.isSelected();
|
||||
REPORT_PARAMETER_FOR_PUBLIC_METHODS = PARAMETER && myReportUnusedParametersInPublics.isSelected();
|
||||
myReportUnusedParametersInPublics.setEnabled(PARAMETER);
|
||||
setIgnoreAccessors(!myCheckGettersSettersCheckBox.isSelected());
|
||||
setClassVisibility((String)myCheckClassesCheckBox.getSelectedItem());
|
||||
setFieldVisibility((String)myCheckFieldsCheckBox.getSelectedItem());
|
||||
setMethodVisibility((String)myCheckMethodsCheckBox.getSelectedItem());
|
||||
setParameterVisibility((String)myCheckParametersCheckBox.getSelectedItem());
|
||||
}
|
||||
};
|
||||
myCheckLocalVariablesCheckBox.addActionListener(listener);
|
||||
@@ -72,7 +90,7 @@ public class UnusedSymbolLocalInspection extends UnusedSymbolLocalInspectionBase
|
||||
myCheckMethodsCheckBox.addActionListener(listener);
|
||||
myCheckClassesCheckBox.addActionListener(listener);
|
||||
myCheckParametersCheckBox.addActionListener(listener);
|
||||
myReportUnusedParametersInPublics.addActionListener(listener);
|
||||
myCheckGettersSettersCheckBox.addActionListener(listener);
|
||||
}
|
||||
|
||||
public JComponent getPanel() {
|
||||
|
||||
+3
-3
@@ -222,13 +222,13 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testUnusedParamsOfPublicMethodDisabled() {
|
||||
UnusedSymbolLocalInspectionBase tool = myUnusedDeclarationInspection.getSharedLocalInspectionTool();
|
||||
assertNotNull(tool);
|
||||
boolean oldVal = tool.REPORT_PARAMETER_FOR_PUBLIC_METHODS;
|
||||
String oldVal = tool.getParameterVisibility();
|
||||
try {
|
||||
tool.REPORT_PARAMETER_FOR_PUBLIC_METHODS = false;
|
||||
tool.setParameterVisibility(PsiModifier.PRIVATE);
|
||||
doTest(true, false);
|
||||
}
|
||||
finally {
|
||||
tool.REPORT_PARAMETER_FOR_PUBLIC_METHODS = oldVal;
|
||||
tool.setParameterVisibility(oldVal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.intellij.profile.Profile;
|
||||
import com.intellij.profile.codeInspection.InspectionProfileManager;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.profile.codeInspection.ui.header.InspectionToolsConfigurable;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.testFramework.LightIdeaTestCase;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
@@ -265,7 +266,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
UnusedDeclarationInspectionBase tool = (UnusedDeclarationInspectionBase)toolWrapper.getTool();
|
||||
tool.ADD_NONJAVA_TO_ENTRIES = true;
|
||||
UnusedSymbolLocalInspectionBase inspectionTool = tool.getSharedLocalInspectionTool();
|
||||
inspectionTool.REPORT_PARAMETER_FOR_PUBLIC_METHODS = true;
|
||||
inspectionTool.setParameterVisibility(PsiModifier.PUBLIC);
|
||||
model.commit();
|
||||
String mergedText = "<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"ToConvert\" />\n" +
|
||||
@@ -307,6 +308,46 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
assertElementsEqual(mergedElement, imported);
|
||||
}
|
||||
|
||||
public void testStoredMemberVisibility() throws Exception {
|
||||
InspectionProfileImpl profile = createProfile(new InspectionProfileImpl("foo"));
|
||||
profile.readExternal(JDOMUtil.loadDocument("<profile version=\"1.0\">\n" +
|
||||
" <inspection_tool class=\"unused\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"true\">\n" +
|
||||
" <option name=\"LOCAL_VARIABLE\" value=\"true\" />\n" +
|
||||
" <option name=\"FIELD\" value=\"true\" />\n" +
|
||||
" <option name=\"METHOD\" value=\"true\" />\n" +
|
||||
" <option name=\"CLASS\" value=\"true\" />\n" +
|
||||
" <option name=\"PARAMETER\" value=\"true\" />\n" +
|
||||
" <option name=\"REPORT_PARAMETER_FOR_PUBLIC_METHODS\" value=\"true\" />\n" +
|
||||
" <option name=\"ADD_MAINS_TO_ENTRIES\" value=\"true\" />\n" +
|
||||
" <option name=\"ADD_APPLET_TO_ENTRIES\" value=\"true\" />\n" +
|
||||
" <option name=\"ADD_SERVLET_TO_ENTRIES\" value=\"true\" />\n" +
|
||||
" <option name=\"ADD_NONJAVA_TO_ENTRIES\" value=\"false\" />\n" +
|
||||
" </inspection_tool>\n" +
|
||||
"</profile>").getRootElement());
|
||||
InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel();
|
||||
InspectionToolWrapper toolWrapper = model.getInspectionTool("unused", getProject());
|
||||
UnusedDeclarationInspectionBase tool = (UnusedDeclarationInspectionBase)toolWrapper.getTool();
|
||||
UnusedSymbolLocalInspectionBase inspectionTool = tool.getSharedLocalInspectionTool();
|
||||
inspectionTool.setClassVisibility("none");
|
||||
model.commit();
|
||||
String mergedText = "<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"ToConvert\" />\n" +
|
||||
" <inspection_tool class=\"unused\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"true\" inner_class=\"none\">\n" +
|
||||
" <option name=\"LOCAL_VARIABLE\" value=\"true\" />\n" +
|
||||
" <option name=\"FIELD\" value=\"true\" />\n" +
|
||||
" <option name=\"METHOD\" value=\"true\" />\n" +
|
||||
" <option name=\"CLASS\" value=\"false\" />\n" +
|
||||
" <option name=\"PARAMETER\" value=\"true\" />\n" +
|
||||
" <option name=\"REPORT_PARAMETER_FOR_PUBLIC_METHODS\" value=\"true\" />\n" +
|
||||
" <option name=\"ADD_MAINS_TO_ENTRIES\" value=\"true\" />\n" +
|
||||
" <option name=\"ADD_APPLET_TO_ENTRIES\" value=\"true\" />\n" +
|
||||
" <option name=\"ADD_SERVLET_TO_ENTRIES\" value=\"true\" />\n" +
|
||||
" <option name=\"ADD_NONJAVA_TO_ENTRIES\" value=\"false\" />\n" +
|
||||
" </inspection_tool>\n" +
|
||||
"</profile>";
|
||||
assertEquals(mergedText, serialize(profile));
|
||||
}
|
||||
|
||||
public void testDisabledUnusedDeclarationWithoutChanges() throws Exception {
|
||||
checkMergedNoChanges("<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"" + PROFILE + "\" />\n" +
|
||||
|
||||
@@ -311,10 +311,11 @@ inspection.javadoc.html.not.required.dialog.title=Edit Additional Not Required H
|
||||
inspection.required.attributes.display.name=Missing required attribute
|
||||
|
||||
inspection.unused.symbol.check.localvars=Check &Local Variables
|
||||
inspection.unused.symbol.check.fields=Check &Fields
|
||||
inspection.unused.symbol.check.methods=Check &Methods
|
||||
inspection.unused.symbol.check.classes=Check &Classes
|
||||
inspection.unused.symbol.check.parameters=Check &Parameters
|
||||
inspection.unused.symbol.check.fields=Check &Fields:
|
||||
inspection.unused.symbol.check.methods=Check &Methods:
|
||||
inspection.unused.symbol.check.accessors=Check &Getters/Setters:
|
||||
inspection.unused.symbol.check.classes=Check &Classes:
|
||||
inspection.unused.symbol.check.parameters=Check &Parameters in Methods:
|
||||
|
||||
inspection.results.for.profile.toolwindow.title=''{0}'' Profile on {1}
|
||||
inspection.results.for.inspection.toolwindow.title=''{0}'' Inspection on {1}
|
||||
|
||||
Reference in New Issue
Block a user