Checkstyle

This commit is contained in:
Clément Fournier
2021-04-05 21:45:25 +02:00
parent 45fc45c809
commit fae74f43b3
3 changed files with 8 additions and 5 deletions

View File

@ -20,7 +20,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration;
/** /**
* Helper class to analyze {@link ASTImportDeclaration}s. * Helper class to analyze {@link ASTImportDeclaration}s.
*/ */
public class ImportWrapper { public final class ImportWrapper {
private static final Logger LOG = Logger.getLogger(ImportWrapper.class.getName()); private static final Logger LOG = Logger.getLogger(ImportWrapper.class.getName());
private final ASTImportDeclaration node; private final ASTImportDeclaration node;

View File

@ -228,7 +228,8 @@ public class UnusedImportsRule extends AbstractJavaRule {
private void removeReferenceSingleImport(String referenceName) { private void removeReferenceSingleImport(String referenceName) {
int firstDot = referenceName.indexOf('.'); int firstDot = referenceName.indexOf('.');
String expectedImport = firstDot < 0 ? referenceName : referenceName.substring(0, firstDot); String expectedImport = firstDot < 0 ? referenceName : referenceName.substring(0, firstDot);
for (Iterator<ImportWrapper> iterator = imports.iterator(); iterator.hasNext(); ) { Iterator<ImportWrapper> iterator = imports.iterator();
while (iterator.hasNext()) {
ImportWrapper anImport = iterator.next(); ImportWrapper anImport = iterator.next();
if (!anImport.isOnDemand() && anImport.getName().equals(expectedImport)) { if (!anImport.isOnDemand() && anImport.getName().equals(expectedImport)) {
iterator.remove(); iterator.remove();
@ -237,7 +238,8 @@ public class UnusedImportsRule extends AbstractJavaRule {
} }
private void removeOnDemandForPackageName(String fullName) { private void removeOnDemandForPackageName(String fullName) {
for (Iterator<ImportWrapper> iterator = imports.iterator(); iterator.hasNext(); ) { Iterator<ImportWrapper> iterator = imports.iterator();
while (iterator.hasNext()) {
ImportWrapper anImport = iterator.next(); ImportWrapper anImport = iterator.next();
if (anImport.isOnDemand() && anImport.getFullName().equals(fullName)) { if (anImport.isOnDemand() && anImport.getFullName().equals(fullName)) {
iterator.remove(); iterator.remove();

View File

@ -14,6 +14,7 @@ public class UnusedImportsTest extends PmdRuleTst {
System.out.println(message); System.out.println(message);
} }
} }
public static void assertSomething(String message, boolean condition) { public static void assertSomething(String message, boolean condition) {
if (!condition) { if (!condition) {
System.out.println(message); System.out.println(message);