diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties index 12bcd3720d38..4886301a8212 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties @@ -701,7 +701,7 @@ while.loop.spins.on.field.display.name='while' loop spins on field object.equals.null.display.name=Object.equals(null) test.method.is.public.void.no.arg.display.name=Test method with incorrect signature if.statement.with.identical.branches.display.name='if' statement with identical branches -multiple.return.points.per.method.display.name=Method with multiple return points. +multiple.return.points.per.method.display.name=Method with multiple return points break.statement.with.label.display.name='break' statement with label public.constructor.in.non.public.class.display.name='public' constructor in non-public class questionable.name.display.name=Questionable name @@ -1653,8 +1653,8 @@ type.may.be.weakened.quickfix=Weaken type to ''{0}'' type.may.be.weakened.ignore.option=Use &righthand type as weakest type in assignments type.may.be.weakened.collection.method.option=Use ¶meterized type of collection for method call arguments type.may.be.weakened.do.not.weaken.to.object.option=Do not &weaken to java.lang.Object -ignore.guard.clauses=Ignore &guard clauses -ignore.for.equals.methods=Ignore for &equals() methods +ignore.guard.clauses.option=Ignore &guard clauses +ignore.for.equals.methods.option=Ignore for &equals() methods caught.exception.immediately.rethrown.display.name=Caught exception is immediately rethrown caught.exception.immediately.rethrown.problem.descriptor=Caught exception #ref is immediately rethrown #loc delete.catch.section.quickfix=Delete 'catch' section diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/BaseInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/BaseInspection.java index f33294c9b4b1..eb370307073e 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/BaseInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/BaseInspection.java @@ -121,7 +121,7 @@ public abstract class BaseInspection extends BaseJavaLocalInspectionTool { final JFormattedTextField valueField = new JFormattedTextField(formatter); final Field field = getClass().getField(fieldName); valueField.setValue(field.get(this)); - valueField.setColumns(4); + valueField.setColumns(2); UIUtil.fixFormattedField(valueField); final Document document = valueField.getDocument(); document.addDocumentListener(new DocumentAdapter() { @@ -129,7 +129,9 @@ public abstract class BaseInspection extends BaseJavaLocalInspectionTool { public void textChanged(DocumentEvent evt) { try { valueField.commitEdit(); - field.set(BaseInspection.this, ((Number) valueField.getValue()).intValue()); + final Number number = (Number) valueField.getValue(); + field.set(BaseInspection.this, + Integer.valueOf(number.intValue())); } catch (IllegalAccessException e) { LOG.error(e); } catch (ParseException e) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java index c3a77298d78d..62970d1fe437 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java @@ -17,7 +17,7 @@ package com.siyeh.ig.controlflow; import com.intellij.psi.*; import com.intellij.psi.tree.IElementType; -import com.intellij.util.ui.UIUtil; +import com.intellij.util.ui.CheckBox; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; @@ -26,15 +26,13 @@ import com.siyeh.ig.fixes.ExtractMethodFix; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.*; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.text.Document; -import java.awt.*; +import javax.swing.JComponent; +import javax.swing.JFormattedTextField; +import javax.swing.JLabel; +import javax.swing.JPanel; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; import java.text.NumberFormat; -import java.text.ParseException; import java.util.HashSet; import java.util.Set; @@ -75,59 +73,27 @@ public class OverlyComplexBooleanExpressionInspection @Override public JComponent createOptionsPanel() { final JPanel panel = new JPanel(new GridBagLayout()); - final JCheckBox ignoreConjunctionsDisjunctionsCheckBox = - new JCheckBox(InspectionGadgetsBundle.message( + final CheckBox ignoreConjunctionsDisjunctionsCheckBox = + new CheckBox(InspectionGadgetsBundle.message( "overly.complex.boolean.expression.ignore.option"), - m_ignorePureConjunctionsDisjunctions); - ignoreConjunctionsDisjunctionsCheckBox.addChangeListener( - new ChangeListener() { - - public void stateChanged(ChangeEvent e) { - m_ignorePureConjunctionsDisjunctions = - ignoreConjunctionsDisjunctionsCheckBox.isSelected(); - } - } - ); + this, "m_ignorePureConjunctionsDisjunctions"); final NumberFormat formatter = NumberFormat.getIntegerInstance(); formatter.setParseIntegerOnly(true); final JFormattedTextField termLimitTextField = - new JFormattedTextField(formatter); - termLimitTextField.setValue(Integer.valueOf(m_limit)); - termLimitTextField.setColumns(2); - UIUtil.fixFormattedField(termLimitTextField); - final Document document = termLimitTextField.getDocument(); - document.addDocumentListener(new DocumentListener() { - public void changedUpdate(DocumentEvent e) { - textChanged(); - } + prepareNumberEditor("m_limit"); - public void insertUpdate(DocumentEvent e) { - textChanged(); - } - - public void removeUpdate(DocumentEvent e) { - textChanged(); - } - - private void textChanged() { - try { - termLimitTextField.commitEdit(); - final Number number = (Number)termLimitTextField.getValue(); - m_limit = number.intValue(); - } catch (ParseException e) { - // No luck this time - } - } - }); final GridBagConstraints constraints = new GridBagConstraints(); final JLabel label = new JLabel(InspectionGadgetsBundle.message( "overly.complex.boolean.expression.max.terms.option")); + constraints.anchor = GridBagConstraints.BASELINE_LEADING; constraints.fill = GridBagConstraints.HORIZONTAL; panel.add(label, constraints); + constraints.fill = GridBagConstraints.NONE; constraints.gridx = 1; panel.add(termLimitTextField, constraints); + constraints.gridx = 0; constraints.gridy = 1; constraints.gridwidth = 2; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/MethodMetricInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/MethodMetricInspection.java index dce2c66140a7..61a8611761d9 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/MethodMetricInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/MethodMetricInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Dave Griffith + * Copyright 2003-2011 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. @@ -22,6 +22,7 @@ import javax.swing.JComponent; public abstract class MethodMetricInspection extends BaseInspection { + @SuppressWarnings("PublicField") public int m_limit = getDefaultLimit(); //this is public for the DefaultJDOMSerialization thingy protected abstract int getDefaultLimit(); @@ -32,6 +33,7 @@ public abstract class MethodMetricInspection extends BaseInspection { return m_limit; } + @Override public JComponent createOptionsPanel() { return new SingleIntegerFieldOptionsPanel(getConfigurationLabel(), this, "m_limit"); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/MultipleReturnPointsPerMethod.form b/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/MultipleReturnPointsPerMethod.form deleted file mode 100644 index 524f186e1413..000000000000 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/MultipleReturnPointsPerMethod.form +++ /dev/null @@ -1,58 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/MultipleReturnPointsPerMethodInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/MultipleReturnPointsPerMethodInspection.java index 471d05616a3e..f310b8605496 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/MultipleReturnPointsPerMethodInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/MultipleReturnPointsPerMethodInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2011 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. @@ -19,14 +19,19 @@ import com.intellij.psi.PsiCodeBlock; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiStatement; import com.intellij.psi.PsiType; +import com.intellij.util.ui.CheckBox; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.psiutils.ControlFlowUtils; import com.siyeh.ig.psiutils.MethodUtils; -import com.siyeh.ig.ui.ToggleAction; import org.jetbrains.annotations.NotNull; -import javax.swing.*; +import javax.swing.JComponent; +import javax.swing.JFormattedTextField; +import javax.swing.JLabel; +import javax.swing.JPanel; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; public class MultipleReturnPointsPerMethodInspection extends MethodMetricInspection { @@ -37,25 +42,30 @@ public class MultipleReturnPointsPerMethodInspection @SuppressWarnings({"PublicField"}) public boolean ignoreEqualsMethod = false; + @Override @NotNull public String getID() { return "MethodWithMultipleReturnPoints"; } + @Override @NotNull public String getDisplayName() { return InspectionGadgetsBundle.message( "multiple.return.points.per.method.display.name"); } + @Override protected int getDefaultLimit() { return 1; } + @Override protected String getConfigurationLabel() { return InspectionGadgetsBundle.message("return.point.limit.option"); } + @Override @NotNull public String buildErrorString(Object... infos) { final Integer returnPointCount = (Integer)infos[0]; @@ -64,11 +74,48 @@ public class MultipleReturnPointsPerMethodInspection returnPointCount); } + @Override public JComponent createOptionsPanel() { - final Form form = new Form(); - return form.getContentPanel(); + final JPanel panel = new JPanel(new GridBagLayout()); + final JLabel label = new JLabel(InspectionGadgetsBundle.message( + "return.point.limit.option")); + final JFormattedTextField termLimitTextField = + prepareNumberEditor("m_limit"); + final CheckBox ignoreGuardClausesCheckBox = + new CheckBox(InspectionGadgetsBundle.message( + "ignore.guard.clauses.option"), + this, "ignoreGuardClauses"); + final CheckBox ignoreEqualsMethodCheckBox = + new CheckBox(InspectionGadgetsBundle.message( + "ignore.for.equals.methods.option"), + this, "ignoreEqualsMethod"); + + final GridBagConstraints constraints = new GridBagConstraints(); + + constraints.anchor = GridBagConstraints.BASELINE_LEADING; + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.gridx = 0; + constraints.gridy = 0; + panel.add(label, constraints); + + constraints.fill = GridBagConstraints.NONE; + constraints.gridx = 1; + panel.add(termLimitTextField, constraints); + + constraints.gridx = 0; + constraints.gridy = 1; + constraints.gridwidth = 2; + constraints.weightx = 1.0; + panel.add(ignoreGuardClausesCheckBox, constraints); + + constraints.gridy = 2; + constraints.weighty = 1.0; + panel.add(ignoreEqualsMethodCheckBox, constraints); + + return panel; } + @Override public BaseInspectionVisitor buildVisitor() { return new MultipleReturnPointsPerMethodVisitor(); } @@ -125,32 +172,4 @@ public class MultipleReturnPointsPerMethodInspection return PsiType.VOID.equals(returnType); } } - - private class Form { - - private JPanel contentPanel; - private JFormattedTextField valueField; - private JCheckBox ignoreGuardClausesCheckBox; - private JCheckBox ignoreForEqualsMethodsCheckBox; - - private void createUIComponents() { - valueField = prepareNumberEditor("m_limit"); - ignoreGuardClausesCheckBox = new JCheckBox( - new ToggleAction(InspectionGadgetsBundle.message( - "ignore.guard.clauses"), - MultipleReturnPointsPerMethodInspection.this, - "ignoreGuardClauses")); - ignoreGuardClausesCheckBox.setSelected(ignoreGuardClauses); - ignoreForEqualsMethodsCheckBox = new JCheckBox( - new ToggleAction(InspectionGadgetsBundle.message( - "ignore.for.equals.methods"), - MultipleReturnPointsPerMethodInspection.this, - "ignoreEqualsMethod")); - ignoreForEqualsMethodsCheckBox.setSelected(ignoreEqualsMethod); - } - - public JComponent getContentPanel(){ - return contentPanel; - } - } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/ui/ToggleAction.java b/plugins/InspectionGadgets/src/com/siyeh/ig/ui/ToggleAction.java deleted file mode 100644 index aede36c36b71..000000000000 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/ui/ToggleAction.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2007 Bas Leijdekkers - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.siyeh.ig.ui; - -import com.siyeh.ig.BaseInspection; -import org.jetbrains.annotations.NonNls; - -import javax.swing.AbstractAction; -import javax.swing.AbstractButton; -import java.awt.event.ActionEvent; -import java.lang.reflect.Field; - -public class ToggleAction extends AbstractAction { - - private final BaseInspection owner; - private final String propertyName; - - public ToggleAction(String labelText, BaseInspection owner, - @NonNls String propertyName) { - this.owner = owner; - this.propertyName = propertyName; - putValue(NAME, labelText); - //putValue(Action.SELECTED_KEY, getPropertyValue()); - } - - public void actionPerformed(ActionEvent event) { - final AbstractButton button = (AbstractButton)event.getSource(); - final boolean selected = button.isSelected(); - try { - final Class aClass = - owner.getClass(); - final Field field = aClass.getField(propertyName); - field.setBoolean(owner, selected); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } - } - - //private Boolean getPropertyValue() { - // try { - // final Class aClass = owner.getClass(); - // final Field field = aClass.getField(propertyName); - // final Object object = field.get(owner); - // assert object instanceof Boolean; - // return (Boolean)object; - // } catch (Exception e) { - // return Boolean.FALSE; - // } - //} -} \ No newline at end of file