IDEA-91663 (Method can be variable arity method shall have an option to ignore methods with multiple array arguments)

This commit is contained in:
Bas Leijdekkers
2014-05-22 11:43:55 +02:00
parent 2335b92e3f
commit 033aed0eb1
5 changed files with 25 additions and 3 deletions
@@ -1893,7 +1893,8 @@ arrays.deep.hash.code.quickfix=Replace with 'Arrays.deepHashCode()'
arrays.hash.code.quickfix=Replace with 'Arrays.hashCode()'
method.can.be.variable.arity.method.display.name=Method can be variable arity method
method.can.be.variable.arity.method.problem.descriptor=<code>#ref()</code> can be converted to variable arity method #loc
method.can.be.variable.arity.method.ignore.byte.short.option=<html>Ignore methods with a last parameter of type byte[] or short[]</html>
method.can.be.variable.arity.method.ignore.byte.short.option=Ignore methods with a last parameter of type byte[] or short[]
method.can.be.variable.arity.method.ignore.multiple.arrays.option=Ignore methods with multiple array parameters
convert.to.variable.arity.method.quickfix=Convert to varargs method
mismatched.string.builder.query.update.display.name=Mismatched query and update of StringBuilder
mismatched.string.builder.updated.problem.descriptor=Contents of {0} <code>#ref</code> are updated, but never queried #loc
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2013 Bas Leijdekkers
* Copyright 2011-2014 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,6 +42,9 @@ public class MethodCanBeVariableArityMethodInspection extends BaseInspection {
@SuppressWarnings("PublicField")
public boolean onlyReportPublicMethods = false;
@SuppressWarnings("PublicField")
public boolean ignoreMultipleArrayParameters = false;
@Nls
@NotNull
@Override
@@ -62,6 +65,8 @@ public class MethodCanBeVariableArityMethodInspection extends BaseInspection {
"ignoreByteAndShortArrayParameters");
panel.addCheckbox(InspectionGadgetsBundle.message("ignore.methods.overriding.super.method"), "ignoreOverridingMethods");
panel.addCheckbox(InspectionGadgetsBundle.message("only.report.public.methods.option"), "onlyReportPublicMethods");
panel.addCheckbox(InspectionGadgetsBundle.message("method.can.be.variable.arity.method.ignore.multiple.arrays.option"),
"ignoreMultipleArrayParameters");
return panel;
}
@@ -116,6 +121,14 @@ public class MethodCanBeVariableArityMethodInspection extends BaseInspection {
if (ignoreOverridingMethods && MethodUtils.hasSuper(method)) {
return;
}
if (ignoreMultipleArrayParameters) {
for (int i = 0, length = parameters.length - 1; i < length; i++) {
final PsiParameter parameter = parameters[i];
if (parameter.getType() instanceof PsiArrayType) {
return;
}
}
}
registerMethodError(method);
}
}
@@ -7,10 +7,14 @@ This inspection only reports if the project or module is configured to use a
language level of 5.0 or higher.
<!-- tooltip end -->
<p>
Use the first checkbox below to not offer to convert byte[] or short[] parameters to vararg.
Use the first checkbox below to not offer to convert <b>byte[]</b> or <b>short[]</b> parameters to vararg.
<p>
Use the second checkbox below to ignore methods overriding or implementing a method from a superclass.
<p>
Use the third checkbox below to only report when the method is <b>public</b>
<p>
Use the fourth checkbox below ot ignore method with more than one array parameter.
<p>
<small>New in 10.5</small>
</body>
</html>
@@ -32,4 +32,7 @@ class Annotated {
}
interface X {
void <warning descr="'m()' can be converted to variable arity method">m</warning>(String[] ss);
}
class Yes {
void m(int[] is, int[] js) {}
}
@@ -15,6 +15,7 @@ public class MethodCanBeVariableArityMethodInspectionTest extends LightInspectio
inspection.ignoreByteAndShortArrayParameters = true;
inspection.ignoreOverridingMethods = true;
inspection.onlyReportPublicMethods = true;
inspection.ignoreMultipleArrayParameters = true;
return inspection;
}
}