Skip to content

Commit

Permalink
Merge pull request #375 from openrewrite/set-max-variable-length-to-40
Browse files Browse the repository at this point in the history
Setting the maximum generated variable length to 40
  • Loading branch information
lkerford authored Oct 22, 2024
2 parents d24228b + 4dc9f45 commit 619b623
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
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

0 comments on commit 619b623

Please sign in to comment.