(no message)

This commit is contained in:
Dave Griffith
2005-02-03 23:45:14 +03:00
parent 0c5ef4894a
commit 9bed01214a
6 changed files with 259 additions and 1 deletions
+3 -1
View File
@@ -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
@@ -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);
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.siyeh.ig.naming.QuestionableNameInspection.Form">
<grid id="9993d" binding="contentPanel" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="92" y="33" width="211" height="192"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="14807">
<constraints>
<xy x="0" y="0" width="211" height="163"/>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="7" hsize-policy="7" anchor="0" fill="3"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="b0978" class="javax.swing.JTable" binding="table">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<component id="f6174" class="javax.swing.JButton" binding="deleteButton">
<constraints>
<xy x="105" y="168" width="106" height="24"/>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1"/>
</constraints>
<properties>
<text value="Delete"/>
</properties>
</component>
<component id="52926" class="javax.swing.JButton" binding="addButton">
<constraints>
<xy x="0" y="168" width="95" height="24"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1"/>
</constraints>
<properties>
<text value="Add"/>
</properties>
</component>
</children>
</grid>
</form>
@@ -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);
}
}
}
@@ -0,0 +1,11 @@
<html>
<body><table> <tr> <td valign = "top" height="150">
<font face="verdana" size="-1">
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.
<p>
Use the list below to specify names which should be reported
</p>
</font></td> </tr> <tr> <td height="20"> <font face="verdana" size="-2">Powered by InspectionGadgets </font> </td> </tr> </table> </body>
</html>
@@ -6,5 +6,10 @@ public class CloneableDeclaresCloneInspection implements Cloneable
{
}
public void barangus()
{
}
}