From 0514b249ad93daf4ab7421d740fd4e5a416d6ea1 Mon Sep 17 00:00:00 2001 From: sokomishalov Date: Sat, 29 May 2021 16:24:15 +0300 Subject: [PATCH] improve kotlin api generator to generate replacement for a deprecated method, typo fix --- .../async/RedisScriptingAsyncCommands.java | 2 +- .../api/async/RedisServerAsyncCommands.java | 4 ++-- .../RedisScriptingReactiveCommands.java | 2 +- .../reactive/RedisServerReactiveCommands.java | 4 ++-- .../core/api/sync/RedisScriptingCommands.java | 2 +- .../core/api/sync/RedisServerCommands.java | 4 ++-- .../NodeSelectionScriptingAsyncCommands.java | 2 +- .../NodeSelectionServerAsyncCommands.java | 4 ++-- .../sync/NodeSelectionScriptingCommands.java | 2 +- .../api/sync/NodeSelectionServerCommands.java | 4 ++-- .../RedisScriptingCoroutinesCommands.kt | 2 +- .../RedisServerCoroutinesCommands.kt | 8 +++---- .../core/api/RedisScriptingCommands.java | 2 +- .../lettuce/core/api/RedisServerCommands.java | 4 ++-- .../KotlinCompilationUnitFactory.java | 23 +++++++++++++++---- 15 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/main/java/io/lettuce/core/api/async/RedisScriptingAsyncCommands.java b/src/main/java/io/lettuce/core/api/async/RedisScriptingAsyncCommands.java index 159df0193d..1e1caaf476 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisScriptingAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisScriptingAsyncCommands.java @@ -124,7 +124,7 @@ public interface RedisScriptingAsyncCommands { /** * Remove all the scripts from the script cache using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java b/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java index a4a6f5a74e..2ab228e0fc 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java @@ -284,7 +284,7 @@ public interface RedisServerAsyncCommands { /** * Remove all keys from all databases using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ @@ -309,7 +309,7 @@ public interface RedisServerAsyncCommands { /** * Remove all keys from the current database using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/api/reactive/RedisScriptingReactiveCommands.java b/src/main/java/io/lettuce/core/api/reactive/RedisScriptingReactiveCommands.java index 603642d244..057b8639a3 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisScriptingReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisScriptingReactiveCommands.java @@ -123,7 +123,7 @@ public interface RedisScriptingReactiveCommands { /** * Remove all the scripts from the script cache using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java b/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java index 2367d0a31e..ef56d9638b 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java @@ -284,7 +284,7 @@ public interface RedisServerReactiveCommands { /** * Remove all keys from all databases using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ @@ -309,7 +309,7 @@ public interface RedisServerReactiveCommands { /** * Remove all keys from the current database using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/api/sync/RedisScriptingCommands.java b/src/main/java/io/lettuce/core/api/sync/RedisScriptingCommands.java index 685de0d5dd..a9e5dc60d9 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisScriptingCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisScriptingCommands.java @@ -123,7 +123,7 @@ public interface RedisScriptingCommands { /** * Remove all the scripts from the script cache using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java b/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java index 1e172461a9..7bc16d1322 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java @@ -283,7 +283,7 @@ public interface RedisServerCommands { /** * Remove all keys from all databases using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ @@ -308,7 +308,7 @@ public interface RedisServerCommands { /** * Remove all keys from the current database using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionScriptingAsyncCommands.java b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionScriptingAsyncCommands.java index 990a8b1063..2ab4e05873 100644 --- a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionScriptingAsyncCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionScriptingAsyncCommands.java @@ -123,7 +123,7 @@ public interface NodeSelectionScriptingAsyncCommands { /** * Remove all the scripts from the script cache using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java index 66db2120d0..d20b5e2da4 100644 --- a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java @@ -269,7 +269,7 @@ public interface NodeSelectionServerAsyncCommands { /** * Remove all keys from all databases using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ @@ -294,7 +294,7 @@ public interface NodeSelectionServerAsyncCommands { /** * Remove all keys from the current database using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionScriptingCommands.java b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionScriptingCommands.java index 95c0de2b9a..162879439c 100644 --- a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionScriptingCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionScriptingCommands.java @@ -123,7 +123,7 @@ public interface NodeSelectionScriptingCommands { /** * Remove all the scripts from the script cache using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java index 47daeb70a8..4cf691dc3b 100644 --- a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java @@ -269,7 +269,7 @@ public interface NodeSelectionServerCommands { /** * Remove all keys from all databases using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ @@ -294,7 +294,7 @@ public interface NodeSelectionServerCommands { /** * Remove all keys from the current database using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisScriptingCoroutinesCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisScriptingCoroutinesCommands.kt index 0202857bf2..e5cf614259 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisScriptingCoroutinesCommands.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisScriptingCoroutinesCommands.kt @@ -124,7 +124,7 @@ interface RedisScriptingCoroutinesCommands { /** * Remove all the scripts from the script cache using the specified [FlushMode]. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommands.kt index 3ea01cc1a7..36a50339a8 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommands.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommands.kt @@ -279,7 +279,7 @@ interface RedisServerCoroutinesCommands { /** * Remove all keys from all databases using the specified [FlushMode]. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ @@ -291,7 +291,7 @@ interface RedisServerCoroutinesCommands { * @return String simple-string-reply. * @deprecated since 6.1, use [flushall(FlushMode)] instead. */ - @Deprecated("since 6.1, use [flushall(FlushMode)] instead") + @Deprecated("Use [flushall(FlushMode.ASYNC)] instead.", ReplaceWith("flushall(FlushMode.ASYNC)")) suspend fun flushallAsync(): String? /** @@ -304,7 +304,7 @@ interface RedisServerCoroutinesCommands { /** * Remove all keys from the current database using the specified [FlushMode]. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ @@ -316,7 +316,7 @@ interface RedisServerCoroutinesCommands { * @return String simple-string-reply. * @deprecated since 6.1, use [flushdb(FlushMode)] instead. */ - @Deprecated("since 6.1, use [flushdb(FlushMode)] instead.") + @Deprecated("Use [flushdb(FlushMode.ASYNC)] instead.", ReplaceWith("flushdb(FlushMode.ASYNC)")) suspend fun flushdbAsync(): String? /** diff --git a/src/main/templates/io/lettuce/core/api/RedisScriptingCommands.java b/src/main/templates/io/lettuce/core/api/RedisScriptingCommands.java index cd70acee9a..18041e63cc 100644 --- a/src/main/templates/io/lettuce/core/api/RedisScriptingCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisScriptingCommands.java @@ -122,7 +122,7 @@ public interface RedisScriptingCommands { /** * Remove all the scripts from the script cache using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/templates/io/lettuce/core/api/RedisServerCommands.java b/src/main/templates/io/lettuce/core/api/RedisServerCommands.java index 8445d03854..7fb7e7173e 100644 --- a/src/main/templates/io/lettuce/core/api/RedisServerCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisServerCommands.java @@ -282,7 +282,7 @@ public interface RedisServerCommands { /** * Remove all keys from all databases using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ @@ -307,7 +307,7 @@ public interface RedisServerCommands { /** * Remove all keys from the current database using the specified {@link FlushMode}. * - * @param flushMode the flush mode (sync/asnync). + * @param flushMode the flush mode (sync/async). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java b/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java index 89e9704d1b..98f69fc453 100644 --- a/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java +++ b/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java @@ -60,8 +60,6 @@ class KotlinCompilationUnitFactory { private static final Set NON_SUSPENDABLE_METHODS = LettuceSets.unmodifiableSet("isOpen", "flushCommands", "setAutoFlushCommands"); private static final Set SKIP_METHODS = LettuceSets.unmodifiableSet("BaseRedisCommands.reset", "getStatefulConnection"); - private static final Set KEEP_DEPRECATED_METHODS = LettuceSets.unmodifiableSet("flushallAsync", "flushdbAsync"); - private static final Set FLOW_METHODS = LettuceSets.unmodifiableSet("aclList", "aclLog", "dispatch", "geohash", "georadius", "georadiusbymember", "geosearch", "hgetall", "hkeys", "hmget", "hvals", "keys", "mget", "sdiff", "sinter", "smembers", "smismember", "sort", "srandmember", "sunion", @@ -75,13 +73,20 @@ class KotlinCompilationUnitFactory { "RedisSentinelCoroutinesCommands.clientKill", "RedisSentinelCoroutinesCommands.clientPause", "RedisSentinelCoroutinesCommands.clientList", "RedisSentinelCoroutinesCommands.info", "RedisSentinelCoroutinesCommands.ping", "pubsubNumsub", "pubsubNumpat", "echo", "ping", "readOnly", "readWrite"); + private static final Map RESULT_SPEC; + private static final Map KEEP_DEPRECATED_METHODS; static { Map resultSpec = new HashMap<>(); resultSpec.put("hgetall", "Flow>"); resultSpec.put("zmscore", "List"); RESULT_SPEC = resultSpec; + + Map deprecatedMethodsSpec = new HashMap<>(); + deprecatedMethodsSpec.put("flushallAsync", "flushall(FlushMode.ASYNC)"); + deprecatedMethodsSpec.put("flushdbAsync", "flushdb(FlushMode.ASYNC)"); + KEEP_DEPRECATED_METHODS = deprecatedMethodsSpec; } private static final String FORMATTING_INDENT = " "; @@ -171,11 +176,12 @@ private class MethodVisitor extends VoidVisitorAdapter { public void visit(MethodDeclaration method, Object arg) { // Skip deprecated and StreamingChannel methods - if (!contains(KEEP_DEPRECATED_METHODS, method) && (method.isAnnotationPresent(Deprecated.class) + if (!contains(KEEP_DEPRECATED_METHODS.keySet(), method) && (method.isAnnotationPresent(Deprecated.class) || contains(SKIP_METHODS, method) || method.getParameters().stream().anyMatch(p -> p.getType().asString().contains("StreamingChannel")))) { return; } + result .append(FORMATTING_INDENT) .append(extractJavadoc(method.getJavadoc().get()).replace("\n", "\n" + FORMATTING_INDENT)) @@ -195,7 +201,16 @@ private String extractAnnotations(MethodDeclaration method) { return method .getAnnotations() .stream() - .map(a -> a.getNameAsString() + "\n" + FORMATTING_INDENT) + .map(a -> { + String annotation = a.getNameAsString(); + if (annotation.equals("Deprecated")) { + String identifier = method.getName().getIdentifier(); + String replacement = KEEP_DEPRECATED_METHODS.get(identifier); + return "@" + annotation + "(\"Use [" + replacement + "] instead.\", ReplaceWith(\"" + replacement + "\"))\n" + FORMATTING_INDENT; + } else { + return "@" + annotation + "\n" + FORMATTING_INDENT; + } + }) .collect(joining()); }