From d650c87d8d4a60d4ad6fe2a514524d952a50bd94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 28 Jul 2020 12:38:00 +0200 Subject: [PATCH] Remove more utils --- .../main/java/net/sourceforge/pmd/Report.java | 23 +- .../lang/rule/ParametricRuleViolation.java | 11 +- .../pmd/lang/symboltable/Applier.java | 7 +- .../lang/symboltable/ImageFinderFunction.java | 7 +- .../AbstractMultiPackagedProperty.java | 78 ---- .../properties/AbstractPackagedProperty.java | 71 ---- .../PackagedPropertyDescriptor.java | 30 -- .../pmd/properties/PropertyTypeId.java | 13 - .../modules/PackagedPropertyModule.java | 181 --------- .../modules/TypePropertyModule.java | 34 -- .../pmd/renderers/TextColorRenderer.java | 3 +- .../sourceforge/pmd/util/CollectionUtil.java | 21 +- .../sourceforge/pmd/util/DateTimeUtil.java | 59 --- .../sourceforge/pmd/util/FileIterable.java | 88 ---- .../pmd/util/NumericConstants.java | 21 - .../sourceforge/pmd/util/SearchFunction.java | 18 - .../net/sourceforge/pmd/util/StringUtil.java | 380 ------------------ .../pmd/lang/symboltable/ApplierTest.java | 7 +- .../pmd/util/DateTimeUtilTest.java | 38 -- .../sourceforge/pmd/util/StringUtilTest.java | 26 -- .../rule/documentation/CommentSizeRule.java | 6 +- .../errorprone/MoreThanOneLoggerRule.java | 3 +- .../DeclarationFinderFunction.java | 7 +- .../symboltable/ImageFinderFunctionTest.java | 4 +- .../pmd/lang/jsp/ast/OpenTagRegister.java | 7 +- .../rule/design/NPathComplexityVisitor.java | 7 +- .../plsql/rule/design/TooManyFieldsRule.java | 3 +- .../pmd/lang/vf/ast/OpenTagRegister.java | 7 +- 28 files changed, 65 insertions(+), 1095 deletions(-) delete mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/properties/AbstractMultiPackagedProperty.java delete mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/properties/AbstractPackagedProperty.java delete mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/properties/PackagedPropertyDescriptor.java delete mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/properties/modules/PackagedPropertyModule.java delete mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/properties/modules/TypePropertyModule.java delete mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/util/DateTimeUtil.java delete mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/util/FileIterable.java delete mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/util/NumericConstants.java delete mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/util/SearchFunction.java delete mode 100644 pmd-core/src/test/java/net/sourceforge/pmd/util/DateTimeUtilTest.java diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/Report.java b/pmd-core/src/main/java/net/sourceforge/pmd/Report.java index f70506fabf..0bc70cdb51 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/Report.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/Report.java @@ -8,6 +8,7 @@ import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -16,8 +17,6 @@ import java.util.List; import java.util.Map; import net.sourceforge.pmd.renderers.AbstractAccumulatingRenderer; -import net.sourceforge.pmd.util.DateTimeUtil; -import net.sourceforge.pmd.util.NumericConstants; /** * A {@link Report} collects all informations during a PMD execution. This @@ -79,7 +78,23 @@ public class Report implements Iterable { * @return human readable representation of the duration */ public String getTime() { - return DateTimeUtil.asHoursMinutesSeconds(duration); + assert this.duration >= 0; + Duration duration = Duration.ofMillis(this.duration); + long seconds = duration.getSeconds(); + + long hours = seconds / 3600; + long minutes = seconds / 60; + + StringBuilder res = new StringBuilder(); + if (hours > 0) { + res.append(hours).append("h "); + } + if (hours > 0 || minutes > 0) { + res.append(minutes).append("m "); + } + res.append(seconds).append('s'); + + return res.toString(); } } @@ -178,7 +193,7 @@ public class Report implements Iterable { for (RuleViolation rv : violations) { String name = rv.getRule().getName(); if (!summary.containsKey(name)) { - summary.put(name, NumericConstants.ZERO); + summary.put(name, 0); } Integer count = summary.get(name); summary.put(name, count + 1); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/ParametricRuleViolation.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/ParametricRuleViolation.java index 8e8073aced..ae4999b152 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/ParametricRuleViolation.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/ParametricRuleViolation.java @@ -11,7 +11,6 @@ import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.properties.PropertyDescriptor; -import net.sourceforge.pmd.util.StringUtil; public class ParametricRuleViolation implements RuleViolation { @@ -66,19 +65,15 @@ public class ParametricRuleViolation implements RuleViolation { final int endIndex = buf.indexOf("}", startIndex); if (endIndex >= 0) { final String name = buf.substring(startIndex + 2, endIndex); - if (isVariable(name)) { - buf.replace(startIndex, endIndex + 1, getVariableValue(name)); + String variableValue = getVariableValue(name); + if (variableValue != null) { + buf.replace(startIndex, endIndex + 1, variableValue); } } } return buf.toString(); } - protected boolean isVariable(String name) { - return StringUtil.isAnyOf(name, "variableName", "methodName", "className", "packageName") - || rule.getPropertyDescriptor(name) != null; - } - protected String getVariableValue(String name) { if ("variableName".equals(name)) { return variableName; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/symboltable/Applier.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/symboltable/Applier.java index e8c93403db..e42b0cc8c0 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/symboltable/Applier.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/symboltable/Applier.java @@ -5,8 +5,7 @@ package net.sourceforge.pmd.lang.symboltable; import java.util.Iterator; - -import net.sourceforge.pmd.util.SearchFunction; +import java.util.function.Predicate; public final class Applier { @@ -14,8 +13,8 @@ public final class Applier { // utility class } - public static void apply(SearchFunction f, Iterator i) { - while (i.hasNext() && f.applyTo(i.next())) { + public static void apply(Predicate f, Iterator i) { + while (i.hasNext() && f.test(i.next())) { // Nothing to do } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/symboltable/ImageFinderFunction.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/symboltable/ImageFinderFunction.java index b9e14141a5..5b8dcfd944 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/symboltable/ImageFinderFunction.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/symboltable/ImageFinderFunction.java @@ -8,10 +8,9 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.function.Predicate; -import net.sourceforge.pmd.util.SearchFunction; - -public class ImageFinderFunction implements SearchFunction { +public class ImageFinderFunction implements Predicate { private final Set images; private NameDeclaration decl; @@ -25,7 +24,7 @@ public class ImageFinderFunction implements SearchFunction { } @Override - public boolean applyTo(NameDeclaration nameDeclaration) { + public boolean test(NameDeclaration nameDeclaration) { if (images.contains(nameDeclaration.getImage())) { decl = nameDeclaration; return false; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/AbstractMultiPackagedProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/AbstractMultiPackagedProperty.java deleted file mode 100644 index 31882c325e..0000000000 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/AbstractMultiPackagedProperty.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.properties; - -import java.util.List; -import java.util.Map; - -import net.sourceforge.pmd.properties.modules.PackagedPropertyModule; - - -/** - * Multi-valued property restricting the type of its values to some packages. - * - * @param The type of the values - * - * @author Brian Remedios - * @author Clément Fournier - * @version Refactored June 2017 (6.0.0) - */ -@Deprecated -/* default */ abstract class AbstractMultiPackagedProperty extends AbstractMultiValueProperty - implements PackagedPropertyDescriptor> { - - - protected final PackagedPropertyModule module; - - - /** - * Create a packaged property. - * - * @param theName Name - * @param theDescription Description - * @param theDefault Default value - * @param theUIOrder UI order - * @param module - * - * @throws IllegalArgumentException - */ - protected AbstractMultiPackagedProperty(String theName, String theDescription, List theDefault, - float theUIOrder, boolean isDefinedExternally, - PackagedPropertyModule module) { - super(theName, theDescription, theDefault, theUIOrder, MULTI_VALUE_DELIMITER, isDefinedExternally); - this.module = module; - } - - - @Override - protected void addAttributesTo(Map attributes) { - super.addAttributesTo(attributes); - module.addAttributesTo(attributes); - } - - - @Override - protected String valueErrorFor(T value) { - if (value == null) { - String err = super.valueErrorFor(null); - if (err != null) { - return err; - } - } - - return module.valueErrorFor(value); - } - - - @Override - public String[] legalPackageNames() { - return module.legalPackageNames(); - } - - - protected String[] packageNamesIn(Map params) { - return module.packageNamesIn(params); - } -} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/AbstractPackagedProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/AbstractPackagedProperty.java deleted file mode 100644 index 94921e7eae..0000000000 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/AbstractPackagedProperty.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.properties; - -import java.util.Map; - -import net.sourceforge.pmd.properties.modules.PackagedPropertyModule; - - -/** - * Property which restricts the type of its values to some packages. If the legalPackageNames value is set to null then - * no restrictions are made. - * - * @param The type of the values - * - * @author Brian Remedios - * @author Clément Fournier - * @version Refactored June 2017 (6.0.0) - */ -@Deprecated -/* default */ abstract class AbstractPackagedProperty extends AbstractSingleValueProperty - implements PackagedPropertyDescriptor { - - protected final PackagedPropertyModule module; - - - /** - * Create a packaged property. - * - * @param theName Name - * @param theDescription Description - * @param theDefault Default value - * @param theUIOrder UI order - * @param module - * - * @throws IllegalArgumentException - */ - protected AbstractPackagedProperty(String theName, String theDescription, T theDefault, - float theUIOrder, boolean isDefinedExternally, - PackagedPropertyModule module) { - super(theName, theDescription, theDefault, theUIOrder, isDefinedExternally); - this.module = module; - } - - - @Override - protected void addAttributesTo(Map attributes) { - super.addAttributesTo(attributes); - module.addAttributesTo(attributes); - } - - - @Override - protected String valueErrorFor(T value) { - return module.valueErrorFor(value); - } - - - @Override - public String[] legalPackageNames() { - return module.legalPackageNames(); - } - - - protected String[] packageNamesIn(Map params) { - return module.packageNamesIn(params); - } - -} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PackagedPropertyDescriptor.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PackagedPropertyDescriptor.java deleted file mode 100644 index e650d9a9b9..0000000000 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PackagedPropertyDescriptor.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.properties; - -/** - * Defines a property descriptor type whose values can be described by qualified names and thus restricted to only some - * packages. These typically use values such as {@link Class} and {@link java.lang.reflect.Method}. - * - * @param type of the property value - * - * @author Clément Fournier - */ -@Deprecated -public interface PackagedPropertyDescriptor extends PropertyDescriptor { - - /** Delimiter used to separate package names. */ - char PACKAGE_NAME_DELIMITER = ' '; - /** Delimiter used to separate multiple values if this descriptor is multi valued. */ - char MULTI_VALUE_DELIMITER = '|'; - - - /** - * Returns the legal package names. - * - * @return The legal package names - */ - String[] legalPackageNames(); -} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyTypeId.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyTypeId.java index 31fc29be43..0ac9b4a361 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyTypeId.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyTypeId.java @@ -116,19 +116,6 @@ public enum PropertyTypeId { } - /** - * Returns true if the property corresponding to this factory is packaged, - * which means it can be safely cast to a {@link PackagedPropertyDescriptor}. - * - * @return whether the property is packaged - */ - @Deprecated - public boolean isPropertyPackaged() { - return factory instanceof PropertyDescriptorBuilderConversionWrapper.SingleValue.Packaged - || factory instanceof PropertyDescriptorBuilderConversionWrapper.MultiValue.Packaged; - } - - /** * Returns true if the property corresponding to this factory takes * lists of values as its value. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/modules/PackagedPropertyModule.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/modules/PackagedPropertyModule.java deleted file mode 100644 index 5e90f6f4cc..0000000000 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/modules/PackagedPropertyModule.java +++ /dev/null @@ -1,181 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.properties.modules; - -import static net.sourceforge.pmd.properties.PackagedPropertyDescriptor.PACKAGE_NAME_DELIMITER; -import static net.sourceforge.pmd.properties.PropertyDescriptorField.LEGAL_PACKAGES; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.regex.Pattern; - -import org.apache.commons.lang3.StringUtils; - -import net.sourceforge.pmd.properties.PropertyDescriptorField; - - -/** - * Factorises common functionality for packaged properties. - * - * @author Clément Fournier - */ -@Deprecated -public abstract class PackagedPropertyModule { - - private static final Pattern PACKAGE_NAME_PATTERN = Pattern.compile("(\\w+)(\\.\\w+)*"); - - private final String[] legalPackageNames; - - - public PackagedPropertyModule(String[] legalPackageNames, List defaults) { - - checkValidPackages(legalPackageNames); - checkValidDefaults(defaults, legalPackageNames); - - this.legalPackageNames = legalPackageNames; - } - - - /** - * Checks that the legal packages are okay. - * - * @param legalNamePrefixes Prefixes to check. Can be null, but not contain null - * - * @throws IllegalArgumentException If the prefixes contain null - * @throws IllegalArgumentException If one name that does not look like a package name - */ - private void checkValidPackages(String[] legalNamePrefixes) throws IllegalArgumentException { - if (legalNamePrefixes == null) { - return; - } - - for (String name : legalNamePrefixes) { - if (name == null) { - throw new IllegalArgumentException("Null is not allowed in the legal package names:" - + Arrays.toString(legalNamePrefixes)); - } else if (!PACKAGE_NAME_PATTERN.matcher(name).matches()) { - throw new IllegalArgumentException("One name is not a package: '" + name + "'"); - - } - } - } - - - /** - * Evaluates the names of the items against the allowable name prefixes. If one or more do not have valid prefixes - * then an exception will be thrown. - * - * @param items Items to check - * @param legalNamePrefixes Legal name prefixes - * - * @throws IllegalArgumentException if some items are not allowed - */ - private void checkValidDefaults(List items, String[] legalNamePrefixes) { - - if (legalNamePrefixes == null) { // valid value, matches everything - return; - } - - Set nameSet = new HashSet<>(); - - for (T item : items) { - if (item == null) { - continue; - } - nameSet.add(packageNameOf(item)); - } - - Set notAllowed = new HashSet<>(nameSet); - - - for (String name : nameSet) { - for (String prefix : legalNamePrefixes) { - if (name.startsWith(prefix)) { - notAllowed.remove(name); - break; - } - } - } - - if (notAllowed.isEmpty()) { - return; - } - - throw new IllegalArgumentException("Invalid items: " + notAllowed); - } - - - /** - * Returns the package name of the item. - * - * @param item Item (not null) - * - * @return Package name of the item - */ - protected abstract String packageNameOf(T item); - - - public String valueErrorFor(T value) { - - if (legalPackageNames == null) { - return null; // no restriction - } - - String name = packageNameOf(value); - - for (int i = 0; i < legalPackageNames.length; i++) { - if (name.startsWith(legalPackageNames[i])) { - return null; - } - } - - return "Disallowed " + itemTypeName() + ": " + name; - } - - - /** - * Returns the name of the type of item. - * - * @return The name of the type of item - */ - protected abstract String itemTypeName(); - - - public String[] legalPackageNames() { - return Arrays.copyOf(legalPackageNames, legalPackageNames.length); - } - - - public void addAttributesTo(Map attributes) { - attributes.put(LEGAL_PACKAGES, delimitedPackageNames()); - } - - - private String delimitedPackageNames() { - - if (legalPackageNames == null || legalPackageNames.length == 0) { - return ""; - } - if (legalPackageNames.length == 1) { - return legalPackageNames[0]; - } - - StringBuilder sb = new StringBuilder(); - sb.append(legalPackageNames[0]); - for (int i = 1; i < legalPackageNames.length; i++) { - sb.append(PACKAGE_NAME_DELIMITER).append(legalPackageNames[i]); - } - return sb.toString(); - } - - - public String[] packageNamesIn(Map params) { - return StringUtils.split(params.get(LEGAL_PACKAGES), PACKAGE_NAME_DELIMITER); - } - -} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/modules/TypePropertyModule.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/modules/TypePropertyModule.java deleted file mode 100644 index 52e4f5d87f..0000000000 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/modules/TypePropertyModule.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.properties.modules; - -import java.util.List; - - -/** - * Factorises common functionality for type properties. - * - * @author Clément Fournier - */ -@Deprecated -public class TypePropertyModule extends PackagedPropertyModule { - - public TypePropertyModule(String[] legalPackageNames, List defaults) { - super(legalPackageNames, defaults); - } - - - @Override - protected String packageNameOf(Class item) { - return item.getName(); - } - - - @Override - protected String itemTypeName() { - return "type"; - } - -} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextColorRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextColorRenderer.java index 4dd4667070..208a03261f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextColorRenderer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextColorRenderer.java @@ -22,7 +22,6 @@ import net.sourceforge.pmd.Report; import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.properties.PropertyDescriptor; import net.sourceforge.pmd.properties.PropertyFactory; -import net.sourceforge.pmd.util.NumericConstants; /** *

@@ -204,7 +203,7 @@ public class TextColorRenderer extends AbstractAccumulatingRenderer { continue; } Integer o = summary.get(key); - summary.put(key, o == null ? NumericConstants.ONE : o + 1); + summary.put(key, o == null ? 1 : o + 1); } return summary; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/CollectionUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/CollectionUtil.java index 82c19c936e..80498daf7c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/CollectionUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/CollectionUtil.java @@ -84,7 +84,10 @@ public final class CollectionUtil { * @param includeInterfaces * boolean * @return boolean + * + * @deprecated Will be replaced with type resolution */ + @Deprecated public static boolean isCollectionType(String typeName, boolean includeInterfaces) { if (COLLECTION_CLASSES_BY_NAMES.contains(typeName)) { @@ -94,18 +97,6 @@ public final class CollectionUtil { return includeInterfaces && COLLECTION_INTERFACES_BY_NAMES.contains(typeName); } - /** - * Returns the items as a populated set. - * - * @param items - * Object[] - * @return Set - */ - public static Set asSet(T[] items) { - - return new HashSet<>(Arrays.asList(items)); - } - /** * Creates and returns a map populated with the keyValuesSets where the * value held by the tuples are they key and value in that order. @@ -115,7 +106,10 @@ public final class CollectionUtil { * @param values * V[] * @return Map + * + * @deprecated Used by deprecated property types */ + @Deprecated public static Map mapFrom(K[] keys, V[] values) { if (keys.length != values.length) { throw new RuntimeException("mapFrom keys and values arrays have different sizes"); @@ -133,7 +127,10 @@ public final class CollectionUtil { * @param source * Map * @return Map + * + * @deprecated Used by deprecated property types */ + @Deprecated public static Map invertedMapFrom(Map source) { Map map = new HashMap<>(source.size()); for (Map.Entry entry : source.entrySet()) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/DateTimeUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/DateTimeUtil.java deleted file mode 100644 index 4a374ce3a1..0000000000 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/DateTimeUtil.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.util; - -import net.sourceforge.pmd.annotation.InternalApi; - -/** - * - * @author Brian Remedios - */ -@InternalApi -@Deprecated -public final class DateTimeUtil { - - private DateTimeUtil() { - } - - /** - * - * @param milliseconds - * @return String - */ - public static String asHoursMinutesSeconds(long milliseconds) { - - if (milliseconds < 0) { - throw new IllegalArgumentException(); - } - - long seconds = 0; - long minutes = 0; - long hours = 0; - - if (milliseconds > 1000) { - seconds = milliseconds / 1000; - } - - if (seconds > 60) { - minutes = seconds / 60; - seconds = seconds % 60; - } - - if (minutes > 60) { - hours = minutes / 60; - minutes = minutes % 60; - } - - StringBuilder res = new StringBuilder(); - if (hours > 0) { - res.append(hours).append("h "); - } - if (hours > 0 || minutes > 0) { - res.append(minutes).append("m "); - } - res.append(seconds).append('s'); - return res.toString(); - } -} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/FileIterable.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/FileIterable.java deleted file mode 100644 index fdd4a1f8f3..0000000000 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/FileIterable.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.util; - -import java.io.File; -import java.io.IOException; -import java.io.LineNumberReader; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Iterator; - -/** - * - *

- * Handy class to easily iterate over a file, line by line, using a Java 5 for - * loop. - *

- * - * @author Romain Pelisse <belaran@gmail.com> - * @deprecated Just use {@link Files#readAllLines(Path, Charset)} or {@code lines} on Java 8 - */ -@Deprecated -public class FileIterable implements Iterable { - - private LineNumberReader lineReader = null; - - public FileIterable(File file) { - try { - lineReader = new LineNumberReader(Files.newBufferedReader(file.toPath(), Charset.defaultCharset())); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - protected void finalize() throws Throwable { - try { - if (lineReader != null) { - lineReader.close(); - } - } catch (IOException e) { - throw new IllegalStateException(e); - } - super.finalize(); - } - - @Override - public Iterator iterator() { - return new FileIterator(); - } - - class FileIterator implements Iterator { - - private boolean hasNext = true; - - @Override - public boolean hasNext() { - return hasNext; - } - - @Override - public String next() { - String line = null; - try { - if (hasNext) { - line = lineReader.readLine(); - if (line == null) { - hasNext = false; - line = ""; - } - } - return line; - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException("remove is not supported by " + this.getClass().getName()); - } - - } - -} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/NumericConstants.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/NumericConstants.java deleted file mode 100644 index fc37a21165..0000000000 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/NumericConstants.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.util; - -/** - * @deprecated These constants were only useful before autoboxing was - * introduced, just use a literal or define your own constants - */ -@Deprecated -public final class NumericConstants { - - public static final Integer ZERO = 0; - - public static final Integer ONE = 1; - - public static final Float FLOAT_ZERO = 0.0f; - - private NumericConstants() { } -} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/SearchFunction.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/SearchFunction.java deleted file mode 100644 index 709aa57325..0000000000 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/SearchFunction.java +++ /dev/null @@ -1,18 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.util; - -/** - * @deprecated Will be replaced with standard java.util.function.Predicate with 7.0.0 - */ -@Deprecated -public interface SearchFunction { - /** - * Applies the search function over a single element. - * @param o The element to analyze. - * @return True if the search should continue, false otherwhise. - */ - boolean applyTo(E o); -} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/StringUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/StringUtil.java index 95765777ba..6b94dd6b64 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/StringUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/StringUtil.java @@ -4,9 +4,6 @@ package net.sourceforge.pmd.util; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.regex.Matcher; @@ -167,44 +164,6 @@ public final class StringUtil { } - /** - * Return whether the non-null text arg starts with any of the prefix - * values. - * - * @return boolean - * - * @deprecated {@link StringUtils#startsWithAny(CharSequence, CharSequence...)} - */ - @Deprecated - public static boolean startsWithAny(String text, String... prefixes) { - - for (String prefix : prefixes) { - if (text.startsWith(prefix)) { - return true; - } - } - - return false; - } - - - /** - * Returns whether the non-null text arg matches any of the test values. - * - * @return boolean - */ - public static boolean isAnyOf(String text, String... tests) { - - for (String test : tests) { - if (text.equals(test)) { - return true; - } - } - - return false; - } - - /** * Checks for the existence of any of the listed prefixes on the non-null * text and removes them. @@ -223,100 +182,6 @@ public final class StringUtil { } - /** - * @param value String - * - * @return boolean - * - * @deprecated {@link StringUtils#isNotBlank(CharSequence)} - */ - @Deprecated - public static boolean isNotEmpty(String value) { - return !isEmpty(value); - } - - - /** - * Returns true if the value arg is either null, empty, or full of - * whitespace characters. More efficient that calling - * (string).trim().length() == 0. - * - * @param value String to test - * - * @return true if the value is empty, false otherwise. - * - * @deprecated {@link StringUtils#isBlank(CharSequence)} - */ - @Deprecated - public static boolean isEmpty(String value) { - return StringUtils.isBlank(value); - } - - - /** - * Returns true if the argument is null or the empty string. - * - * @param value String to test - * - * @return True if the argument is null or the empty string - * - * @deprecated {@link StringUtils#isEmpty(CharSequence)} - */ - @Deprecated - public static boolean isMissing(String value) { - return StringUtils.isEmpty(value); - } - - - /** - * Returns true if both strings are effectively null or whitespace, returns - * false otherwise if they have actual text that differs. - * - * @return boolean - */ - @Deprecated - public static boolean areSemanticEquals(String a, String b) { - - if (a == null) { - return isEmpty(b); - } - if (b == null) { - return isEmpty(a); - } - - return a.equals(b); - } - - - /** - * @param original String - * @param oldString String - * @param newString String - * - * @return String - * - * @deprecated {@link StringUtils#replace(String, String, String)} - */ - @Deprecated - public static String replaceString(final String original, final String oldString, final String newString) { - int index = original.indexOf(oldString); - if (index < 0) { - return original; - } else { - final String replace = newString == null ? "" : newString; - final StringBuilder buf = new StringBuilder(Math.max(16, original.length() + replace.length())); - int last = 0; - while (index != -1) { - buf.append(original.substring(last, index)); - buf.append(replace); - last = index + oldString.length(); - index = original.indexOf(oldString, last); - } - buf.append(original.substring(last)); - return buf.toString(); - } - } - /** * @param supportUTF8 override the default setting, whether special characters should be replaced with entities ( * false) or should be included as is ( true). @@ -387,174 +252,6 @@ public final class StringUtil { return s; } - /** - * @param original String - * @param oldChar char - * @param newString String - * - * @return String - * - * @deprecated {@link StringUtils#replace(String, String, String)} or {@link StringUtils#replaceChars(String, char, char)} - */ - @Deprecated - public static String replaceString(final String original, char oldChar, final String newString) { - int index = original.indexOf(oldChar); - if (index < 0) { - return original; - } else { - final String replace = newString == null ? "" : newString; - final StringBuilder buf = new StringBuilder(Math.max(16, original.length() + replace.length())); - int last = 0; - while (index != -1) { - buf.append(original.substring(last, index)); - buf.append(replace); - last = index + 1; - index = original.indexOf(oldChar, last); - } - buf.append(original.substring(last)); - return buf.toString(); - } - } - - - /** - * Parses the input source using the delimiter specified. This method is - * much faster than using the StringTokenizer or String.split(char) approach - * and serves as a replacement for String.split() for JDK1.3 that doesn't - * have it. - * - * @param source String - * @param delimiter char - * - * @return String[] - * - * @deprecated {@link StringUtils#split(String, char)} - */ - @Deprecated - public static String[] substringsOf(String source, char delimiter) { - - if (source == null || source.length() == 0) { - return EMPTY_STRINGS; - } - - int delimiterCount = 0; - int length = source.length(); - char[] chars = source.toCharArray(); - - for (int i = 0; i < length; i++) { - if (chars[i] == delimiter) { - delimiterCount++; - } - } - - if (delimiterCount == 0) { - return new String[] {source}; - } - - String[] results = new String[delimiterCount + 1]; - - int i = 0; - int offset = 0; - - while (offset <= length) { - int pos = source.indexOf(delimiter, offset); - if (pos < 0) { - pos = length; - } - results[i++] = pos == offset ? "" : source.substring(offset, pos); - offset = pos + 1; - } - - return results; - } - - - /** - * Much more efficient than StringTokenizer. - * - * @param str String - * @param separator char - * - * @return String[] - * - * @deprecated {@link StringUtils#split(String, String)} - */ - @Deprecated - public static String[] substringsOf(String str, String separator) { - - if (str == null || str.length() == 0) { - return EMPTY_STRINGS; - } - - int index = str.indexOf(separator); - if (index == -1) { - return new String[] {str}; - } - - List list = new ArrayList<>(); - int currPos = 0; - int len = separator.length(); - while (index != -1) { - list.add(str.substring(currPos, index)); - currPos = index + len; - index = str.indexOf(separator, currPos); - } - list.add(str.substring(currPos)); - return list.toArray(new String[0]); - } - - - /** - * Copies the elements returned by the iterator onto the string buffer each - * delimited by the separator. - * - * @param sb StringBuffer - * @param iter Iterator - * @param separator String - * - * @deprecated {@link StringUtils#join(Iterator, String)} - */ - @Deprecated - public static void asStringOn(StringBuffer sb, Iterator iter, String separator) { - - if (!iter.hasNext()) { - return; - } - - sb.append(iter.next()); - - while (iter.hasNext()) { - sb.append(separator); - sb.append(iter.next()); - } - } - - - /** - * Copies the array items onto the string builder each delimited by the - * separator. Does nothing if the array is null or empty. - * - * @param sb StringBuilder - * @param items Object[] - * @param separator String - * - * @deprecated {@link StringUtils#join(Iterable, String)} - */ - @Deprecated - public static void asStringOn(StringBuilder sb, Object[] items, String separator) { - - if (items == null || items.length == 0) { - return; - } - - sb.append(items[0]); - - for (int i = 1; i < items.length; i++) { - sb.append(separator); - sb.append(items[i]); - } - } - /** * Determine the maximum number of common leading whitespace characters the @@ -634,28 +331,6 @@ public final class StringUtil { } - /** - * Left pads a string. - * - * @param s The String to pad - * @param length The desired minimum length of the resulting padded String - * - * @return The resulting left padded String - * - * @deprecated {@link StringUtils#leftPad(String, int)} - */ - @Deprecated - public static String lpad(String s, int length) { - String res = s; - if (length - s.length() > 0) { - char[] arr = new char[length - s.length()]; - Arrays.fill(arr, ' '); - res = new StringBuilder(length).append(arr).append(s).toString(); - } - return res; - } - - /** * Are the two String values the same. The Strings can be optionally trimmed * before checking. The Strings can be optionally compared ignoring case. @@ -729,61 +404,6 @@ public final class StringUtil { } - /** - * Converts the given string to Camel case, - * that is, removing all spaces, and capitalising - * the first letter of each word except the first. - * - *

If the first word starts with an uppercase - * letter, it's kept as is. This method can thus - * be used for Pascal case too. - * - * @param name The string to convert - * - * @return The string converted to Camel case - * - * @deprecated Use {@link CaseConvention} - */ - @Deprecated - public static String toCamelCase(String name) { - return toCamelCase(name, false); - } - - - /** - * Converts the given string to Camel case, - * that is, removing all spaces, and capitalising - * the first letter of each word except the first. - * - *

The second parameter can be used to force the - * words to be converted to lowercase before capitalising. - * This can be useful if eg the first word contains - * several uppercase letters. - * - * @param name The string to convert - * @param forceLowerCase Whether to force removal of all upper - * case letters except on word start - * - * @return The string converted to Camel case - * - * @deprecated Use {@link CaseConvention} - */ - @Deprecated - public static String toCamelCase(String name, boolean forceLowerCase) { - StringBuilder sb = new StringBuilder(); - boolean isFirst = true; - for (String word : name.trim().split("\\s++")) { - String pretreated = forceLowerCase ? word.toLowerCase(Locale.ROOT) : word; - if (isFirst) { - sb.append(pretreated); - isFirst = false; - } else { - sb.append(StringUtils.capitalize(pretreated)); - } - } - return sb.toString(); - } - /** * Replaces unprintable characters by their escaped (or unicode escaped) * equivalents in the given string diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/symboltable/ApplierTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/symboltable/ApplierTest.java index e3dc8558ad..934ab5edb0 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/symboltable/ApplierTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/symboltable/ApplierTest.java @@ -8,14 +8,13 @@ import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.List; +import java.util.function.Predicate; import org.junit.Test; -import net.sourceforge.pmd.util.SearchFunction; - public class ApplierTest { - private static class MyFunction implements SearchFunction { + private static class MyFunction implements Predicate { private int numCallbacks = 0; private final int maxCallbacks; @@ -24,7 +23,7 @@ public class ApplierTest { } @Override - public boolean applyTo(Object o) { + public boolean test(Object o) { this.numCallbacks++; return numCallbacks < maxCallbacks; } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/util/DateTimeUtilTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/util/DateTimeUtilTest.java deleted file mode 100644 index 61d66292cb..0000000000 --- a/pmd-core/src/test/java/net/sourceforge/pmd/util/DateTimeUtilTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.util; - -import static org.junit.Assert.assertEquals; - -import java.util.Collection; - -import org.junit.Test; - -import net.sourceforge.pmd.ReadableDurationTest; - -/** - * - * @author Brian Remedios - */ -public class DateTimeUtilTest { - - @Test - public void testConversions() { - - Collection stringNumberPairs = ReadableDurationTest.data(); - - for (Object[] stringAndNumber : stringNumberPairs) { - String result = (String) stringAndNumber[0]; - Integer milliseconds = (Integer) stringAndNumber[1]; - - assertEquals(result, DateTimeUtil.asHoursMinutesSeconds(milliseconds)); - } - - } - - public static junit.framework.Test suite() { - return new junit.framework.JUnit4TestAdapter(DateTimeUtilTest.class); - } -} diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/util/StringUtilTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/util/StringUtilTest.java index 9362373baf..f03e7ce6ca 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/util/StringUtilTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/util/StringUtilTest.java @@ -10,11 +10,6 @@ import org.junit.Test; public class StringUtilTest { - @Test - public void testReplaceWithOneChar() { - assertEquals("faa", StringUtil.replaceString("foo", 'o', "a")); - } - @Test public void testColumnNumber() { assertEquals(-1, StringUtil.columnNumberAt("f\rah\nb", -1)); @@ -52,27 +47,6 @@ public class StringUtilTest { assertEquals(-1, StringUtil.columnNumberAt("", 1)); } - @Test - public void testReplaceWithMultipleChars() { - assertEquals("faaaa", StringUtil.replaceString("foo", 'o', "aa")); - } - - @Test - public void testReplaceStringWithString() { - assertEquals("foo]]>bar", StringUtil.replaceString("foo]]>bar", "]]>", "]]>")); - } - - @Test - public void testReplaceStringWithString2() { - assertEquals("replaceString didn't work with a >", "foobar", - StringUtil.replaceString("foobar", "]]>", "]]>")); - } - - @Test - public void testReplaceWithNull() { - assertEquals("replaceString didn't work with a char", "f", StringUtil.replaceString("foo", 'o', null)); - } - @Test public void testUTF8NotSupported() { StringBuilder sb = new StringBuilder(); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentSizeRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentSizeRule.java index 4f27e3ee66..eeb80497cd 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentSizeRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentSizeRule.java @@ -5,9 +5,11 @@ package net.sourceforge.pmd.lang.java.rule.documentation; import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive; +import static net.sourceforge.pmd.util.CollectionUtil.setOf; import java.util.ArrayList; import java.util.List; +import java.util.Set; import org.apache.commons.lang3.StringUtils; @@ -36,6 +38,8 @@ public class CommentSizeRule extends AbstractCommentRule { private static final String CR = "\n"; + static final Set IGNORED_LINES = setOf("//", "/*", "/**", "*", "*/"); + public CommentSizeRule() { definePropertyDescriptor(MAX_LINES); definePropertyDescriptor(MAX_LINE_LENGTH); @@ -47,7 +51,7 @@ public class CommentSizeRule extends AbstractCommentRule { return false; } - return !StringUtil.isAnyOf(line.trim(), "//", "/*", "/**", "*", "*/"); + return !IGNORED_LINES.contains(line.trim()); } private boolean hasTooManyLines(Comment comment) { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/MoreThanOneLoggerRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/MoreThanOneLoggerRule.java index 4a12afe969..e45d885fd5 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/MoreThanOneLoggerRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/MoreThanOneLoggerRule.java @@ -17,7 +17,6 @@ import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator; import net.sourceforge.pmd.lang.java.ast.JavaNode; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; import net.sourceforge.pmd.lang.java.typeresolution.TypeHelper; -import net.sourceforge.pmd.util.NumericConstants; public class MoreThanOneLoggerRule extends AbstractJavaRule { @@ -47,7 +46,7 @@ public class MoreThanOneLoggerRule extends AbstractJavaRule { private Object init(JavaNode node, Object data) { stack.push(count); - count = NumericConstants.ZERO; + count = 0; node.children().forEach(it -> it.acceptVisitor(this, data)); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/DeclarationFinderFunction.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/DeclarationFinderFunction.java index b513294028..5d70064a45 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/DeclarationFinderFunction.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/DeclarationFinderFunction.java @@ -4,12 +4,13 @@ package net.sourceforge.pmd.lang.java.symboltable; +import java.util.function.Predicate; + import net.sourceforge.pmd.lang.java.ast.ASTMethodReference; import net.sourceforge.pmd.lang.symboltable.NameDeclaration; import net.sourceforge.pmd.lang.symboltable.NameOccurrence; -import net.sourceforge.pmd.util.SearchFunction; -public class DeclarationFinderFunction implements SearchFunction { +public class DeclarationFinderFunction implements Predicate { private NameOccurrence occurrence; private NameDeclaration decl; @@ -19,7 +20,7 @@ public class DeclarationFinderFunction implements SearchFunction tagList = new ArrayList<>(); public void openTag(ASTElement elm) { - if (elm == null || StringUtil.isEmpty(elm.getName())) { + if (elm == null || StringUtils.isBlank(elm.getName())) { throw new IllegalStateException("Tried to open a tag with empty name"); } @@ -40,7 +41,7 @@ class OpenTagRegister { * was ever opened ( or registered ) */ public boolean closeTag(String closingTagName) { - if (StringUtil.isEmpty(closingTagName)) { + if (StringUtils.isBlank(closingTagName)) { throw new IllegalStateException("Tried to close a tag with empty name"); } diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/NPathComplexityVisitor.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/NPathComplexityVisitor.java index 4ea35c76f7..f895ca4cdb 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/NPathComplexityVisitor.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/NPathComplexityVisitor.java @@ -27,7 +27,6 @@ import net.sourceforge.pmd.lang.plsql.ast.ASTWhileStatement; import net.sourceforge.pmd.lang.plsql.ast.ExecutableCode; import net.sourceforge.pmd.lang.plsql.ast.PLSQLNode; import net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitorAdapter; -import net.sourceforge.pmd.util.NumericConstants; /** * @author Clément Fournier @@ -220,7 +219,7 @@ class NPathComplexityVisitor extends PLSQLParserVisitorAdapter { ASTExpression expr = node.getFirstChildOfType(ASTExpression.class); if (expr == null) { - return NumericConstants.ONE; + return 1; } int boolCompReturn = NPathComplexityRule.sumExpressionComplexity(expr); @@ -233,7 +232,7 @@ class NPathComplexityVisitor extends PLSQLParserVisitorAdapter { if (boolCompReturn > 0) { return boolCompReturn; } - return NumericConstants.ONE; + return 1; } @Override @@ -278,7 +277,7 @@ class NPathComplexityVisitor extends PLSQLParserVisitorAdapter { @Override public Object visit(ASTConditionalOrExpression node, Object data) { - return NumericConstants.ONE; + return 1; } } diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/TooManyFieldsRule.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/TooManyFieldsRule.java index 094f47c3ef..30f7f1b0a9 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/TooManyFieldsRule.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/TooManyFieldsRule.java @@ -19,7 +19,6 @@ import net.sourceforge.pmd.lang.plsql.ast.PLSQLNode; import net.sourceforge.pmd.lang.plsql.rule.AbstractPLSQLRule; import net.sourceforge.pmd.properties.PropertyDescriptor; import net.sourceforge.pmd.properties.PropertyFactory; -import net.sourceforge.pmd.util.NumericConstants; public class TooManyFieldsRule extends AbstractPLSQLRule { @@ -91,7 +90,7 @@ public class TooManyFieldsRule extends AbstractPLSQLRule { private void bumpCounterFor(PLSQLNode clazz) { String key = clazz.getImage(); if (!stats.containsKey(key)) { - stats.put(key, NumericConstants.ZERO); + stats.put(key, 0); nodes.put(key, clazz); } Integer i = stats.get(key) + 1; diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/OpenTagRegister.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/OpenTagRegister.java index 910c21db2a..0c8eca2519 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/OpenTagRegister.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/OpenTagRegister.java @@ -7,8 +7,9 @@ package net.sourceforge.pmd.lang.vf.ast; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.StringUtils; + import net.sourceforge.pmd.annotation.InternalApi; -import net.sourceforge.pmd.util.StringUtil; /** * Utility class to keep track of unclosed tags. The mechanism is rather simple. @@ -26,7 +27,7 @@ class OpenTagRegister { private List tagList = new ArrayList<>(); public void openTag(ASTElement elm) { - if (elm == null || StringUtil.isEmpty(elm.getName())) { + if (elm == null || StringUtils.isBlank(elm.getName())) { throw new IllegalStateException("Tried to open a tag with empty name"); } @@ -40,7 +41,7 @@ class OpenTagRegister { * was ever opened ( or registered ) */ public boolean closeTag(String closingTagName) { - if (StringUtil.isEmpty(closingTagName)) { + if (StringUtils.isBlank(closingTagName)) { throw new IllegalStateException("Tried to close a tag with empty name"); }