Skip to content

Commit

Permalink
#3156 = fix non-final fields, mark progress
Browse files Browse the repository at this point in the history
  • Loading branch information
coiouhkc committed Jun 11, 2023
1 parent 10b5c96 commit bb366ab
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@

/**
* TODO: Check the following criteria:
* - Lombok in dependencies
* - All methods of class are static
* - No instances of given class
* - All static attributes are final
* - Lombok in dependencies +
* - All methods of class are static +
* - No instances of given class +
* - All static attributes are final +
* <p>
* TODO: Perform the transformation:
* - Add the annotation
* - Remove static from all attributes and methods
* - Add the annotation +
* - Remove static from all attributes and methods +
* <p>
* TODO: Features to consider:
* - Transformation: Add Lombok config if not present + supported configuration options for utility class
* - Transformation: Replace instantiation with static calls to methods
* - Transformation: Replace instantiation with static calls to methods --> na
* - Anonymous classes ???
* - Reflection ???
*/
public class LombokUtilityClass extends Recipe {

Expand Down Expand Up @@ -145,7 +147,7 @@ public J.VariableDeclarations.NamedVariable visitVariable(
) {
if (variable.isField(getCursor())
&& variable.getVariableType() != null
&& !variable.getVariableType().hasFlags(Flag.Static)) {
&& !variable.getVariableType().hasFlags(Flag.Static, Flag.Final)) {
shouldPerformChanges.set(false);
}
return super.visitVariable(variable, shouldPerformChanges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ public class A {
);
}

@Test
void doNotChangeFieldIfNotFinal() {
rewriteRun(
recipeSpec -> recipeSpec
.recipe(new LombokUtilityClass()
),
java(
"""
public class A {
public static int C = 0;
}
"""
)
);
}

@Test
void happyPathMultiVariableField() {
rewriteRun(
Expand Down

0 comments on commit bb366ab

Please sign in to comment.