diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties
index 4d8a80d7e687..9de82e4a9d56 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties
+++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties
@@ -1283,6 +1283,7 @@ non.comment.source.statements.problem.descriptor=#ref is too long (
parameters.per.method.problem.descriptor=#ref() has too many parameters (num parameters = {0}) #loc
parameters.per.constructor.problem.descriptor=#ref() has too many parameters (num parameters = {0}) #loc
parameter.limit.option=Parameter limit:
+constructor.visibility.option=Ignore constructors with visibility
three.negations.per.method.ignore.option=Ignore negations in 'equals()' methods
three.negations.per.method.ignore.assert.option=Ignore negations in 'assert' statements
three.negations.per.method.problem.descriptor=#ref contains {0} negations #loc
@@ -1989,3 +1990,7 @@ public.constructor.problem.descriptor=Public constructor #ref()
public.constructor.quickfix=Replace constructor with factory method
junit3.style.test.method.in.junit4.class.display.name=Old style JUnit test method in JUnit 4 class
junit3.style.test.method.in.junit4.class.problem.descriptor=Old style JUnit test method #ref in JUnit 4 class
+none=none
+private=private
+package.local.private=package local & private
+protected.package.local.private=protected, package local & private
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/ParametersPerConstructorInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/ParametersPerConstructorInspection.java
index 6e8f12373c39..409c8e007eaf 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/ParametersPerConstructorInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/ParametersPerConstructorInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,44 +16,133 @@
package com.siyeh.ig.methodmetrics;
import com.intellij.psi.PsiMethod;
+import com.intellij.psi.PsiModifier;
import com.intellij.psi.PsiParameterList;
+import com.intellij.ui.ListCellRendererWrapper;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspectionVisitor;
import org.jetbrains.annotations.NotNull;
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
public class ParametersPerConstructorInspection extends MethodMetricInspection {
+ private enum Scope {
+ NONE {
+ @Override
+ String getText() {
+ return InspectionGadgetsBundle.message("none");
+ }
+ },
+ PRIVATE {
+ @Override
+ String getText() {
+ return InspectionGadgetsBundle.message("private");
+ }
+ },
+ PACKAGE_LOCAL {
+ @Override
+ String getText() {
+ return InspectionGadgetsBundle.message("package.local.private");
+ }
+ },
+ PROTECTED {
+ @Override
+ String getText() {
+ return InspectionGadgetsBundle.message("protected.package.local.private");
+ }
+ };
+
+ abstract String getText();
+ }
+
+ @SuppressWarnings("PublicField") public Scope ignoreScope = Scope.NONE;
+
+ @Override
@NotNull
public String getID() {
return "ConstructorWithTooManyParameters";
}
+ @Override
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "parameters.per.constructor.display.name");
+ return InspectionGadgetsBundle.message("parameters.per.constructor.display.name");
}
+ @Override
@NotNull
public String buildErrorString(Object... infos) {
final Integer parameterCount = (Integer)infos[0];
- return InspectionGadgetsBundle.message(
- "parameters.per.constructor.problem.descriptor", parameterCount);
+ return InspectionGadgetsBundle.message("parameters.per.constructor.problem.descriptor", parameterCount);
}
+ @Override
protected int getDefaultLimit() {
return 5;
}
+ @Override
protected String getConfigurationLabel() {
return InspectionGadgetsBundle.message("parameter.limit.option");
}
- public BaseInspectionVisitor buildVisitor() {
- return new ParametersPerMethodVisitor();
+ @Override
+ public JComponent createOptionsPanel() {
+ final JPanel panel = new JPanel();
+ final JLabel textFieldLabel = new JLabel(getConfigurationLabel());
+ final JFormattedTextField valueField = prepareNumberEditor("m_limit");
+ final JLabel comboBoxLabel = new JLabel(InspectionGadgetsBundle.message("constructor.visibility.option"));
+ final JComboBox comboBox = new JComboBox();
+ comboBox.addItem(Scope.NONE);
+ comboBox.addItem(Scope.PRIVATE);
+ comboBox.addItem(Scope.PACKAGE_LOCAL);
+ comboBox.addItem(Scope.PROTECTED);
+ comboBox.setRenderer(new ListCellRendererWrapper() {
+ @Override
+ public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
+ if (value instanceof Scope) setText(((Scope)value).getText());
+ }
+ });
+ comboBox.setSelectedItem(ignoreScope);
+ comboBox.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ ignoreScope = (Scope)comboBox.getSelectedItem();
+ }
+ });
+ comboBox.setPrototypeDisplayValue(Scope.PROTECTED);
+
+ final GroupLayout layout = new GroupLayout(panel);
+ layout.setAutoCreateGaps(true);
+ panel.setLayout(layout);
+ final GroupLayout.ParallelGroup horizontal = layout.createParallelGroup();
+ horizontal.addGroup(layout.createSequentialGroup()
+ .addComponent(textFieldLabel)
+ .addComponent(valueField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE));
+ horizontal.addGroup(layout.createSequentialGroup()
+ .addComponent(comboBoxLabel).addComponent(comboBox, 100, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE));
+ layout.setHorizontalGroup(horizontal);
+ final GroupLayout.SequentialGroup vertical = layout.createSequentialGroup();
+ vertical.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
+ .addComponent(textFieldLabel)
+ .addComponent(valueField));
+ vertical.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
+ .addComponent(comboBoxLabel)
+ .addComponent(comboBox));
+ layout.setVerticalGroup(vertical);
+
+ return panel;
}
- private class ParametersPerMethodVisitor extends BaseInspectionVisitor {
+ @Override
+ public BaseInspectionVisitor buildVisitor() {
+ return new ParametersPerConstructorVisitor();
+ }
+
+ private class ParametersPerConstructorVisitor extends BaseInspectionVisitor {
@Override
public void visitMethod(@NotNull PsiMethod method) {
@@ -64,6 +153,13 @@ public class ParametersPerConstructorInspection extends MethodMetricInspection {
if (!method.isConstructor()) {
return;
}
+ if (ignoreScope != Scope.NONE) {
+ switch (ignoreScope.ordinal()) {
+ case 3: if (method.hasModifierProperty(PsiModifier.PROTECTED)) return;
+ case 2: if (method.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) return;
+ case 1: if (method.hasModifierProperty(PsiModifier.PRIVATE)) return;
+ }
+ }
final PsiParameterList parameterList = method.getParameterList();
final int parametersCount = parameterList.getParametersCount();
if (parametersCount <= getLimit()) {
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerConstructor.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerConstructor.html
index 4392ee862fc8..f9d0928af51f 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerConstructor.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerConstructor.html
@@ -6,6 +6,9 @@ with too many parameters can be a good sign that refactoring is necessary.
Use the field provided below to specify the maximum acceptable number of parameters a constructor might have.
+Use the combobox below to specify if the inspection should ignore private, package local & private or protected, package local and +private constructors +
Powered by InspectionGadgets