Skip to content

Commit 2a0f017

Browse files
authored
Do not use nested recipes where visitors suffice (#837)
1 parent 33ddf3b commit 2a0f017

File tree

2 files changed

+11
-68
lines changed

2 files changed

+11
-68
lines changed

src/main/java/org/openrewrite/java/spring/amqp/UseTlsAmqpConnectionString.java

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@ public class UseTlsAmqpConnectionString extends Recipe {
5454
@Nullable
5555
String propertyKey;
5656

57-
@Option(displayName = "Old Port",
57+
@Option(displayName = "Old port",
5858
description = "The non-TLS enabled port number to replace with the TLS-enabled port. " +
5959
"If this value is specified, no changes will be made to amqp connection strings which do not contain this port number. ",
6060
example = "1234")
6161
@Nullable
6262
Integer oldPort;
6363

64-
@Option(displayName = "TLS Port",
64+
@Option(displayName = "TLS port",
6565
description = "The TLS-enabled port to use.",
6666
example = "1234")
6767
@Nullable
6868
Integer port;
6969

70-
@Option(displayName = "TLS Property Key",
70+
@Option(displayName = "TLS property key",
7171
description = "The Spring property key to enable default TLS mode against. " +
7272
"If this value is specified, the specified property will be used when updating the default TLS mode, otherwise a default of " +
7373
"`spring.rabbitmq.ssl.enabled` will be used instead.",
@@ -139,7 +139,7 @@ private boolean sourcePathMatches(Path sourcePath, ExecutionContext ctx) {
139139

140140
@EqualsAndHashCode(callSuper = false)
141141
@Value
142-
static class UseTlsAmqpConnectionStringYaml extends Recipe {
142+
static class UseTlsAmqpConnectionStringYaml {
143143
String propertyKey;
144144

145145
@Nullable
@@ -153,17 +153,6 @@ static class UseTlsAmqpConnectionStringYaml extends Recipe {
153153
@Nullable
154154
List<String> pathExpressions;
155155

156-
@Override
157-
public String getDisplayName() {
158-
return "Use TLS for AMQP connection strings";
159-
}
160-
161-
@Override
162-
public String getDescription() {
163-
return "Use TLS for AMQP connection strings.";
164-
}
165-
166-
@Override
167156
public TreeVisitor<?, ExecutionContext> getVisitor() {
168157
return Preconditions.check(new YamlVisitor<ExecutionContext>() {
169158
@Override
@@ -225,7 +214,7 @@ public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionC
225214
}
226215

227216
if (updated) {
228-
e = e.withValue(((Yaml.Scalar) e.getValue()).withValue(join(connectionStrings, ",")));
217+
e = e.withValue(((Yaml.Scalar) e.getValue()).withValue(String.join(",", connectionStrings)));
229218
}
230219
} catch (URISyntaxException | IllegalArgumentException ignored) {
231220
// do nothing
@@ -239,7 +228,7 @@ public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionC
239228

240229
@EqualsAndHashCode(callSuper = false)
241230
@Value
242-
static class UseTlsAmqpConnectionStringProperties extends Recipe {
231+
static class UseTlsAmqpConnectionStringProperties {
243232
String propertyKey;
244233

245234
@Nullable
@@ -253,17 +242,6 @@ static class UseTlsAmqpConnectionStringProperties extends Recipe {
253242
@Nullable
254243
List<String> pathExpressions;
255244

256-
@Override
257-
public String getDisplayName() {
258-
return "Use TLS for AMQP connection strings";
259-
}
260-
261-
@Override
262-
public String getDescription() {
263-
return "Use TLS for AMQP connection strings.";
264-
}
265-
266-
@Override
267245
public TreeVisitor<?, ExecutionContext> getVisitor() {
268246
return Preconditions.check(new PropertiesVisitor<ExecutionContext>() {
269247
@Override
@@ -323,7 +301,7 @@ public Properties.Entry visitEntry(Properties.Entry entry, ExecutionContext ctx)
323301
}
324302

325303
if (updated) {
326-
e = e.withValue(e.getValue().withText(join(connectionStrings, ",")));
304+
e = e.withValue(e.getValue().withText(String.join(",", connectionStrings)));
327305
}
328306
} catch (URISyntaxException | IllegalArgumentException ignored) {
329307
// do nothing
@@ -354,17 +332,4 @@ private static String maybeUpdateAmqpConnectionString(String amqpUrl, @Nullable
354332
}
355333
return updatedAmqpUrl;
356334
}
357-
358-
private static String join(String[] strings, String separator) {
359-
if (strings.length == 0) {
360-
return "";
361-
}
362-
363-
StringBuilder builder = new StringBuilder();
364-
int idx = 0;
365-
while (idx < strings.length - 1) {
366-
builder.append(strings[idx++]).append(separator);
367-
}
368-
return builder.append(strings[idx]).toString();
369-
}
370335
}

src/main/java/org/openrewrite/java/spring/data/UseTlsJdbcConnectionString.java

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public class UseTlsJdbcConnectionString extends Recipe {
4848
String propertyKey;
4949

5050
@Option(
51-
displayName = "Old Port",
51+
displayName = "Old port",
5252
description = "The non-TLS enabled port number to replace with the TLS-enabled port. " +
5353
"If this value is specified, no changes will be made to jdbc connection strings which do not contain this port number. ",
5454
example = "1234")
5555
@Nullable
5656
Integer oldPort;
5757

5858
@Option(
59-
displayName = "TLS Port",
59+
displayName = "TLS port",
6060
description = "The TLS-enabled port to use.",
6161
example = "1234")
6262
@Nullable
@@ -111,7 +111,7 @@ public Tree preVisit(Tree tree, ExecutionContext ctx) {
111111

112112
@EqualsAndHashCode(callSuper = false)
113113
@Value
114-
static class UseTlsJdbcConnectionStringYaml extends Recipe {
114+
static class UseTlsJdbcConnectionStringYaml {
115115
String propertyKey;
116116

117117
@Nullable
@@ -123,16 +123,6 @@ static class UseTlsJdbcConnectionStringYaml extends Recipe {
123123
@Nullable
124124
String attribute;
125125

126-
@Override
127-
public String getDisplayName() {
128-
return "Use TLS for JDBC connection strings";
129-
}
130-
131-
@Override
132-
public String getDescription() {
133-
return "Use TLS for JDBC connection strings.";
134-
}
135-
136126
private TreeVisitor<?, ExecutionContext> precondition() {
137127
return new YamlVisitor<ExecutionContext>() {
138128
@Override
@@ -145,7 +135,6 @@ public Yaml visitDocuments(Yaml.Documents documents, ExecutionContext ctx) {
145135
};
146136
}
147137

148-
@Override
149138
public TreeVisitor<?, ExecutionContext> getVisitor() {
150139
return Preconditions.check(precondition(), new YamlIsoVisitor<ExecutionContext>() {
151140
final JsonPathMatcher jdbcUrl = new JsonPathMatcher("$." + propertyKey);
@@ -178,7 +167,7 @@ public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionC
178167

179168
@EqualsAndHashCode(callSuper = false)
180169
@Value
181-
static class UseTlsJdbcConnectionStringProperties extends Recipe {
170+
static class UseTlsJdbcConnectionStringProperties {
182171
String propertyKey;
183172

184173
@Nullable
@@ -190,16 +179,6 @@ static class UseTlsJdbcConnectionStringProperties extends Recipe {
190179
@Nullable
191180
String attribute;
192181

193-
@Override
194-
public String getDisplayName() {
195-
return "Use TLS for JDBC connection strings";
196-
}
197-
198-
@Override
199-
public String getDescription() {
200-
return "Use TLS for JDBC connection strings.";
201-
}
202-
203182
private TreeVisitor<?, ExecutionContext> precondition() {
204183
return new PropertiesVisitor<ExecutionContext>() {
205184
@Override
@@ -212,7 +191,6 @@ public Properties visitFile(Properties.File file, ExecutionContext ctx) {
212191
};
213192
}
214193

215-
@Override
216194
public TreeVisitor<?, ExecutionContext> getVisitor() {
217195
return Preconditions.check(precondition(), new PropertiesIsoVisitor<ExecutionContext>() {
218196
@Override

0 commit comments

Comments
 (0)