Cleanup some usages of CollectionUtil

This commit is contained in:
Clément Fournier
2020-03-20 01:32:55 +01:00
parent 170360b309
commit e577169862
7 changed files with 40 additions and 37 deletions

View File

@ -8,9 +8,9 @@ import java.util.Collections;
import java.util.List;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.internal.util.IteratorUtil;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.NodeStream;
import net.sourceforge.pmd.util.CollectionUtil;
/**
@ -102,7 +102,7 @@ public class ASTClassOrInterfaceDeclaration extends AbstractAnyTypeDeclaration {
? getFirstChildOfType(ASTExtendsList.class)
: getFirstChildOfType(ASTImplementsList.class);
return it == null ? Collections.<ASTClassOrInterfaceType>emptyList() : CollectionUtil.toList(it.iterator());
return it == null ? Collections.emptyList() : IteratorUtil.toList(it.iterator());
}
}

View File

@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.rule.errorprone;
import static net.sourceforge.pmd.util.CollectionUtil.setOf;
import java.util.Set;
import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression;
@ -11,7 +13,6 @@ import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType;
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.util.CollectionUtil;
public class UnnecessaryConversionTemporaryRule extends AbstractJavaRule {
@ -19,12 +20,11 @@ public class UnnecessaryConversionTemporaryRule extends AbstractJavaRule {
private ASTPrimaryExpression primary;
private boolean usingPrimitiveWrapperAllocation;
private static final Set<String> PRIMITIVE_WRAPPERS = CollectionUtil
.asSet(new String[] { "Integer", "Boolean", "Double", "Long", "Short", "Byte", "Float" });
private static final Set<String> PRIMITIVE_WRAPPERS = setOf("Integer", "Boolean", "Double", "Long", "Short", "Byte", "Float");
@Override
public Object visit(ASTPrimaryExpression node, Object data) {
if (node.getNumChildren() == 0 || (node.getChild(0)).getNumChildren() == 0
if (node.getNumChildren() == 0 || node.getChild(0).getNumChildren() == 0
|| !(node.getChild(0).getChild(0) instanceof ASTAllocationExpression)) {
return super.visit(node, data);
}

View File

@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.rule.errorprone;
import static net.sourceforge.pmd.util.CollectionUtil.setOf;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@ -15,7 +17,6 @@ import net.sourceforge.pmd.lang.java.ast.ASTType;
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
import net.sourceforge.pmd.util.CollectionUtil;
/**
* An operation on an Immutable object (String, BigDecimal or BigInteger) won't
@ -27,25 +28,25 @@ public class UselessOperationOnImmutableRule extends AbstractJavaRule {
/**
* These are the BigDecimal methods which are immutable
*/
private static final Set<String> BIG_DECIMAL_METHODS = CollectionUtil
.asSet(new String[] { ".abs", ".add", ".divide", ".divideToIntegralValue", ".max", ".min", ".movePointLeft",
".movePointRight", ".multiply", ".negate", ".plus", ".pow", ".remainder", ".round",
".scaleByPowerOfTen", ".setScale", ".stripTrailingZeros", ".subtract", ".ulp", });
private static final Set<String> BIG_DECIMAL_METHODS =
setOf(".abs", ".add", ".divide", ".divideToIntegralValue", ".max", ".min", ".movePointLeft",
".movePointRight", ".multiply", ".negate", ".plus", ".pow", ".remainder", ".round",
".scaleByPowerOfTen", ".setScale", ".stripTrailingZeros", ".subtract", ".ulp");
/**
* These are the BigInteger methods which are immutable
*/
private static final Set<String> BIG_INTEGER_METHODS = CollectionUtil
.asSet(new String[] { ".abs", ".add", ".and", ".andNot", ".clearBit", ".divide", ".flipBit", ".gcd", ".max",
".min", ".mod", ".modInverse", ".modPow", ".multiply", ".negate", ".nextProbablePrine", ".not", ".or",
".pow", ".remainder", ".setBit", ".shiftLeft", ".shiftRight", ".subtract", ".xor", });
private static final Set<String> BIG_INTEGER_METHODS =
setOf(".abs", ".add", ".and", ".andNot", ".clearBit", ".divide", ".flipBit", ".gcd", ".max",
".min", ".mod", ".modInverse", ".modPow", ".multiply", ".negate", ".nextProbablePrine", ".not", ".or",
".pow", ".remainder", ".setBit", ".shiftLeft", ".shiftRight", ".subtract", ".xor");
/**
* These are the String methods which are immutable
*/
private static final Set<String> STRING_METHODS = CollectionUtil
.asSet(new String[] { ".concat", ".intern", ".replace", ".replaceAll", ".replaceFirst", ".substring",
".toLowerCase", ".toString", ".toUpperCase", ".trim", });
private static final Set<String> STRING_METHODS =
setOf(".concat", ".intern", ".replace", ".replaceAll", ".replaceFirst", ".substring",
".toLowerCase", ".toString", ".toUpperCase", ".trim");
/**
* These are the classes that the rule can apply to

View File

@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.rule.performance;
import static net.sourceforge.pmd.util.CollectionUtil.setOf;
import java.util.Set;
import net.sourceforge.pmd.RuleContext;
@ -15,15 +17,14 @@ import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix;
import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.util.CollectionUtil;
public class UnnecessaryWrapperObjectCreationRule extends AbstractJavaRule {
private static final Set<String> PREFIX_SET = CollectionUtil.asSet(new String[] { "Byte.valueOf", "Short.valueOf",
"Integer.valueOf", "Long.valueOf", "Float.valueOf", "Double.valueOf", "Character.valueOf", });
private static final Set<String> PREFIX_SET = setOf("Byte.valueOf", "Short.valueOf",
"Integer.valueOf", "Long.valueOf", "Float.valueOf", "Double.valueOf", "Character.valueOf");
private static final Set<String> SUFFIX_SET = CollectionUtil.asSet(new String[] { "toString", "byteValue",
"shortValue", "intValue", "longValue", "floatValue", "doubleValue", "charValue", });
private static final Set<String> SUFFIX_SET = setOf( "toString", "byteValue",
"shortValue", "intValue", "longValue", "floatValue", "doubleValue", "charValue");
@Override
public Object visit(ASTPrimaryPrefix node, Object data) {