diff --git a/plugins/InspectionGadgets/Leftovers.txt b/plugins/InspectionGadgets/Leftovers.txt index 70964f1a4dec..2fed59b71ca6 100644 --- a/plugins/InspectionGadgets/Leftovers.txt +++ b/plugins/InspectionGadgets/Leftovers.txt @@ -9,7 +9,7 @@ Avoid repeated casting arithmetic operations on volatile types Field has setter but no getter - Name with forbidden component + Class name with forbidden component Paired open/close for Sockets Paired open/close for Channels Paired acquire/release for Locks @@ -19,10 +19,12 @@ Non-Boolean method name cannot begin with Equals methods that do not check parameter type Call to simple getter or setter from within class + Copyright comment Inheritance as type def (change the EmptyClass inspection) changing multiply/divide to shift may change precedence! Fix the "variable accessed in synchronized and unsynchronized contexts" to deal with unsynchronized private methods called only from synchronized contexts SerialVersionUID calculation + Filter resource management inspection for in-memory streams diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java b/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java index bac406893f13..c063373bf036 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java @@ -278,6 +278,7 @@ public class InspectionGadgetsPlugin implements ApplicationComponent, inspectionClasses.add(MethodNameSameAsClassNameInspection.class); inspectionClasses.add(MethodNameSameAsParentNameInspection.class); inspectionClasses.add(StandardVariableNamesInspection.class); + inspectionClasses.add(QuestionableNameInspection.class); inspectionClasses.add(ConfusingMainMethodInspection.class); inspectionClasses.add(UpperCaseFieldNameNotConstantInspection.class); inspectionClasses.add(DollarSignInNameInspection.class); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/naming/QuestionableName.form b/plugins/InspectionGadgets/src/com/siyeh/ig/naming/QuestionableName.form new file mode 100644 index 000000000000..79e3956d664b --- /dev/null +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/naming/QuestionableName.form @@ -0,0 +1,46 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/naming/QuestionableNameInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/naming/QuestionableNameInspection.java new file mode 100644 index 000000000000..d9bdd34abd34 --- /dev/null +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/naming/QuestionableNameInspection.java @@ -0,0 +1,193 @@ +package com.siyeh.ig.naming; + +import com.intellij.codeInspection.InspectionManager; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.WriteExternalException; +import com.intellij.psi.*; +import com.siyeh.ig.*; +import org.jdom.Element; + +import javax.swing.*; +import javax.swing.border.EtchedBorder; +import javax.swing.table.AbstractTableModel; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +public class QuestionableNameInspection extends ClassInspection{ + public String nameCheckString = "foo,bar,baz"; + + private List nameList = new ArrayList(32); + + { + parseNameString(); + } + + public void readSettings(Element element) throws InvalidDataException{ + super.readSettings(element); + parseNameString(); + } + + private void parseNameString(){ + nameList.clear(); + final String[] strings = nameCheckString.split(","); + for(int i = 0; i < strings.length; i++){ + nameList.add(strings[i]); + } + } + + public void writeSettings(Element element) throws WriteExternalException{ + formatNameCheckString(); + super.writeSettings(element); + } + + private void formatNameCheckString(){ + final StringBuffer buffer = new StringBuffer(); + boolean first = true; + for(Iterator iterator = nameList.iterator(); iterator.hasNext();){ + if(first){ + first = false; + } else{ + buffer.append(','); + } + final String exceptionName = (String) iterator.next(); + buffer.append(exceptionName); + } + nameCheckString = buffer.toString(); + } + + public String getDisplayName(){ + return "Questionable name"; + } + + public String getGroupDisplayName(){ + return GroupNames.NAMING_CONVENTIONS_GROUP_NAME; + } + + public JComponent createOptionsPanel(){ + final Form form = new Form(); + return form.getContentPanel(); + } + + public String buildErrorString(PsiElement location){ + return "Questionable name '#ref'. #loc "; + } + + public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, + boolean onTheFly){ + return new QuestionableNameVisitor(this, inspectionManager, onTheFly); + } + + private class QuestionableNameVisitor extends BaseInspectionVisitor{ + private boolean inClass = false; + private QuestionableNameVisitor(BaseInspection inspection, + InspectionManager inspectionManager, + boolean isOnTheFly){ + super(inspection, inspectionManager, isOnTheFly); + } + + public void visitVariable(PsiVariable variable){ + super.visitVariable(variable); + final String name = variable.getName(); + if(nameList.contains(name)){ + registerVariableError(variable); + } + } + + public void visitMethod(PsiMethod method){ + super.visitMethod(method); + final String name = method.getName(); + if(nameList.contains(name)){ + registerMethodError(method); + } + } + + public void visitClass(PsiClass aClass){ + if(inClass){ + return; + } + final String name = aClass.getName(); + if(nameList.contains(name)){ + registerClassError(aClass); + } + final boolean wasInClass = inClass; + inClass = true; + super.visitClass(aClass); + inClass = wasInClass; + } + } + + public class Form{ + private JPanel contentPanel; + private JButton addButton; + private JButton deleteButton; + private JTable table; + + public Form(){ + super(); + table.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); + table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); + table.setRowSelectionAllowed(true); + table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + table.setEnabled(true); + final QuestionableNameTableModel model = + new QuestionableNameTableModel(); + table.setModel(model); + addButton.setEnabled(true); + addButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + nameList.add(""); + model.fireTableStructureChanged(); + } + }); + deleteButton.setEnabled(true); + deleteButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + final int[] selectedRows = table.getSelectedRows(); + Arrays.sort(selectedRows); + for(int i = selectedRows.length - 1; i >= 0; i--){ + nameList.remove(selectedRows[i]); + } + model.fireTableStructureChanged(); + } + }); + } + + public JComponent getContentPanel(){ + return contentPanel; + } + } + + private class QuestionableNameTableModel extends AbstractTableModel{ + public int getRowCount(){ + return nameList.size(); + } + + public int getColumnCount(){ + return 1; + } + + public String getColumnName(int columnIndex){ + return "Name"; + } + + public Class getColumnClass(int columnIndex){ + return String.class; + } + + public boolean isCellEditable(int rowIndex, int columnIndex){ + return true; + } + + public Object getValueAt(int rowIndex, int columnIndex){ + return nameList.get(rowIndex); + } + + public void setValueAt(Object aValue, int rowIndex, int columnIndex){ + nameList.set(rowIndex, aValue); + } + } +} diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/QuestionableName.html b/plugins/InspectionGadgets/src/inspectionDescriptions/QuestionableName.html new file mode 100644 index 000000000000..b39b8394f100 --- /dev/null +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/QuestionableName.html @@ -0,0 +1,11 @@ + +
+ +This inspection reports on any variables, methods, or classes with questionable names. +This inspection is best used to report common metasyntactic variables which may be +used as names by lazy or confused developers. +

+Use the list below to specify names which should be reported +

+
Powered by InspectionGadgets
+ \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/cloneable/CloneableDeclaresCloneInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/cloneable/CloneableDeclaresCloneInspection.java index 85168059efad..97039e4ff687 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/cloneable/CloneableDeclaresCloneInspection.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/cloneable/CloneableDeclaresCloneInspection.java @@ -6,5 +6,10 @@ public class CloneableDeclaresCloneInspection implements Cloneable { } + + public void barangus() + { + + } }