Fixed #3954 missing reporting of issue on records.
This commit is contained in:
@ -115,7 +115,13 @@ public class UseCollectionIsEmptyRule extends AbstractInefficientZeroCheck {
|
||||
classOrEnumBody = expr.getFirstParentOfType(ASTEnumBody.class);
|
||||
}
|
||||
if (classOrEnumBody == null) {
|
||||
classOrEnumBody = expr.getFirstParentOfType(ASTRecordBody.class);
|
||||
classOrEnumBody = expr.getFirstParentOfType(ASTRecordDeclaration.class);
|
||||
List<ASTVariableDeclaratorId> descendantsOfType = classOrEnumBody.findDescendantsOfType(ASTVariableDeclaratorId.class);
|
||||
for (ASTVariableDeclaratorId variableDeclaratorId : descendantsOfType) {
|
||||
if (variableDeclaratorId.getName().equals(varName)) {
|
||||
return variableDeclaratorId.getTypeNode().getTypeDefinition();
|
||||
}
|
||||
}
|
||||
}
|
||||
List<ASTVariableDeclarator> varDeclarators = classOrEnumBody.findDescendantsOfType(ASTVariableDeclarator.class);
|
||||
for (ASTVariableDeclarator varDeclarator : varDeclarators) {
|
||||
|
@ -500,6 +500,20 @@ public record Record(Set<String> stringSet) {
|
||||
public boolean hasMoreThanOneItem() {
|
||||
return this.stringSet.size() > 1;
|
||||
}
|
||||
} ]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>With records and size check</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>6</expected-linenumbers>
|
||||
<code><![CDATA[
|
||||
import java.util.Set;
|
||||
|
||||
public record Record(Set<String> stringSet) {
|
||||
|
||||
public boolean hasMoreThanOneItem() {
|
||||
return this.stringSet.size() == 0;
|
||||
}
|
||||
} ]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
Reference in New Issue
Block a user