mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
UnusedDeclarationInspection ui
This commit is contained in:
@@ -369,7 +369,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
QuickFixAction.registerQuickFixAction(info, HighlightMethodUtil.getFixRange(field), new CreateConstructorParameterFromFieldFix(field), null);
|
||||
SpecialAnnotationsUtil.createAddToSpecialAnnotationFixes(field, new Processor<String>() {
|
||||
public boolean process(final String annoName) {
|
||||
QuickFixAction.registerQuickFixAction(info, myUnusedSymbolInspection.createQuickFix(annoName, field));
|
||||
QuickFixAction.registerQuickFixAction(info, myUnusedSymbolInspection.createQuickFix(annoName, "fields"));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -377,7 +377,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
}
|
||||
else if (!myRefCountHolder.isReferenced(field) && weAreSureThereAreNoUsages(field)) {
|
||||
return formatUnusedSymbolHighlightInfo("field.is.not.used", field);
|
||||
return formatUnusedSymbolHighlightInfo("field.is.not.used", field, "fields");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -471,14 +471,12 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
PsiIdentifier identifier = method.getNameIdentifier();
|
||||
final HighlightInfo highlightInfo = createUnusedSymbolInfo(identifier, message);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new SafeDeleteFix(method), myUnusedSymbolKey);
|
||||
if (PropertyUtil.isSimplePropertySetter(method)) {
|
||||
SpecialAnnotationsUtil.createAddToSpecialAnnotationFixes(method, new Processor<String>() {
|
||||
public boolean process(final String annoName) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, myUnusedSymbolInspection.createQuickFix(annoName, method));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
SpecialAnnotationsUtil.createAddToSpecialAnnotationFixes(method, new Processor<String>() {
|
||||
public boolean process(final String annoName) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, myUnusedSymbolInspection.createQuickFix(annoName, "methods"));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return highlightInfo;
|
||||
}
|
||||
|
||||
@@ -529,19 +527,20 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
@Nullable
|
||||
private HighlightInfo processClass(PsiClass aClass) {
|
||||
if (!isClassUnused(aClass)) return null;
|
||||
String element = "classes";
|
||||
if (aClass.getContainingClass() != null && aClass.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
String pattern = aClass.isInterface()
|
||||
? "private.inner.interface.is.not.used"
|
||||
: "private.inner.class.is.not.used";
|
||||
return formatUnusedSymbolHighlightInfo(pattern, aClass);
|
||||
return formatUnusedSymbolHighlightInfo(pattern, aClass, element);
|
||||
}
|
||||
if (aClass.getParent() instanceof PsiDeclarationStatement) { // local class
|
||||
return formatUnusedSymbolHighlightInfo("local.class.is.not.used", aClass);
|
||||
return formatUnusedSymbolHighlightInfo("local.class.is.not.used", aClass, element);
|
||||
}
|
||||
if (aClass instanceof PsiTypeParameter) {
|
||||
return formatUnusedSymbolHighlightInfo("type.parameter.is.not.used", aClass);
|
||||
return formatUnusedSymbolHighlightInfo("type.parameter.is.not.used", aClass, element);
|
||||
}
|
||||
return formatUnusedSymbolHighlightInfo("class.is.not.used", aClass);
|
||||
return formatUnusedSymbolHighlightInfo("class.is.not.used", aClass, element);
|
||||
}
|
||||
|
||||
private final Map<PsiClass, Boolean> unusedClassCache = new THashMap<PsiClass, Boolean>();
|
||||
@@ -564,12 +563,18 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
|
||||
private HighlightInfo formatUnusedSymbolHighlightInfo(@PropertyKey(resourceBundle = JavaErrorMessages.BUNDLE) String pattern,
|
||||
PsiNameIdentifierOwner aClass) {
|
||||
PsiNameIdentifierOwner aClass, final String element) {
|
||||
String symbolName = aClass.getName();
|
||||
String message = JavaErrorMessages.message(pattern, symbolName);
|
||||
PsiElement identifier = aClass.getNameIdentifier();
|
||||
HighlightInfo highlightInfo = createUnusedSymbolInfo(identifier, message);
|
||||
final HighlightInfo highlightInfo = createUnusedSymbolInfo(identifier, message);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new SafeDeleteFix(aClass), myUnusedSymbolKey);
|
||||
SpecialAnnotationsUtil.createAddToSpecialAnnotationFixes((PsiModifierListOwner)aClass, new Processor<String>() {
|
||||
public boolean process(final String annoName) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, myUnusedSymbolInspection.createQuickFix(annoName, element));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return highlightInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +1,28 @@
|
||||
<?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="8" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="618" height="400"/>
|
||||
<xy x="20" y="20" width="394" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="b6cc3" class="javax.swing.JCheckBox" binding="myCheckLocalVariablesCheckBox" 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"/>
|
||||
<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">
|
||||
<preferred-size width="172" height="22"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.localvars"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="36ace">
|
||||
<constraints>
|
||||
<grid row="7" 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>
|
||||
<component id="bcd0d" class="javax.swing.JCheckBox" binding="myCheckClassesCheckBox" 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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.classes"/>
|
||||
</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="3" 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="6664b" class="javax.swing.JCheckBox" binding="myCheckParametersCheckBox" 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"/>
|
||||
<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>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/InspectionsBundle" key="inspection.unused.symbol.check.parameters"/>
|
||||
@@ -47,7 +30,9 @@
|
||||
</component>
|
||||
<component id="c49dc" class="javax.swing.JCheckBox" binding="myCheckMethodsCheckBox" default-binding="true">
|
||||
<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"/>
|
||||
<grid row="1" 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"/>
|
||||
@@ -55,7 +40,7 @@
|
||||
</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"/>
|
||||
<grid row="3" column="0" row-span="1" col-span="2" 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"/>
|
||||
@@ -63,12 +48,28 @@
|
||||
</component>
|
||||
<grid id="a47a5" binding="myAnnos" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="b2b9f" class="javax.swing.JCheckBox" binding="myCheckFieldsCheckBox" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" 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="1" column="1" 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>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
+14
-8
@@ -11,16 +11,15 @@ import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.BaseJavaLocalInspectionTool;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.deadCode.UnusedCodeExtension;
|
||||
import com.intellij.codeInspection.ex.UnfairLocalInspectionTool;
|
||||
import com.intellij.codeInspection.util.SpecialAnnotationsUtil;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.util.JDOMExternalizableStringList;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.psi.util.PropertyUtil;
|
||||
import org.intellij.lang.annotations.Pattern;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -74,6 +73,7 @@ public class UnusedSymbolLocalInspection extends BaseJavaLocalInspectionTool imp
|
||||
return SHORT_NAME;
|
||||
}
|
||||
|
||||
@Pattern("[a-zA-Z_0-9.]+")
|
||||
@NotNull
|
||||
@NonNls
|
||||
public String getID() {
|
||||
@@ -100,20 +100,26 @@ public class UnusedSymbolLocalInspection extends BaseJavaLocalInspectionTool imp
|
||||
private JPanel myPanel;
|
||||
|
||||
public OptionsPanel() {
|
||||
|
||||
myCheckLocalVariablesCheckBox.setSelected(LOCAL_VARIABLE);
|
||||
myCheckClassesCheckBox.setSelected(CLASS);
|
||||
myCheckFieldsCheckBox.setSelected(FIELD);
|
||||
myCheckMethodsCheckBox.setSelected(METHOD);
|
||||
|
||||
myCheckParametersCheckBox.setSelected(PARAMETER);
|
||||
myReportUnusedParametersInPublics.setSelected(REPORT_PARAMETER_FOR_PUBLIC_METHODS);
|
||||
myReportUnusedParametersInPublics.setEnabled(PARAMETER);
|
||||
|
||||
final ActionListener listener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LOCAL_VARIABLE = myCheckLocalVariablesCheckBox.isSelected();
|
||||
CLASS = myCheckClassesCheckBox.isSelected();
|
||||
FIELD = myCheckFieldsCheckBox.isSelected();
|
||||
PARAMETER = myCheckParametersCheckBox.isSelected();
|
||||
METHOD = myCheckMethodsCheckBox.isSelected();
|
||||
REPORT_PARAMETER_FOR_PUBLIC_METHODS = myReportUnusedParametersInPublics.isSelected();
|
||||
|
||||
PARAMETER = myCheckParametersCheckBox.isSelected();
|
||||
REPORT_PARAMETER_FOR_PUBLIC_METHODS = PARAMETER && myReportUnusedParametersInPublics.isSelected();
|
||||
myReportUnusedParametersInPublics.setEnabled(PARAMETER);
|
||||
}
|
||||
};
|
||||
myCheckLocalVariablesCheckBox.addActionListener(listener);
|
||||
@@ -123,7 +129,7 @@ public class UnusedSymbolLocalInspection extends BaseJavaLocalInspectionTool imp
|
||||
myCheckParametersCheckBox.addActionListener(listener);
|
||||
myReportUnusedParametersInPublics.addActionListener(listener);
|
||||
|
||||
String title = InspectionsBundle.message("dependency.injection.annotations.list");
|
||||
String title = "Do not check if annotated by";
|
||||
final JPanel listPanel = SpecialAnnotationsUtil.createSpecialAnnotationsListControl(INJECTION_ANNOS, title);
|
||||
|
||||
myAnnos.add(listPanel, BorderLayout.CENTER);
|
||||
@@ -139,11 +145,11 @@ public class UnusedSymbolLocalInspection extends BaseJavaLocalInspectionTool imp
|
||||
return new OptionsPanel().getPanel();
|
||||
}
|
||||
|
||||
public IntentionAction createQuickFix(final String qualifiedName, final PsiElement context) {
|
||||
public IntentionAction createQuickFix(final String qualifiedName, String element) {
|
||||
return SpecialAnnotationsUtil.createAddToSpecialAnnotationsListIntentionAction(
|
||||
QuickFixBundle.message("fix.unused.symbol.injection.text", qualifiedName),
|
||||
QuickFixBundle.message("fix.unused.symbol.injection.text", element, qualifiedName),
|
||||
QuickFixBundle.message("fix.unused.symbol.injection.family"),
|
||||
INJECTION_ANNOS, qualifiedName, context);
|
||||
INJECTION_ANNOS, qualifiedName);
|
||||
}
|
||||
|
||||
private static List<String> getRegisteredAnnotations() {
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.ActionPlaces;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.actionSystem.ActionToolbar;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
@@ -24,6 +25,7 @@ import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.ui.ReorderableListController;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.ui.SeparatorFactory;
|
||||
import com.intellij.ui.SortedListModel;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.Processor;
|
||||
@@ -83,24 +85,34 @@ public class SpecialAnnotationsUtil {
|
||||
listChanged();
|
||||
}
|
||||
});
|
||||
|
||||
final JScrollPane listScrollPane = ScrollPaneFactory.createScrollPane(injectionList);
|
||||
listScrollPane.setBorder(BorderFactory.createEtchedBorder());
|
||||
// listScrollPane.setBorder(BorderFactory.createEtchedBorder());
|
||||
listScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||
listScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
final FontMetrics fontMetrics = injectionList.getFontMetrics(injectionList.getFont());
|
||||
listScrollPane.setPreferredSize(new Dimension(0, fontMetrics.getHeight() * 5));
|
||||
listScrollPane.setMinimumSize(new Dimension(0, fontMetrics.getHeight() * 3));
|
||||
//int height = injectionList.getCellRenderer().getListCellRendererComponent(injectionList, "foo", 0, false, false).getSize().height;
|
||||
//injectionList.setFixedCellHeight(height);
|
||||
//injectionList.setPreferredSize(new Dimension(0, height * 3));
|
||||
//injectionList.setMinimumSize(new Dimension(0, height * 3));
|
||||
// injectionList.setVisibleRowCount(3);
|
||||
|
||||
final JPanel listPanel = new JPanel(new BorderLayout());
|
||||
listPanel.setBorder(BorderFactory.createTitledBorder(borderTitle));
|
||||
|
||||
listPanel.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.PROJECT_VIEW_TOOLBAR, actionGroup, true).getComponent(), BorderLayout.NORTH);
|
||||
listPanel.add(listScrollPane, BorderLayout.SOUTH);
|
||||
return listPanel;
|
||||
ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actionGroup, true);
|
||||
listPanel.add(actionToolbar.getComponent(), BorderLayout.NORTH);
|
||||
listPanel.add(listScrollPane, BorderLayout.CENTER);
|
||||
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.add(SeparatorFactory.createSeparator(borderTitle, null), BorderLayout.NORTH);
|
||||
panel.add(listPanel, BorderLayout.CENTER);
|
||||
return panel;
|
||||
}
|
||||
|
||||
public static IntentionAction createAddToSpecialAnnotationsListIntentionAction(final String text, final String family, final List<String> targetList,
|
||||
final String qualifiedName,
|
||||
final PsiElement context) {
|
||||
final String qualifiedName) {
|
||||
return new IntentionAction() {
|
||||
@NotNull
|
||||
public String getText() {
|
||||
@@ -117,7 +129,7 @@ public class SpecialAnnotationsUtil {
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
doQuickFixInternal(project, targetList, qualifiedName, context);
|
||||
doQuickFixInternal(project, targetList, qualifiedName);
|
||||
}
|
||||
|
||||
public boolean startInWriteAction() {
|
||||
@@ -141,12 +153,12 @@ public class SpecialAnnotationsUtil {
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
doQuickFixInternal(project, targetList, qualifiedName, context);
|
||||
doQuickFixInternal(project, targetList, qualifiedName);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static void doQuickFixInternal(final Project project, final List<String> targetList, final String qualifiedName, final PsiElement context) {
|
||||
private static void doQuickFixInternal(final Project project, final List<String> targetList, final String qualifiedName) {
|
||||
targetList.add(qualifiedName);
|
||||
Collections.sort(targetList);
|
||||
final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
|
||||
|
||||
Reference in New Issue
Block a user