mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simpler UI code
This commit is contained in:
@@ -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 <code>#ref</code> is immediately rethrown #loc
|
||||
delete.catch.section.quickfix=Delete 'catch' section
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+14
-48
@@ -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;
|
||||
|
||||
+3
-1
@@ -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");
|
||||
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.siyeh.ig.methodmetrics.MultipleReturnPointsPerMethodInspection.Form">
|
||||
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="4" vgap="4">
|
||||
<margin top="4" left="4" bottom="4" right="4"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="f6e5e" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" 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="4b947"/>
|
||||
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="return.point.limit.option"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="676eb">
|
||||
<constraints>
|
||||
<grid row="3" 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="4b947" class="javax.swing.JFormattedTextField" binding="valueField" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="30" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<hspacer id="d9af9">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="1baf7" class="javax.swing.JCheckBox" binding="ignoreGuardClausesCheckBox" custom-create="true" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="ignore.guard.clauses"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="caa1" class="javax.swing.JCheckBox" binding="ignoreForEqualsMethodsCheckBox" custom-create="true" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="ignore.for.equals.methods"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
+52
-33
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<? extends BaseInspection> 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<? extends BaseInspection> 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;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
Reference in New Issue
Block a user