Skip to content

Commit

Permalink
Polish NoEmptyCollectionWithRawType
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed May 7, 2024
1 parent c2fffaf commit bb0aadd
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
@Override
public J visitImport(J.Import anImport, ExecutionContext ctx) {
J.Identifier name = anImport.getQualid().getName();
if (anImport.isStatic() && name.getSimpleName().startsWith("EMPTY_") &&
if (anImport.isStatic() && updateFields.containsKey(name.getSimpleName()) &&
TypeUtils.isOfClassType(anImport.getQualid().getTarget().getType(), "java.util.Collections")) {
return anImport.withQualid(anImport.getQualid().withName(name.withSimpleName(updateFields.get(name.getSimpleName()))));
}
Expand All @@ -83,7 +83,7 @@ public J visitImport(J.Import anImport, ExecutionContext ctx) {
public J visitFieldAccess(J.FieldAccess fieldAccess, ExecutionContext ctx) {
J.Identifier name = fieldAccess.getName();
JavaType.Variable varType = name.getFieldType();
if (varType != null && varType.getName().startsWith("EMPTY_") &&
if (varType != null && updateFields.containsKey(varType.getName()) &&
TypeUtils.isOfClassType(varType.getOwner(), "java.util.Collections")) {
return JavaTemplate.builder("java.util.Collections." + updateFields.get(varType.getName()) + "()")
.contextSensitive() // context sensitive due to generics
Expand All @@ -97,7 +97,7 @@ public J visitFieldAccess(J.FieldAccess fieldAccess, ExecutionContext ctx) {
@Override
public J visitIdentifier(J.Identifier identifier, ExecutionContext ctx) {
JavaType.Variable varType = identifier.getFieldType();
if (varType != null && varType.getName().startsWith("EMPTY_") &&
if (varType != null && updateFields.containsKey(varType.getName()) &&
TypeUtils.isOfClassType(varType.getOwner(), "java.util.Collections")) {

return JavaTemplate.builder(updateFields.get(varType.getName()) + "()")
Expand Down

0 comments on commit bb0aadd

Please sign in to comment.