From 32e4a691f18f3b78b1348f320a43b7cb4ed5f0f4 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Thu, 18 Jan 2018 10:50:29 +0700 Subject: [PATCH] ToArrayCallWithZeroLengthArrayArgument: fixes according to review IDEA-CR-28526 1. Use default serialization 2. myEmptyPreferred is final 3. Typos in description --- ...WithZeroLengthArrayArgumentInspection.java | 27 +------------------ ...oArrayCallWithZeroLengthArrayArgument.html | 4 +-- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/ToArrayCallWithZeroLengthArrayArgumentInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/ToArrayCallWithZeroLengthArrayArgumentInspection.java index 1d5ac6c96f4b..d8f895430ee3 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/ToArrayCallWithZeroLengthArrayArgumentInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/ToArrayCallWithZeroLengthArrayArgumentInspection.java @@ -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; diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ToArrayCallWithZeroLengthArrayArgument.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ToArrayCallWithZeroLengthArrayArgument.html index bb467bd4ffcb..991eef793e5e 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/ToArrayCallWithZeroLengthArrayArgument.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ToArrayCallWithZeroLengthArrayArgument.html @@ -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 size and toArray 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.

This inspection allows to follow the uniform style: either using an empty array