Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions MUTATORS_BY_TAG.generated.MD
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@
- [UseIndexOfChar](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseIndexOfChar.java)
- [UseUnderscoresInNumericLiterals](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseUnderscoresInNumericLiterals.java)

## Performance

- [AppendCharacterWithChar](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AppendCharacterWithChar.java)
- [AvoidFileStream](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidFileStream.java)
- [RemoveAllToClearCollection](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/RemoveAllToClearCollection.java)
- [StringToString](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringToString.java)
- [UseIndexOfChar](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseIndexOfChar.java)

## PitFall

- [SimplifyBooleanExpression](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/SimplifyBooleanExpression.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
* Copyright 2023-2025 Benoit Lacelle - SOLVEN
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,7 +43,7 @@ default boolean isDeprecationNotice() {
* @see UseCollectionIsEmpty
*/
// Relates to https://eslint.org/docs/user-guide/command-line-interface#--fix-type
default boolean isPerformanceImprovment() {
default boolean isPerformanceImprovement() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import eu.solven.cleanthat.engine.java.refactorer.AJavaparserExprMutator;
import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver;
import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers;
import eu.solven.cleanthat.engine.java.refactorer.meta.IMutatorDescriber;

/**
* Turns `stringBuilder.append("c")` into `stringBuilder.append('c')`
Expand All @@ -37,7 +38,7 @@
*
* @author Balazs Glatz
*/
public class AppendCharacterWithChar extends AJavaparserExprMutator {
public class AppendCharacterWithChar extends AJavaparserExprMutator implements IMutatorDescriber {

public static final String APOSTROPHE = "'";
public static final String METHOD_APPEND = "append";
Expand All @@ -47,9 +48,15 @@ public String minimalJavaVersion() {
return IJdkVersionConstants.JDK_5;
}

@Override
public boolean isPerformanceImprovement() {
// Avoids the extra indirection of creating or handling a String and uses the most direct, efficient overload.
return true;
}

@Override
public Set<String> getTags() {
return ImmutableSet.of("String");
return ImmutableSet.of("Performance", "String");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
* Copyright 2023-2025 Benoit Lacelle - SOLVEN
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,7 @@

import eu.solven.cleanthat.engine.java.IJdkVersionConstants;
import eu.solven.cleanthat.engine.java.refactorer.ATodoJavaParserMutator;
import eu.solven.cleanthat.engine.java.refactorer.meta.IMutatorDescriber;

/**
* Avoid use of {@link FileInputStream}, {@link FileOutputStream}, {@link FileReader} and {@link FileWriter}
Expand All @@ -34,15 +35,21 @@
*
*/
@Deprecated(since = "Not-ready")
public class AvoidFileStream extends ATodoJavaParserMutator {
public class AvoidFileStream extends ATodoJavaParserMutator implements IMutatorDescriber {

@Override
public String minimalJavaVersion() {
return IJdkVersionConstants.JDK_7;
}

@Override
public boolean isPerformanceImprovement() {
return true;
}

@Override
public Set<String> getTags() {
return ImmutableSet.of("NIO");
return ImmutableSet.of("NIO", "Performance");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
* Copyright 2023-2025 Benoit Lacelle - SOLVEN
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,23 +27,29 @@
import eu.solven.cleanthat.engine.java.refactorer.AJavaparserExprMutator;
import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver;
import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers;
import eu.solven.cleanthat.engine.java.refactorer.meta.IMutatorDescriber;

/**
* Turns 'c.removeAll(c)' into 'c.clear()' in Collection
*
* @author Benoit Lacelle
*/
public class RemoveAllToClearCollection extends AJavaparserExprMutator {
public class RemoveAllToClearCollection extends AJavaparserExprMutator implements IMutatorDescriber {

@Override
public String minimalJavaVersion() {
// Collection has been introduced in JDK2
return IJdkVersionConstants.JDK_2;
}

@Override
public boolean isPerformanceImprovement() {
return true;
}

@Override
public Set<String> getTags() {
return ImmutableSet.of("Collection");
return ImmutableSet.of("Collection", "Performance");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
* Copyright 2023-2025 Benoit Lacelle - SOLVEN
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,13 +26,15 @@
import eu.solven.cleanthat.engine.java.refactorer.AJavaparserExprMutator;
import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver;
import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers;
import eu.solven.cleanthat.engine.java.refactorer.meta.IMutatorDescriber;

/**
* Turns `"someString".toString()` into `"someString"`
*
* @author Benoit Lacelle
*/
public class StringToString extends AJavaparserExprMutator {
public class StringToString extends AJavaparserExprMutator implements IMutatorDescriber {

private static final String METHOD_TO_STRING = "toString";

@Override
Expand All @@ -45,9 +47,14 @@ public boolean isDraft() {
return IS_PRODUCTION_READY;
}

@Override
public boolean isPerformanceImprovement() {
return true;
}

@Override
public Set<String> getTags() {
return ImmutableSet.of("String");
return ImmutableSet.of("Performance", "String");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
* Copyright 2023-2025 Benoit Lacelle - SOLVEN
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,22 +29,28 @@
import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator;
import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver;
import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers;
import eu.solven.cleanthat.engine.java.refactorer.meta.IMutatorDescriber;

/**
* Turns 's.indexOf("s")’ into ’s.indexOf('s')'.
*
* @author Benoit Lacelle
*/
public class UseIndexOfChar extends AJavaparserNodeMutator {
public class UseIndexOfChar extends AJavaparserNodeMutator implements IMutatorDescriber {

@Override
public String minimalJavaVersion() {
return IJdkVersionConstants.JDK_1;
}

@Override
public boolean isPerformanceImprovement() {
return true;
}

@Override
public Set<String> getTags() {
return ImmutableSet.of("String");
return ImmutableSet.of("Performance", "String");
}

@Override
Expand Down