Skip to content

Commit a7959a4

Browse files
committed
fixed indentation and placement of new literal
1 parent 796ecc1 commit a7959a4

File tree

5 files changed

+28
-32
lines changed

5 files changed

+28
-32
lines changed

core-codemods/src/main/java/io/codemodder/codemods/CreateConstantForLiteral.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,12 @@ protected void defineConstant(final String constantName) {
7272
}
7373

7474
/**
75-
* Adds a {@link FieldDeclaration} as the first member of the provided {@link
76-
* ClassOrInterfaceDeclaration}
77-
*/
75+
* Adds a {@link FieldDeclaration} as the last member of the provided {@link
76+
* ClassOrInterfaceDeclaration}. Adding last seems like it would be <a href="https://github.com/pixee/codemodder-java/issues/288">preferred by users and better for JavaParser to match the existing indentation</a>.
77+
*/
7878
private void addConstantFieldToClass(final FieldDeclaration constantField) {
79-
80-
// TODO: Add the constant field to the end, and get better indent?
8179
final NodeList<BodyDeclaration<?>> members = classOrInterfaceDeclaration.getMembers();
82-
83-
members.addFirst(constantField);
80+
members.addLast(constantField);
8481
}
8582

8683
/** Creates a {@link FieldDeclaration} of {@link String} type with the constant name provided */

core-codemods/src/test/resources/define-constant-for-duplicate-literal-s1192/case-1/Test.java.after

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ import org.springframework.web.bind.annotation.RestController;
4949
})
5050
public class SqlInjectionLesson9 extends AssignmentEndpoint {
5151

52-
private static final String SPAN = "</span>";
53-
54-
private static final String BR_SPAN_CLASS_FEEDBACK_NEGATIVE = "<br><span class='feedback-negative'>";
55-
56-
private static final String PRINTLN = "1 2 3...";
57-
5852
private final LessonDataSource dataSource;
5953
private static final String UTF8 = "UTF-8";
6054

@@ -136,4 +130,10 @@ private static final String PRINTLN = "1 2 3...";
136130
.build();
137131
}
138132
}
133+
134+
private static final String PRINTLN = "1 2 3...";
135+
136+
private static final String BR_SPAN_CLASS_FEEDBACK_NEGATIVE = "<br><span class='feedback-negative'>";
137+
138+
private static final String SPAN = "</span>";
139139
}

core-codemods/src/test/resources/define-constant-for-duplicate-literal-s1192/case-2/Test.java.after

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ import org.springframework.web.bind.annotation.RestController;
3838
@AssignmentHints({"idor.hints.idor_login"})
3939
public class IDORLogin extends AssignmentEndpoint {
4040

41-
private static final String password1 = "password";
42-
4341
private Map<String, Map<String, String>> idorUserInfo = new HashMap<>();
4442

4543
private static final String password = "collision and snake case";
@@ -78,4 +76,6 @@ public class IDORLogin extends AssignmentEndpoint {
7876
return failed(this).feedback("idor.login.failure").build();
7977
}
8078
}
79+
80+
private static final String password1 = "password";
8181
}

core-codemods/src/test/resources/define-constant-for-duplicate-literal-s1192/case-3/Test.java.after

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ import software.amazon.awssdk.utils.ImmutableMap;
4343

4444
public class PartitionMetadataGenerator implements PoetClass {
4545

46-
private static final String BUILD = ".build()";
47-
48-
private static final String S = ", $S)";
49-
50-
private static final String PUT = ".put(";
51-
5246
private final Partition partition;
5347
private final String basePackage;
5448
private final String regionBasePackage;
@@ -208,4 +202,10 @@ private static final String PUT = ".put(";
208202
private ClassName partitionEndpointKeyClass() {
209203
return ClassName.get(regionBasePackage, "PartitionEndpointKey");
210204
}
205+
206+
private static final String PUT = ".put(";
207+
208+
private static final String S = ", $S)";
209+
210+
private static final String BUILD = ".build()";
211211
}

core-codemods/src/test/resources/define-constant-for-duplicate-literal-s1192/case-5/Test.java.after

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ import software.amazon.awssdk.core.waiters.WaiterOverrideConfiguration;
2525

2626
public final class WaiterDocs {
2727

28-
private static final String A_REFERENCE_TO_THIS_OBJECT_SO_THAT_METHOD_CALLS_CAN_BE_CHAINED_TOGETHER = "a reference to this object so that method calls can be chained together.";
29-
30-
private static final String FOR_POLLING = " for polling";
31-
32-
private static final String OR_UNTIL_IT_IS_DETERMINED_THAT_THE_RESOURCE_WILL_NEVER = "or until it is determined that the resource will never ";
33-
34-
private static final String CODE_N_IS_MET = "{@code $N} is met, ";
35-
36-
private static final String POLLS_LINK_T_N_API_UNTIL_THE_DESIRED_CONDITION = "Polls {@link $T#$N} API until the desired condition ";
37-
3828
private WaiterDocs() {
3929
}
4030

@@ -246,5 +236,14 @@ private static final String POLLS_LINK_T_N_API_UNTIL_THE_DESIRED_CONDITION = "Po
246236
.add(javadocs, waiterClassName, waiterClassName)
247237
.build();
248238
}
249-
239+
240+
private static final String POLLS_LINK_T_N_API_UNTIL_THE_DESIRED_CONDITION = "Polls {@link $T#$N} API until the desired condition ";
241+
242+
private static final String CODE_N_IS_MET = "{@code $N} is met, ";
243+
244+
private static final String OR_UNTIL_IT_IS_DETERMINED_THAT_THE_RESOURCE_WILL_NEVER = "or until it is determined that the resource will never ";
245+
246+
private static final String FOR_POLLING = " for polling";
247+
248+
private static final String A_REFERENCE_TO_THIS_OBJECT_SO_THAT_METHOD_CALLS_CAN_BE_CHAINED_TOGETHER = "a reference to this object so that method calls can be chained together.";
250249
}

0 commit comments

Comments
 (0)