diff --git a/plugins/InspectionGadgets/InspectionGadgetsSVN.iml b/plugins/InspectionGadgets/InspectionGadgetsSVN.iml index 7feca1a3cc69..28a017346da5 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsSVN.iml +++ b/plugins/InspectionGadgets/InspectionGadgetsSVN.iml @@ -10,7 +10,7 @@ - + diff --git a/plugins/InspectionGadgets/InspectionGadgetsSVN.ipr b/plugins/InspectionGadgets/InspectionGadgetsSVN.ipr index e70570c59167..3095fdd86b29 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsSVN.ipr +++ b/plugins/InspectionGadgets/InspectionGadgetsSVN.ipr @@ -21,6 +21,9 @@ + + + diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.form b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.form index 620f2db837d7..0689789e1791 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.form +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.form @@ -1,44 +1,64 @@ - + - + - + + - - + + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - - - - - - - - - + diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.java index 871aa5145207..d30ecf244e09 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.java @@ -9,9 +9,12 @@ import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.ExpressionInspection; import com.siyeh.ig.GroupNames; import com.siyeh.ig.psiutils.ClassUtils; +import com.siyeh.ig.psiutils.LibraryUtil; import org.jdom.Element; import javax.swing.*; +import javax.swing.event.ChangeListener; +import javax.swing.event.ChangeEvent; import javax.swing.border.EtchedBorder; import javax.swing.table.AbstractTableModel; import java.awt.event.ActionEvent; @@ -23,7 +26,9 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class IgnoreResultOfCallInspection extends ExpressionInspection { +public class IgnoreResultOfCallInspection extends ExpressionInspection{ + public boolean m_reportAllNonLibraryCalls = false; + public String callCheckString = "java.io.InputStream,read," + "java.io.InputStream,skip," + "java.lang.StringBuffer,toString," + @@ -39,33 +44,34 @@ public class IgnoreResultOfCallInspection extends ExpressionInspection { parseCallCheckString(); } - public void readSettings(Element element) throws InvalidDataException { + public void readSettings(Element element) throws InvalidDataException{ super.readSettings(element); parseCallCheckString(); } - private void parseCallCheckString() { + private void parseCallCheckString(){ callsToCheck.clear(); final String[] strings = callCheckString.split(","); - for (int i = 0; i < strings.length; i += 2) { + for(int i = 0; i < strings.length; i += 2){ final String className = strings[i]; final String methodName = strings[i + 1]; - callsToCheck.add(new ReturnCheckSpecification(className, methodName)); + callsToCheck.add( + new ReturnCheckSpecification(className, methodName)); } } - public void writeSettings(Element element) throws WriteExternalException { + public void writeSettings(Element element) throws WriteExternalException{ formatCallCheckString(); super.writeSettings(element); } - private void formatCallCheckString() { + private void formatCallCheckString(){ final StringBuffer buffer = new StringBuffer(); boolean first = true; - for (Iterator iterator = callsToCheck.iterator(); iterator.hasNext();) { - if (first) { + for(Iterator iterator = callsToCheck.iterator(); iterator.hasNext();){ + if(first){ first = false; - } else { + } else{ buffer.append(','); } final ReturnCheckSpecification returnCheckSpecification = @@ -79,20 +85,20 @@ public class IgnoreResultOfCallInspection extends ExpressionInspection { callCheckString = buffer.toString(); } - public String getDisplayName() { + public String getDisplayName(){ return "Result of method call ignored"; } - public String getGroupDisplayName() { + public String getGroupDisplayName(){ return GroupNames.BUGS_GROUP_NAME; } - public JComponent createOptionsPanel() { + public JComponent createOptionsPanel(){ final Form form = new Form(); return form.getContentPanel(); } - public String buildErrorString(PsiElement location) { + public String buildErrorString(PsiElement location){ final PsiElement parent = location.getParent(); final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) parent.getParent(); final PsiMethod method = methodCallExpression.resolveMethod(); @@ -101,48 +107,57 @@ public class IgnoreResultOfCallInspection extends ExpressionInspection { return "result of " + className + ".#ref() is ignored. #loc "; } - public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) { + public BaseInspectionVisitor createVisitor( + InspectionManager inspectionManager, boolean onTheFly){ return new IgnoreResultOfCallVisitor(this, inspectionManager, onTheFly); } - private class IgnoreResultOfCallVisitor extends BaseInspectionVisitor { - private IgnoreResultOfCallVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) { + private class IgnoreResultOfCallVisitor extends BaseInspectionVisitor{ + private IgnoreResultOfCallVisitor(BaseInspection inspection, + InspectionManager inspectionManager, + boolean isOnTheFly){ super(inspection, inspectionManager, isOnTheFly); } - public void visitExpressionStatement(PsiExpressionStatement statement) { + public void visitExpressionStatement(PsiExpressionStatement statement){ super.visitExpressionStatement(statement); - if (!(statement.getExpression() instanceof PsiMethodCallExpression)) { + if(!(statement.getExpression() instanceof PsiMethodCallExpression)){ return; } final PsiMethodCallExpression call = (PsiMethodCallExpression) statement.getExpression(); - final PsiReferenceExpression methodExpression = call.getMethodExpression(); - final String methodName = methodExpression.getReferenceName(); - if (methodName == null) { + final PsiMethod method = call.resolveMethod(); + if(method == null){ return; } - - final PsiMethod method = call.resolveMethod(); - if (method == null) { + if(method.isConstructor()){ + return; + } + final PsiType retType = method.getReturnType(); + if(PsiType.VOID.equals(retType)){ return; } final PsiClass aClass = method.getContainingClass(); - if (aClass == null) { + if(aClass == null){ return; } - - final PsiType retType = method.getReturnType(); - if (retType == PsiType.VOID) { + if(m_reportAllNonLibraryCalls && + !LibraryUtil.classIsInLibrary(aClass)){ + registerMethodCallError(call); return; } - - for (Iterator iterator = callsToCheck.iterator(); iterator.hasNext();) { + final PsiReferenceExpression methodExpression = call.getMethodExpression(); + final String methodName = methodExpression.getReferenceName(); + if(methodName == null){ + return; + } + for(Iterator iterator = callsToCheck.iterator(); + iterator.hasNext();){ final ReturnCheckSpecification spec = (ReturnCheckSpecification) iterator.next(); final Pattern methodNamePattern = spec.getMethodNamePattern(); - if (methodNamePattern != null && - methodNamesMatch(methodName, methodNamePattern)) { + if(methodNamePattern != null && + methodNamesMatch(methodName, methodNamePattern)){ final String classNameToCompare = spec.getClassName(); - if (ClassUtils.isSubclass(aClass, classNameToCompare)) { + if(ClassUtils.isSubclass(aClass, classNameToCompare)){ registerMethodCallError(call); return; } @@ -151,93 +166,107 @@ public class IgnoreResultOfCallInspection extends ExpressionInspection { } - private boolean methodNamesMatch(String methodName, Pattern methodNamePattern) { + private boolean methodNamesMatch(String methodName, + Pattern methodNamePattern){ final Matcher matcher = methodNamePattern.matcher(methodName); return matcher.matches(); } } - public class Form { + public class Form{ private JPanel contentPanel; private JButton addButton; private JButton deleteButton; private JTable table; + private JCheckBox nonLibraryCheckbox; - public Form() { + 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.setSelectionMode( + ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setEnabled(true); final ReturnCheckSpecificationTableModel model = new ReturnCheckSpecificationTableModel(); table.setModel(model); addButton.setEnabled(true); - addButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { + addButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ callsToCheck.add(new ReturnCheckSpecification()); model.fireTableStructureChanged(); } }); deleteButton.setEnabled(true); - deleteButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { + 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--) { + for(int i = selectedRows.length - 1; i >= 0; i--){ callsToCheck.remove(selectedRows[i]); } model.fireTableStructureChanged(); } }); + nonLibraryCheckbox.setEnabled(true); + nonLibraryCheckbox.setSelected(m_reportAllNonLibraryCalls); + final ButtonModel buttonModel = nonLibraryCheckbox.getModel(); + buttonModel.addChangeListener(new ChangeListener(){ + public void stateChanged(ChangeEvent e){ + m_reportAllNonLibraryCalls = buttonModel.isSelected(); + } + }); } - public JComponent getContentPanel() { + public JComponent getContentPanel(){ return contentPanel; } } - private class ReturnCheckSpecificationTableModel extends AbstractTableModel { + private class ReturnCheckSpecificationTableModel + extends AbstractTableModel{ - public int getRowCount() { + public int getRowCount(){ return callsToCheck.size(); } - public int getColumnCount() { + public int getColumnCount(){ return 2; } - public String getColumnName(int columnIndex) { - if (columnIndex == 0) { + public String getColumnName(int columnIndex){ + if(columnIndex == 0){ return "Class name"; } return "Method name"; } - public Class getColumnClass(int columnIndex) { + public Class getColumnClass(int columnIndex){ return String.class; } - public boolean isCellEditable(int rowIndex, int columnIndex) { + public boolean isCellEditable(int rowIndex, int columnIndex){ return true; } - public Object getValueAt(int rowIndex, int columnIndex) { - final ReturnCheckSpecification spec = (ReturnCheckSpecification) callsToCheck.get(rowIndex); - if (columnIndex == 0) { + public Object getValueAt(int rowIndex, int columnIndex){ + final ReturnCheckSpecification spec = (ReturnCheckSpecification) callsToCheck.get( + rowIndex); + if(columnIndex == 0){ return spec.getClassName(); - } else { + } else{ return spec.getMethodName(); } } - public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - final ReturnCheckSpecification spec = (ReturnCheckSpecification) callsToCheck.get(rowIndex); - if (columnIndex == 0) { + public void setValueAt(Object aValue, int rowIndex, int columnIndex){ + final ReturnCheckSpecification spec = (ReturnCheckSpecification) callsToCheck.get( + rowIndex); + if(columnIndex == 0){ spec.setClassName((String) aValue); - } else { + } else{ spec.setMethodName((String) aValue); } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/serialization/SerialVersionUIDNotStaticFinalInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/serialization/SerialVersionUIDNotStaticFinalInspection.java index 59e8c9ba0067..abdfb19851e5 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/serialization/SerialVersionUIDNotStaticFinalInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/serialization/SerialVersionUIDNotStaticFinalInspection.java @@ -50,7 +50,7 @@ public class SerialVersionUIDNotStaticFinalInspection extends ClassInspection { registerFieldError(field); } else { final PsiType type = field.getType(); - if (PsiType.LONG.equals(type)) { + if (!PsiType.LONG.equals(type)) { registerFieldError(field); } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/verbose/UnnecessaryFullyQualifiedNameInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/verbose/UnnecessaryFullyQualifiedNameInspection.java index 7c6e3579272d..79f44703cc17 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/verbose/UnnecessaryFullyQualifiedNameInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/verbose/UnnecessaryFullyQualifiedNameInspection.java @@ -52,8 +52,8 @@ public class UnnecessaryFullyQualifiedNameInspection extends ClassInspection { final boolean oldUseFQNamesInJavadoc = settings.USE_FQ_CLASS_NAMES_IN_JAVADOC; final boolean oldUseFQNames = settings.USE_FQ_CLASS_NAMES; try { - settings.USE_FQ_CLASS_NAMES_IN_JAVADOC = true; - settings.USE_FQ_CLASS_NAMES = true; + settings.USE_FQ_CLASS_NAMES_IN_JAVADOC = false; + settings.USE_FQ_CLASS_NAMES = false; final PsiJavaCodeReferenceElement reference = (PsiJavaCodeReferenceElement) descriptor.getPsiElement(); final PsiManager psiManager = reference.getManager(); final CodeStyleManager styleManager = psiManager.getCodeStyleManager(); diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/IgnoreResultOfCall.html b/plugins/InspectionGadgets/src/inspectionDescriptions/IgnoreResultOfCall.html index 22073c9deef1..09af8f1521e9 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/IgnoreResultOfCall.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/IgnoreResultOfCall.html @@ -12,6 +12,7 @@ as all of those methods are side-effect free and thus pointless if ignored Use the panel below to enter the class names and method names of the methods you wish to check for ignored returns. Class names must be specified as a simple string, while method names may be specified using a standard Java regular expression. Specifying a class names implicitly specifies -that class and all of it's subclasses. +that class and all of it's subclasses. In addition, you may choose to report any +call to a non-library call whose result is ignored Powered by InspectionGadgets