mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-53385 ("Non-boolean method name must not start with question" doesn't know Boolean) and added option to ignore Boolean methods again
This commit is contained in:
@@ -1763,3 +1763,4 @@ remove.leading.zero.to.make.decimal.quickfix=Remove leading zero to make decimal
|
||||
convert.octal.literal.to.decimal.literal.quickfix=Convert octal literal to decimal literal
|
||||
ignore.single.field.static.imports.option=Ignore single &field static imports
|
||||
ignore.single.method.static.imports.option=Ignore single &method static imports
|
||||
ignore.methods.with.boolean.return.type.option=ignore methods with Boolean return type
|
||||
|
||||
+66
-32
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2010 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.
|
||||
@@ -25,15 +25,17 @@ import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
import com.siyeh.ig.psiutils.LibraryUtil;
|
||||
import com.siyeh.ig.ui.AddAction;
|
||||
import com.siyeh.ig.ui.IGTable;
|
||||
import com.siyeh.ig.ui.ListWrappingTableModel;
|
||||
import com.siyeh.ig.ui.RemoveAction;
|
||||
import com.siyeh.ig.ui.*;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -45,47 +47,99 @@ public class NonBooleanMethodNameMayNotStartWithQuestionInspection
|
||||
"is,can,has,should,could,will,shall,check,contains,equals," +
|
||||
"startsWith,endsWith";
|
||||
|
||||
@SuppressWarnings({"PublicField"})
|
||||
public boolean ignoreBooleanMethods = true;
|
||||
|
||||
List<String> questionList = new ArrayList(32);
|
||||
|
||||
public NonBooleanMethodNameMayNotStartWithQuestionInspection(){
|
||||
parseString(questionString, questionList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName(){
|
||||
return InspectionGadgetsBundle.message(
|
||||
"non.boolean.method.name.must.not.start.with.question.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos){
|
||||
return InspectionGadgetsBundle.message(
|
||||
"non.boolean.method.name.must.not.start.with.question.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSettings(Element element) throws InvalidDataException{
|
||||
super.readSettings(element);
|
||||
parseString(questionString, questionList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSettings(Element element) throws WriteExternalException{
|
||||
questionString = formatString(questionList);
|
||||
super.writeSettings(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel(){
|
||||
final Form form = new Form();
|
||||
return form.getContentPanel();
|
||||
final JPanel panel = new JPanel(new GridBagLayout());
|
||||
final IGTable table =
|
||||
new IGTable(new ListWrappingTableModel(questionList,
|
||||
InspectionGadgetsBundle.message(
|
||||
"boolean.method.name.must.start.with.question.table.column.name")));
|
||||
final JScrollPane scrollPane = new JScrollPane(table);
|
||||
|
||||
final GridBagConstraints constraints = new GridBagConstraints();
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 0;
|
||||
constraints.gridheight = 3;
|
||||
constraints.weightx = 1.0;
|
||||
constraints.weighty = 1.0;
|
||||
constraints.fill = GridBagConstraints.BOTH;
|
||||
panel.add(scrollPane, constraints);
|
||||
|
||||
final JButton addButton = new JButton(new AddAction(table));
|
||||
constraints.gridx = 1;
|
||||
constraints.gridheight = 1;
|
||||
constraints.weightx = 0.0;
|
||||
constraints.weighty = 0.0;
|
||||
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
panel.add(addButton, constraints);
|
||||
|
||||
final JButton removeButton = new JButton(new RemoveAction(table));
|
||||
constraints.gridy = 1;
|
||||
panel.add(removeButton, constraints);
|
||||
|
||||
final BlankFiller filler = new BlankFiller();
|
||||
constraints.gridy = 2;
|
||||
constraints.weighty = 1.0;
|
||||
panel.add(filler, constraints);
|
||||
|
||||
final CheckBox checkBox =
|
||||
new CheckBox(InspectionGadgetsBundle.message(
|
||||
"ignore.methods.with.boolean.return.type.option"),
|
||||
this, "ignoreBooleanMethods");
|
||||
constraints.gridy = 3;
|
||||
constraints.gridx = 0;
|
||||
constraints.gridwidth = 2;
|
||||
constraints.weighty = 0.0;
|
||||
panel.add(checkBox, constraints);
|
||||
return panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos){
|
||||
return new RenameFix();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean buildQuickFixesOnlyForOnTheFlyErrors(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor(){
|
||||
return new NonBooleanMethodNameMayNotStartWithQuestionVisitor();
|
||||
}
|
||||
@@ -99,6 +153,10 @@ public class NonBooleanMethodNameMayNotStartWithQuestionInspection
|
||||
if(returnType == null || returnType.equals(PsiType.BOOLEAN)){
|
||||
return;
|
||||
}
|
||||
if(ignoreBooleanMethods && returnType.equalsToText(
|
||||
"java.lang.Boolean")){
|
||||
return;
|
||||
}
|
||||
final String name = method.getName();
|
||||
boolean startsWithQuestionWord = false;
|
||||
for(String question : questionList){
|
||||
@@ -121,28 +179,4 @@ public class NonBooleanMethodNameMayNotStartWithQuestionInspection
|
||||
registerMethodError(method);
|
||||
}
|
||||
}
|
||||
|
||||
private class Form{
|
||||
|
||||
JPanel contentPanel;
|
||||
JButton addButton;
|
||||
JButton removeButton;
|
||||
IGTable table;
|
||||
|
||||
Form(){
|
||||
super();
|
||||
addButton.setAction(new AddAction(table));
|
||||
removeButton.setAction(new RemoveAction(table));
|
||||
}
|
||||
|
||||
private void createUIComponents(){
|
||||
table = new IGTable(new ListWrappingTableModel(questionList,
|
||||
InspectionGadgetsBundle.message(
|
||||
"boolean.method.name.must.start.with.question.table.column.name")));
|
||||
}
|
||||
|
||||
public JComponent getContentPanel(){
|
||||
return contentPanel;
|
||||
}
|
||||
}
|
||||
}
|
||||
-48
@@ -1,48 +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.naming.NonBooleanMethodNameMayNotStartWithQuestionInspection.Form">
|
||||
<grid id="c36c6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="4" vgap="4">
|
||||
<margin top="4" left="4" bottom="4" right="4"/>
|
||||
<constraints>
|
||||
<xy x="94" y="35" width="298" height="158"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<scrollpane id="14807">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="d8a2f" class="com.siyeh.ig.ui.IGTable" binding="table" custom-create="true">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<component id="52926" class="javax.swing.JButton" binding="addButton">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="button.add"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f6174" class="javax.swing.JButton" binding="removeButton">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<margin top="3" left="8" bottom="3" right="8"/>
|
||||
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="button.remove"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="5ac98">
|
||||
<constraints>
|
||||
<grid row="2" 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>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
Reference in New Issue
Block a user