Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ public class ReplaceDuplicateStringLiterals extends Recipe {
@Nullable
Boolean includeTestSources;

@Option(displayName = "Maximum length of the generate variable names",
description = "By default this is set to 100 characters",
required = false)
@Nullable
Integer maxVariableLength = 100;

@Override
public String getDisplayName() {
return "Replace duplicate `String` literals";
Expand All @@ -74,6 +68,8 @@ public Duration getEstimatedEffortPerOccurrence() {
return Duration.ofMinutes(2);
}

int maxVariableLength = 40;

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(new UsesType<>("java.lang.String", false), new JavaVisitor<ExecutionContext>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ class A {
"""
package org.foo;
class A {
private static final String THIS_IS_AN_UNREASONABLY_LONG_VARIABLE_NAME_IT_GOES_ON_AND_ON_FOR_AVERY_LONG_TIME_IT_MIGHT_NEVER_END = "ThisIsAnUnreasonablyLongVariableNameItGoesOnAndOnForAVeryLongTimeItMightNeverEndWhoIsToKnowHowLongItWillKeepGoingAndGoing";
final String val1 = THIS_IS_AN_UNREASONABLY_LONG_VARIABLE_NAME_IT_GOES_ON_AND_ON_FOR_AVERY_LONG_TIME_IT_MIGHT_NEVER_END;
final String val2 = THIS_IS_AN_UNREASONABLY_LONG_VARIABLE_NAME_IT_GOES_ON_AND_ON_FOR_AVERY_LONG_TIME_IT_MIGHT_NEVER_END;
final String val3 = THIS_IS_AN_UNREASONABLY_LONG_VARIABLE_NAME_IT_GOES_ON_AND_ON_FOR_AVERY_LONG_TIME_IT_MIGHT_NEVER_END;
private static final String THIS_IS_AN_UNREASONABLY_LONG_VARIABLE = "ThisIsAnUnreasonablyLongVariableNameItGoesOnAndOnForAVeryLongTimeItMightNeverEndWhoIsToKnowHowLongItWillKeepGoingAndGoing";
final String val1 = THIS_IS_AN_UNREASONABLY_LONG_VARIABLE;
final String val2 = THIS_IS_AN_UNREASONABLY_LONG_VARIABLE;
final String val3 = THIS_IS_AN_UNREASONABLY_LONG_VARIABLE;
}
"""
)
Expand Down Expand Up @@ -278,17 +278,17 @@ void transformStringValue() {
java(
"""
class A {
final String val1 = "An example,, of a :: String with `` special __ characters.";
final String val2 = "An example,, of a :: String with `` special __ characters.";
final String val3 = "An example,, of a :: String with `` special __ characters.";
final String val1 = "Example,, :: String with `` special __ characters.";
final String val2 = "Example,, :: String with `` special __ characters.";
final String val3 = "Example,, :: String with `` special __ characters.";
}
""",
"""
class A {
private static final String AN_EXAMPLE_OF_A_STRING_WITH_SPECIAL_CHARACTERS = "An example,, of a :: String with `` special __ characters.";
final String val1 = AN_EXAMPLE_OF_A_STRING_WITH_SPECIAL_CHARACTERS;
final String val2 = AN_EXAMPLE_OF_A_STRING_WITH_SPECIAL_CHARACTERS;
final String val3 = AN_EXAMPLE_OF_A_STRING_WITH_SPECIAL_CHARACTERS;
private static final String EXAMPLE_STRING_WITH_SPECIAL_CHARACTERS = "Example,, :: String with `` special __ characters.";
final String val1 = EXAMPLE_STRING_WITH_SPECIAL_CHARACTERS;
final String val2 = EXAMPLE_STRING_WITH_SPECIAL_CHARACTERS;
final String val3 = EXAMPLE_STRING_WITH_SPECIAL_CHARACTERS;
}
"""
)
Expand Down