ToArrayCallWithZeroLengthArrayArgument: fixes according to review IDEA-CR-28526

1. Use default serialization
2. myEmptyPreferred is final
3. Typos in description
This commit is contained in:
Tagir Valeev
2018-01-18 10:50:29 +07:00
parent a745aff70a
commit 32e4a691f1
2 changed files with 3 additions and 28 deletions
@@ -29,8 +29,6 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.callMatcher.CallMatcher;
import com.siyeh.ig.psiutils.*;
import one.util.streamex.StreamEx;
import org.jdom.Element;
import org.jetbrains.annotations.*;
import javax.swing.*;
@@ -40,7 +38,6 @@ public class ToArrayCallWithZeroLengthArrayArgumentInspection extends BaseInspec
CallMatcher.instanceCall(CommonClassNames.JAVA_UTIL_COLLECTION, "size").parameterCount(0);
private static final CallMatcher COLLECTION_TO_ARRAY =
CallMatcher.instanceCall(CommonClassNames.JAVA_UTIL_COLLECTION, "toArray").parameterCount(1);
private static final String PREFER_EMPTY_ARRAY_SETTING = "PreferEmptyArray";
private static final PreferEmptyArray DEFAULT_MODE = PreferEmptyArray.ALWAYS;
@@ -63,11 +60,6 @@ public class ToArrayCallWithZeroLengthArrayArgumentInspection extends BaseInspec
return PsiUtil.isLanguageLevel7OrHigher(expression);
}
}
@NotNull
static PreferEmptyArray from(String name) {
return StreamEx.of(values()).filterBy(PreferEmptyArray::name, name).findFirst().orElse(DEFAULT_MODE);
}
}
@NotNull
@@ -104,23 +96,6 @@ public class ToArrayCallWithZeroLengthArrayArgumentInspection extends BaseInspec
return InspectionGadgetsBundle.message("to.array.call.style.display.name");
}
@Override
public void readSettings(@NotNull Element node) {
Element element = node.getChild(PREFER_EMPTY_ARRAY_SETTING);
if (element != null) {
myMode = PreferEmptyArray.from(element.getAttributeValue("value"));
}
}
@Override
public void writeSettings(@NotNull Element node) {
if (myMode != DEFAULT_MODE) {
Element element = new Element(PREFER_EMPTY_ARRAY_SETTING);
element.setAttribute("value", myMode.toString());
node.addContent(element);
}
}
@Override
@NotNull
protected String buildErrorString(Object... infos) {
@@ -178,7 +153,7 @@ public class ToArrayCallWithZeroLengthArrayArgumentInspection extends BaseInspec
}
private static class ToArrayCallWithZeroLengthArrayArgumentFix extends InspectionGadgetsFix {
private boolean myEmptyPreferred;
private final boolean myEmptyPreferred;
public ToArrayCallWithZeroLengthArrayArgumentFix(boolean emptyPreferred) {
myEmptyPreferred = emptyPreferred;
@@ -8,10 +8,10 @@ There are two styles to convert collection to array: either using a pre-sized ar
call which is necessary to create an array of proper size was quite slow.
However since late updates of OpenJDK 6 this call was intrinsified making
the performance of the empty array version the same and sometimes even better, comparing
to the pre-sized version. Also passing pre-sized array is dangerous for concurrent or
to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or
synchronized collection as data race is possible between the <b>size</b> and <b>toArray</b>
call which may result in extra nulls at the end of the array if the collection was concurrently
shrinked during the operation.
shrunk during the operation.
</p>
<p>
This inspection allows to follow the uniform style: either using an empty array