From 69d0d4f3b532478fce336ef4ef7c000af6b13df6 Mon Sep 17 00:00:00 2001 From: tangcent Date: Tue, 24 Mar 2020 19:19:33 +0800 Subject: [PATCH 1/7] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 217cff14a..690d8760e 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ ## Feature - [Export API Doc To`Postman`](https://easyapi.itangcent.com/documents/export2postman.html) - [Export API Doc To`Markdown`](https://easyapi.itangcent.com/documents/export2markdown.html) -- [Export RPC Doc To`Markdown`](https://easyapi.itangcent.com/documents/export_rpc.html) +- [Export RPC Doc To`RPC`](https://easyapi.itangcent.com/documents/export_rpc.html) - Api DashBoard ## Navigation From a6bfe51382aed58f5e8573a78b124523698b6c14 Mon Sep 17 00:00:00 2001 From: tangcent Date: Fri, 27 Mar 2020 21:57:54 +0800 Subject: [PATCH 2/7] chore: use `notNullOr*` instead of `!isNullOr*` --- .../com/itangcent/common/kit/KVUtils.kt | 7 ++--- .../com/itangcent/common/kit/KitUtils.kt | 16 ++++++++++++ .../com/itangcent/http/ApacheHttpClient.kt | 5 ++-- .../kotlin/com/itangcent/http/RequestUtils.kt | 5 ++-- .../plugin/api/DefaultMethodInferHelper.kt | 6 ++--- .../api/cache/CachedRequestClassExporter.kt | 3 ++- .../export/AbstractRequestClassExporter.kt | 26 ++++++++----------- .../idea/plugin/api/export/CommentResolver.kt | 18 +++++++------ .../plugin/api/export/DefaultLinkResolver.kt | 3 ++- .../export/DefaultMethodDocClassExporter.kt | 13 +++++----- .../api/export/SpringRequestClassExporter.kt | 5 ++-- .../api/export/markdown/MarkdownFormatter.kt | 22 +++++++++------- .../export/postman/DefaultPostmanApiHelper.kt | 5 ++-- .../api/export/postman/PostmanApiExporter.kt | 5 ++-- .../export/postman/PostmanCachedApiHelper.kt | 3 ++- .../api/export/postman/PostmanFormatter.kt | 3 ++- .../plugin/api/export/suv/SuvApiExporter.kt | 5 ++-- .../plugin/config/RecommendConfigReader.kt | 5 ++-- .../idea/plugin/dialog/ApiCallDialog.kt | 8 +++--- .../idea/plugin/dialog/EasyApiSettingGUI.kt | 8 +++--- .../idea/plugin/dialog/SuvApiExportDialog.kt | 3 ++- .../com/itangcent/idea/utils/ModuleHelper.kt | 3 ++- .../com/itangcent/intellij/extend/GsonKit.kt | 2 -- 23 files changed, 104 insertions(+), 75 deletions(-) diff --git a/common-api/src/main/kotlin/com/itangcent/common/kit/KVUtils.kt b/common-api/src/main/kotlin/com/itangcent/common/kit/KVUtils.kt index 8b6f56735..e3c4de558 100644 --- a/common-api/src/main/kotlin/com/itangcent/common/kit/KVUtils.kt +++ b/common-api/src/main/kotlin/com/itangcent/common/kit/KVUtils.kt @@ -1,10 +1,7 @@ package com.itangcent.common.kit import com.itangcent.common.constant.Attrs -import com.itangcent.common.utils.KV -import com.itangcent.common.utils.isNullOrBlank -import com.itangcent.common.utils.isNullOrEmpty -import com.itangcent.common.utils.joinToString +import com.itangcent.common.utils.* import java.util.* import kotlin.collections.ArrayList @@ -25,7 +22,7 @@ object KVUtils { val optionList = options as List> val optionDesc = getOptionDesc(optionList) - if (!optionDesc.isNullOrBlank()) { + if (optionDesc.notNullOrEmpty()) { desc = if (desc.isNullOrBlank()) { optionDesc } else { diff --git a/common-api/src/main/kotlin/com/itangcent/common/kit/KitUtils.kt b/common-api/src/main/kotlin/com/itangcent/common/kit/KitUtils.kt index d1e4ee8c1..8d813c0fc 100644 --- a/common-api/src/main/kotlin/com/itangcent/common/kit/KitUtils.kt +++ b/common-api/src/main/kotlin/com/itangcent/common/kit/KitUtils.kt @@ -1,6 +1,7 @@ package com.itangcent.common.kit import com.itangcent.common.utils.GsonUtils +import com.itangcent.common.utils.isNullOrBlank object KitUtils { @@ -65,3 +66,18 @@ fun String?.equalIgnoreCase(str: String?): Boolean { return this.toLowerCase() == str.toLowerCase() } +fun String?.notNullOrBlank(): Boolean { + return !this.isNullOrBlank() +} + +fun Array<*>?.notNullOrEmpty(): Boolean { + return !this.isNullOrEmpty() +} + +fun Collection<*>?.notNullOrEmpty(): Boolean { + return !this.isNullOrEmpty() +} + +fun Map<*, *>?.notNullOrEmpty(): Boolean { + return !this.isNullOrEmpty() +} \ No newline at end of file diff --git a/common-api/src/main/kotlin/com/itangcent/http/ApacheHttpClient.kt b/common-api/src/main/kotlin/com/itangcent/http/ApacheHttpClient.kt index a58fcf7fb..a1b986bc7 100644 --- a/common-api/src/main/kotlin/com/itangcent/http/ApacheHttpClient.kt +++ b/common-api/src/main/kotlin/com/itangcent/http/ApacheHttpClient.kt @@ -2,8 +2,9 @@ package com.itangcent.http import com.itangcent.annotation.script.ScriptIgnore import com.itangcent.annotation.script.ScriptTypeName -import com.itangcent.common.utils.append +import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.kit.toJson +import com.itangcent.common.utils.append import org.apache.http.HttpEntity import org.apache.http.NameValuePair import org.apache.http.client.config.RequestConfig @@ -81,7 +82,7 @@ open class ApacheHttpClient : HttpClient { if (request.method().toUpperCase() != "GET") { var requestEntity: HttpEntity? = null - if (!request.params().isNullOrEmpty()) { + if (request.params().notNullOrEmpty()) { if (request.contentType()?.startsWith("application/x-www-form-urlencoded") != true) { if (request.contentType()?.startsWith("multipart/form-data") == true) { diff --git a/common-api/src/main/kotlin/com/itangcent/http/RequestUtils.kt b/common-api/src/main/kotlin/com/itangcent/http/RequestUtils.kt index 4a9dbef66..6b75a095f 100644 --- a/common-api/src/main/kotlin/com/itangcent/http/RequestUtils.kt +++ b/common-api/src/main/kotlin/com/itangcent/http/RequestUtils.kt @@ -2,6 +2,7 @@ package com.itangcent.http import com.itangcent.common.constant.Attrs import com.itangcent.common.kit.mutable +import com.itangcent.common.kit.notNullOrBlank import com.itangcent.common.utils.GsonUtils import com.itangcent.common.utils.append import com.itangcent.common.utils.mapToTypedArray @@ -105,11 +106,11 @@ object RequestUtils { .append(this.protocol ?: "http") .append("://") .append(host!!.removeSuffix("?/")) - if (!path.isNullOrBlank()) { + if (path.notNullOrBlank()) { sb.append("/") sb.append(path!!.removePrefix("/").removeSuffix("?")) } - if (!query.isNullOrBlank()) { + if (query.notNullOrBlank()) { sb.append("?") sb.append(query!!.removePrefix("?")) } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/DefaultMethodInferHelper.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/DefaultMethodInferHelper.kt index 36b1ec484..059a92c54 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/DefaultMethodInferHelper.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/DefaultMethodInferHelper.kt @@ -6,7 +6,7 @@ import com.intellij.lang.jvm.JvmModifier import com.intellij.psi.* import com.intellij.psi.util.* import com.itangcent.common.kit.KVUtils -import com.itangcent.common.utils.mapToTypedArray +import com.itangcent.common.kit.notNullOrBlank import com.itangcent.common.logger.traceError import com.itangcent.common.utils.* import com.itangcent.idea.plugin.settings.SettingBinder @@ -277,7 +277,7 @@ class DefaultMethodInferHelper : MethodInferHelper { valueOf(args[0])?.let { asMap(realCaller)?.put(it, valueOf(args[1])) val attr = findAttrFromContext(context) - if (!attr.isNullOrBlank()) { + if (attr.notNullOrBlank()) { KVUtils.addComment(asMap(realCaller)!!, it, attr) } } @@ -437,7 +437,7 @@ class DefaultMethodInferHelper : MethodInferHelper { if (context == null) return null var comment = findNextEndOfLineComment(context) - if (!comment.isNullOrBlank()) return comment + if (comment.notNullOrBlank()) return comment comment = findPreLineEndOfLineComment(context) return comment } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/cache/CachedRequestClassExporter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/cache/CachedRequestClassExporter.kt index a82b42535..074159b0c 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/cache/CachedRequestClassExporter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/cache/CachedRequestClassExporter.kt @@ -5,6 +5,7 @@ import com.google.inject.name.Named import com.intellij.psi.PsiClass import com.intellij.psi.PsiElement import com.itangcent.common.exception.ProcessCanceledException +import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.logger.traceError import com.itangcent.common.model.Request import com.itangcent.idea.plugin.StatusRecorder @@ -94,7 +95,7 @@ class CachedRequestClassExporter : ClassExporter, Worker { && fileApiCache.lastModified!! > FileUtils.getLastModified(psiFile) ?: System.currentTimeMillis() && fileApiCache.md5 == md5) { - if (!fileApiCache.requests.isNullOrEmpty()) { + if (fileApiCache.requests.notNullOrEmpty()) { statusRecorder.newWork() actionContext.runInReadUI { try { diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/AbstractRequestClassExporter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/AbstractRequestClassExporter.kt index 889bd0fbe..239acd14d 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/AbstractRequestClassExporter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/AbstractRequestClassExporter.kt @@ -3,14 +3,10 @@ package com.itangcent.idea.plugin.api.export import com.google.inject.Inject import com.intellij.lang.jvm.JvmModifier import com.intellij.psi.* -import com.intellij.util.containers.isNullOrEmpty import com.itangcent.common.constant.Attrs import com.itangcent.common.constant.HttpMethod import com.itangcent.common.exception.ProcessCanceledException -import com.itangcent.common.kit.KVUtils -import com.itangcent.common.kit.KitUtils -import com.itangcent.common.kit.getAs -import com.itangcent.common.kit.getAsKv +import com.itangcent.common.kit.* import com.itangcent.common.logger.traceError import com.itangcent.common.model.* import com.itangcent.common.utils.* @@ -200,7 +196,7 @@ abstract class AbstractRequestClassExporter : ClassExporter, Worker { //parse additionalHeader by config val additionalHeader = ruleComputer!!.computer(ClassExportRuleKeys.METHOD_ADDITIONAL_HEADER, method) - if (!additionalHeader.isNullOrEmpty()) { + if (additionalHeader.notNullOrEmpty()) { val additionalHeaders = additionalHeader!!.lines() for (headerStr in additionalHeaders) { cacheAble!!.cache("header" to headerStr) { @@ -224,7 +220,7 @@ abstract class AbstractRequestClassExporter : ClassExporter, Worker { //parse additionalParam by config val additionalParam = ruleComputer.computer(ClassExportRuleKeys.METHOD_ADDITIONAL_PARAM, method) - if (!additionalParam.isNullOrEmpty()) { + if (additionalParam.notNullOrEmpty()) { val additionalParams = additionalParam!!.lines() for (paramStr in additionalParams) { cacheAble!!.cache("param" to paramStr) { @@ -247,10 +243,10 @@ abstract class AbstractRequestClassExporter : ClassExporter, Worker { } //parse additionalResponseHeader by config - if (!request.response.isNullOrEmpty()) { + if (request.response.notNullOrEmpty()) { val additionalResponseHeader = ruleComputer.computer(ClassExportRuleKeys.METHOD_ADDITIONAL_RESPONSE_HEADER, method) - if (!additionalResponseHeader.isNullOrEmpty()) { + if (additionalResponseHeader.notNullOrEmpty()) { val additionalHeaders = additionalResponseHeader!!.lines() for (headerStr in additionalHeaders) { cacheAble!!.cache("header" to headerStr) { @@ -281,7 +277,7 @@ abstract class AbstractRequestClassExporter : ClassExporter, Worker { var returnType: DuckType? = null var fromRule = false val returnTypeByRule = ruleComputer!!.computer(ClassExportRuleKeys.METHOD_RETURN, method) - if (!returnTypeByRule.isNullOrBlank()) { + if (returnTypeByRule.notNullOrBlank()) { val resolvedReturnType = duckTypeHelper!!.resolve(returnTypeByRule!!.trim(), method.psi()) if (resolvedReturnType != null) { returnType = resolvedReturnType @@ -301,7 +297,7 @@ abstract class AbstractRequestClassExporter : ClassExporter, Worker { val typedResponse = parseResponseBody(returnType, fromRule, method) val descOfReturn = docHelper!!.findDocByTag(method.psi(), "return") - if (!descOfReturn.isNullOrBlank()) { + if (descOfReturn.notNullOrBlank()) { val methodReturnMain = ruleComputer.computer(ClassExportRuleKeys.METHOD_RETURN_MAIN, method) if (methodReturnMain.isNullOrBlank()) { requestHelper.appendResponseBodyDesc(response, descOfReturn) @@ -340,12 +336,12 @@ abstract class AbstractRequestClassExporter : ClassExporter, Worker { } }) - if (!comment.isNullOrBlank()) { + if (comment.notNullOrBlank()) { if (!KVUtils.addKeyComment(typedResponse, methodReturnMain!!, comment!!)) { requestHelper.appendResponseBodyDesc(response, comment) } } - if (!options.isNullOrEmpty()) { + if (options.notNullOrEmpty()) { if (!KVUtils.addKeyOptions(typedResponse, methodReturnMain!!, options)) { requestHelper.appendResponseBodyDesc(response, KVUtils.getOptionDesc(options)) } @@ -399,7 +395,7 @@ abstract class AbstractRequestClassExporter : ClassExporter, Worker { val name: String = entry.key val value: String? = entry.value if (methodParamComment == null) methodParamComment = KV.create() - if (!value.isNullOrBlank()) { + if (value.notNullOrBlank()) { val options: ArrayList> = ArrayList() val comment = linkExtractor!!.extract(value, psiMethod, object : AbstractLinkResolve() { @@ -436,7 +432,7 @@ abstract class AbstractRequestClassExporter : ClassExporter, Worker { }) methodParamComment!![name] = comment ?: "" - if (!options.isNullOrEmpty()) { + if (options.notNullOrEmpty()) { methodParamComment!!["$name@options"] = options } } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/CommentResolver.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/CommentResolver.kt index 92499a770..df8cc971b 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/CommentResolver.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/CommentResolver.kt @@ -5,6 +5,8 @@ import com.google.inject.Singleton import com.intellij.psi.PsiElement import com.intellij.psi.PsiType import com.itangcent.common.kit.KVUtils +import com.itangcent.common.kit.notNullOrBlank +import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.intellij.config.rule.RuleComputer import com.itangcent.intellij.jvm.DuckTypeHelper import com.itangcent.intellij.jvm.JvmClassHelper @@ -53,11 +55,11 @@ class CommentResolver { val convertTo = ruleComputer!!.computer(ClassRuleKeys.ENUM_CONVERT, duckType, context) - if (!convertTo.isNullOrBlank()) { - if (convertTo.contains("#")) { + if (convertTo.notNullOrBlank()) { + if (convertTo!!.contains("#")) { val options = psiClassHelper!!.resolveEnumOrStatic(convertTo, context, "") - if (!options.isNullOrEmpty()) { - return KVUtils.getOptionDesc(options) + if (options.notNullOrEmpty()) { + return KVUtils.getOptionDesc(options!!) } } else { val resolveClass = duckTypeHelper!!.resolveClass(convertTo, context) @@ -97,11 +99,11 @@ class CommentResolver { val convertTo = ruleComputer!!.computer(ClassRuleKeys.ENUM_CONVERT, psiType, context) - if (!convertTo.isNullOrBlank()) { - if (convertTo.contains("#")) { + if (convertTo.notNullOrBlank()) { + if (convertTo!!.contains("#")) { val options = psiClassHelper!!.resolveEnumOrStatic(convertTo, context, "") - if (!options.isNullOrEmpty()) { - return KVUtils.getOptionDesc(options) + if (options.notNullOrEmpty()) { + return KVUtils.getOptionDesc(options!!) } } else { val resolveClass = duckTypeHelper!!.resolveClass(convertTo, context) diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultLinkResolver.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultLinkResolver.kt index cf5642a84..0d69a6249 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultLinkResolver.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultLinkResolver.kt @@ -6,6 +6,7 @@ import com.intellij.psi.PsiClass import com.intellij.psi.PsiField import com.intellij.psi.PsiMethod import com.intellij.psi.util.PropertyUtil +import com.itangcent.common.kit.notNullOrBlank import com.itangcent.intellij.jvm.DocHelper import com.itangcent.intellij.jvm.PsiClassHelper import com.itangcent.intellij.psi.PsiClassUtils @@ -35,7 +36,7 @@ open class DefaultLinkResolver : LinkResolver { } val attrOfMethod = docHelper!!.getAttrOfDocComment(linkMethod) ?.lines()?.first { !it.isBlank() } - if (!attrOfMethod.isNullOrBlank()) { + if (attrOfMethod.notNullOrBlank()) { return "[$attrOfMethod]" } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultMethodDocClassExporter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultMethodDocClassExporter.kt index fbaf99672..879054f36 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultMethodDocClassExporter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultMethodDocClassExporter.kt @@ -3,9 +3,10 @@ package com.itangcent.idea.plugin.api.export import com.google.inject.Inject import com.intellij.lang.jvm.JvmModifier import com.intellij.psi.* -import com.intellij.util.containers.isNullOrEmpty import com.itangcent.common.exception.ProcessCanceledException import com.itangcent.common.kit.KVUtils +import com.itangcent.common.kit.notNullOrBlank +import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.logger.traceError import com.itangcent.common.model.MethodDoc import com.itangcent.common.utils.KV @@ -204,7 +205,7 @@ open class DefaultMethodDocClassExporter : ClassExporter, Worker { val descOfReturn = docHelper!!.findDocByTag(method, "return") - if (!descOfReturn.isNullOrBlank()) { + if (descOfReturn.notNullOrBlank()) { val methodReturnMain = ruleComputer!!.computer(ClassExportRuleKeys.METHOD_RETURN_MAIN, method) if (methodReturnMain.isNullOrBlank()) { methodDocHelper.appendRetDesc(methodDoc, descOfReturn) @@ -243,12 +244,12 @@ open class DefaultMethodDocClassExporter : ClassExporter, Worker { } }) - if (!comment.isNullOrBlank()) { - if (!KVUtils.addKeyComment(typedResponse, methodReturnMain, comment)) { + if (comment.notNullOrBlank()) { + if (!KVUtils.addKeyComment(typedResponse, methodReturnMain, comment!!)) { methodDocHelper.appendRetDesc(methodDoc, comment) } } - if (!options.isNullOrEmpty()) { + if (options.notNullOrEmpty()) { if (!KVUtils.addKeyOptions(typedResponse, methodReturnMain, options)) { methodDocHelper.appendRetDesc(methodDoc, KVUtils.getOptionDesc(options)) } @@ -315,7 +316,7 @@ open class DefaultMethodDocClassExporter : ClassExporter, Worker { }) methodParamComment[name!!] = comment ?: "" - if (!options.isNullOrEmpty()) { + if (options.notNullOrEmpty()) { methodParamComment["$name@options"] = options } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/SpringRequestClassExporter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/SpringRequestClassExporter.kt index 1f1e7a439..ea4e4f90f 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/SpringRequestClassExporter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/SpringRequestClassExporter.kt @@ -6,6 +6,7 @@ import com.intellij.psi.PsiElement import com.intellij.psi.PsiMethod import com.intellij.psi.PsiParameter import com.itangcent.common.constant.HttpMethod +import com.itangcent.common.kit.notNullOrBlank import com.itangcent.common.model.Header import com.itangcent.common.model.Request import com.itangcent.common.utils.* @@ -30,7 +31,7 @@ open class SpringRequestClassExporter : AbstractRequestClassExporter() { val ctrlRequestMappingAnn = findRequestMapping(cls) var basePath: String = findHttpPath(ctrlRequestMappingAnn) ?: "" val prefixPath = ruleComputer!!.computer(ClassExportRuleKeys.CLASS_PREFIX_PATH, cls) - if (!prefixPath.isNullOrBlank()) { + if (prefixPath.notNullOrBlank()) { basePath = contractPath(prefixPath, basePath) ?: "" } @@ -150,7 +151,7 @@ open class SpringRequestClassExporter : AbstractRequestClassExporter() { val readParamDefaultValue = readParamDefaultValue(param) - if (!readParamDefaultValue.isNullOrBlank()) { + if (readParamDefaultValue.notNullOrBlank()) { defaultVal = readParamDefaultValue } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/markdown/MarkdownFormatter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/markdown/MarkdownFormatter.kt index 92b1820f5..2da467611 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/markdown/MarkdownFormatter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/markdown/MarkdownFormatter.kt @@ -4,16 +4,18 @@ import com.google.inject.Inject import com.google.inject.Singleton import com.intellij.psi.PsiClass import com.itangcent.common.constant.Attrs +import com.itangcent.common.kit.KVUtils +import com.itangcent.common.kit.KitUtils +import com.itangcent.common.kit.notNullOrBlank +import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.model.Doc import com.itangcent.common.model.MethodDoc import com.itangcent.common.model.Request import com.itangcent.common.utils.DateUtils -import com.itangcent.common.kit.KVUtils -import com.itangcent.common.kit.KitUtils +import com.itangcent.http.RequestUtils import com.itangcent.idea.plugin.settings.SettingBinder import com.itangcent.idea.psi.ResourceHelper import com.itangcent.idea.utils.ModuleHelper -import com.itangcent.http.RequestUtils import com.itangcent.intellij.context.ActionContext import com.itangcent.intellij.logger.Logger import com.itangcent.intellij.util.ActionUtils @@ -124,7 +126,7 @@ class MarkdownFormatter { handle("${hN(deep)} ${methodDoc.name}\n\n") handle(" \n\n") - if (!methodDoc.desc.isNullOrBlank()) { + if (methodDoc.desc.notNullOrBlank()) { handle("**Desc:**\n\n") handle("

${methodDoc.desc}

\n\n") } @@ -159,7 +161,7 @@ class MarkdownFormatter { handle("${hN(deep + 1)} BASIC\n\n") handle("**Path:** ${request.path}\n\n") handle("**Method:** ${request.method}\n\n") - if (!request.desc.isNullOrBlank()) { + if (request.desc.notNullOrBlank()) { handle("**Desc:**\n\n") handle("

${request.desc}

\n\n") } @@ -168,7 +170,7 @@ class MarkdownFormatter { handle("${hN(deep + 1)} REQUEST\n\n") //path - if (!request.paths.isNullOrEmpty()) { + if (request.paths.notNullOrEmpty()) { handle("\n**Path:**\n\n") handle("| name | value | desc |\n") handle("| ------------ | ------------ | ------------ |\n") @@ -181,7 +183,7 @@ class MarkdownFormatter { } //header - if (!request.headers.isNullOrEmpty()) { + if (request.headers.notNullOrEmpty()) { handle("\n**Headers:**\n\n") handle("| name | value | required | example | desc |\n") handle("| ------------ | ------------ | ------------ | ------------ | ------------ |\n") @@ -194,7 +196,7 @@ class MarkdownFormatter { } //query - if (!request.querys.isNullOrEmpty()) { + if (request.querys.notNullOrEmpty()) { handle("\n**Query:**\n\n") handle("| name | value | required | desc |\n") handle("| ------------ | ------------ | ------------ | ------------ |\n") @@ -220,7 +222,7 @@ class MarkdownFormatter { } - if (!request.formParams.isNullOrEmpty()) { + if (request.formParams.notNullOrEmpty()) { handle("\n**Form:**\n\n") handle("| name | value | required | type | desc |\n") handle("| ------------ | ------------ | ------------ | ------------ | ------------ |\n") @@ -232,7 +234,7 @@ class MarkdownFormatter { } } - if (!request.response.isNullOrEmpty()) { + if (request.response.notNullOrEmpty()) { val response = request.response!!.firstOrNull { it.body != null } //todo:support multiple response diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/DefaultPostmanApiHelper.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/DefaultPostmanApiHelper.kt index 468bdc984..597c5344a 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/DefaultPostmanApiHelper.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/DefaultPostmanApiHelper.kt @@ -2,6 +2,7 @@ package com.itangcent.idea.plugin.api.export.postman import com.google.gson.internal.LazilyParsedNumber import com.google.inject.Inject +import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.logger.traceError import com.itangcent.common.utils.GsonUtils import com.itangcent.common.utils.KV @@ -56,7 +57,7 @@ open class DefaultPostmanApiHelper : PostmanApiHelper { private val apiThrottle: Throttle = ThrottleHelper().build("postman_api") override fun hasPrivateToken(): Boolean { - return !getPrivateToken().isNullOrEmpty() + return getPrivateToken().notNullOrEmpty() } override fun getPrivateToken(): String? { @@ -138,7 +139,7 @@ open class DefaultPostmanApiHelper : PostmanApiHelper { if (returnValue.notNullOrEmpty() && returnValue!!.contains("collection")) { val returnObj = GsonUtils.parseToJsonTree(returnValue) val collectionInfo = returnObj?.asJsonObject?.get("collection")?.asMap() - if (!collectionInfo.isNullOrEmpty()) { + if (collectionInfo.notNullOrEmpty()) { return collectionInfo } } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanApiExporter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanApiExporter.kt index dafc01543..ad7453c04 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanApiExporter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanApiExporter.kt @@ -5,6 +5,7 @@ import com.google.inject.Singleton import com.intellij.openapi.project.Project import com.intellij.openapi.ui.Messages import com.itangcent.common.kit.getAs +import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.logger.traceError import com.itangcent.common.model.Request import com.itangcent.common.utils.GsonUtils @@ -91,8 +92,8 @@ class PostmanApiExporter { logger.info("PrivateToken of postman be found") val createdCollection = postmanApiHelper.createCollection(postman) - if (!createdCollection.isNullOrEmpty()) { - val collectionName = createdCollection.getAs("name") + if (createdCollection.notNullOrEmpty()) { + val collectionName = createdCollection!!.getAs("name") if (StringUtils.isNotBlank(collectionName)) { logger.info("Imported as collection:$collectionName") return@runAsync diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanCachedApiHelper.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanCachedApiHelper.kt index 2900e2beb..883dffa78 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanCachedApiHelper.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanCachedApiHelper.kt @@ -1,6 +1,7 @@ package com.itangcent.idea.plugin.api.export.postman import com.google.inject.Inject +import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.idea.binder.DbBeanBinderFactory import com.itangcent.intellij.file.LocalFileRepository import com.itangcent.intellij.logger.Logger @@ -146,7 +147,7 @@ class PostmanCachedApiHelper : DefaultPostmanApiHelper() { val oldCollectionCache = beanBinder.read() if (oldCollectionCache != NULL_COLLECTION_INFO_CACHE - && !oldCollectionCache.allCollection.isNullOrEmpty()) { + && oldCollectionCache.allCollection.notNullOrEmpty()) { val survivedCollectionIds = allCollection.stream() .map { it["id"] } .filter { it != null } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanFormatter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanFormatter.kt index 2309ecb9a..f7e3778d9 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanFormatter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanFormatter.kt @@ -3,6 +3,7 @@ package com.itangcent.idea.plugin.api.export.postman import com.google.inject.Inject import com.google.inject.Singleton import com.intellij.psi.PsiClass +import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.model.Request import com.itangcent.common.model.getContentType import com.itangcent.common.utils.DateUtils @@ -138,7 +139,7 @@ class PostmanFormatter { } - if (!request.response.isNullOrEmpty()) { + if (request.response.notNullOrEmpty()) { val responses: ArrayList> = ArrayList() val exampleName = request.name + "-Example" diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt index 8784a5b73..31cc02e78 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.project.Project import com.intellij.psi.PsiMethod +import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.logger.traceError import com.itangcent.common.model.Doc import com.itangcent.common.model.MethodDoc @@ -408,8 +409,8 @@ class SuvApiExporter { logger!!.info("PrivateToken of postman be found") val createdCollection = postmanApiHelper.createCollection(postman) - if (!createdCollection.isNullOrEmpty()) { - val collectionName = createdCollection["name"]?.toString() + if (createdCollection.notNullOrEmpty()) { + val collectionName = createdCollection!!["name"]?.toString() if (StringUtils.isNotBlank(collectionName)) { logger!!.info("Imported as collection:$collectionName") return diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/config/RecommendConfigReader.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/config/RecommendConfigReader.kt index 3718eb278..4df2c7042 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/config/RecommendConfigReader.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/config/RecommendConfigReader.kt @@ -3,6 +3,7 @@ package com.itangcent.idea.plugin.config import com.google.inject.Inject import com.google.inject.name.Named import com.intellij.ide.util.PropertiesComponent +import com.itangcent.common.kit.notNullOrBlank import com.itangcent.common.utils.invokeMethod import com.itangcent.idea.plugin.settings.SettingBinder import com.itangcent.intellij.config.ConfigReader @@ -139,8 +140,8 @@ class RecommendConfigReader : ConfigReader { val propertiesComponent = PropertiesComponent.getInstance() val cachedValue = propertiesComponent.getValue(config_name) - if (!cachedValue.isNullOrBlank()) { - val cachedVersion = cachedValue.substring(0, 10).trim() + if (cachedValue.notNullOrBlank()) { + val cachedVersion = cachedValue!!.substring(0, 10).trim() if (cachedVersion == curr_version) { RECOMMEND_CONFIG_PLAINT = cachedValue.substring(10) return cachedValue diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/ApiCallDialog.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/ApiCallDialog.kt index 244bbe24c..d216b4252 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/ApiCallDialog.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/ApiCallDialog.kt @@ -11,6 +11,8 @@ import com.intellij.ui.components.JBTabbedPane import com.intellij.ui.table.JBTable import com.intellij.util.ui.ComboBoxCellEditor import com.itangcent.common.kit.KitUtils +import com.itangcent.common.kit.notNullOrBlank +import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.logger.traceError import com.itangcent.common.model.FormParam import com.itangcent.common.model.Request @@ -293,7 +295,7 @@ class ApiCallDialog : JDialog() { autoComputer.bindVisible(this.paramPanel!!) .with(this::currRequest) - .eval { !it?.querys.isNullOrEmpty() } + .eval { it?.querys.notNullOrEmpty() } autoComputer.bindVisible(this.contentTypePanel!!) .with(this::currRequest) @@ -761,7 +763,7 @@ class ApiCallDialog : JDialog() { val httpRequest = getHttpClient().request().method(request.method ?: "GET") .url(url) - if (!requestHeader.isNullOrBlank()) { + if (requestHeader.notNullOrBlank()) { parseEqualLine(requestHeader) { name, value -> httpRequest.header(name, value) } @@ -769,7 +771,7 @@ class ApiCallDialog : JDialog() { if (request.method?.toUpperCase() != "GET") { - if (!request.formParams.isNullOrEmpty()) { + if (request.formParams.notNullOrEmpty()) { val formParams = formTableBinder.readAvailableForm(this.formTable!!) if (formParams != null) { diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.kt index 9c0114f95..667de3938 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.kt @@ -13,8 +13,10 @@ import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.wm.WindowManager import com.intellij.ui.CheckBoxList +import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.utils.GsonUtils import com.itangcent.common.utils.SystemUtils +import com.itangcent.common.utils.notNullOrEmpty import com.itangcent.common.utils.truncate import com.itangcent.idea.icons.EasyIcons import com.itangcent.idea.icons.iconOnly @@ -410,11 +412,11 @@ class EasyApiSettingGUI { toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation) } val files = chooser.choose(null, toSelect) - if (!files.isNullOrEmpty()) { + if (files.notNullOrEmpty()) { val virtualFile = files[0] val read = com.itangcent.common.utils.FileUtils.read(File(virtualFile.path), kotlin.text.Charsets.UTF_8) - if (!read.isNullOrEmpty()) { - setSettings(GsonUtils.fromJson(read, Settings::class)) + if (read.notNullOrEmpty()) { + setSettings(GsonUtils.fromJson(read!!, Settings::class)) } } } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/SuvApiExportDialog.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/SuvApiExportDialog.kt index 517de3427..f3143ff52 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/SuvApiExportDialog.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/SuvApiExportDialog.kt @@ -4,6 +4,7 @@ import com.google.inject.Inject import com.intellij.ide.util.PropertiesComponent import com.intellij.ui.components.JBCheckBox import com.itangcent.common.logger.traceError +import com.itangcent.common.utils.notNullOrEmpty import com.itangcent.idea.icons.EasyIcons import com.itangcent.idea.icons.iconOnly import com.itangcent.idea.utils.SwingUtils @@ -106,7 +107,7 @@ class SuvApiExportDialog : JDialog() { val lastUsedChannel = PropertiesComponent.getInstance().getValue(LAST_USED_CHANNEL) - if (!lastUsedChannel.isNullOrEmpty()) { + if (lastUsedChannel.notNullOrEmpty()) { channels.firstOrNull { it.toString() == lastUsedChannel } ?.let { this.channelComboBox!!.model.selectedItem = it } } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/utils/ModuleHelper.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/utils/ModuleHelper.kt index 0da4e588e..e09c22d31 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/utils/ModuleHelper.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/utils/ModuleHelper.kt @@ -7,6 +7,7 @@ import com.intellij.openapi.project.Project import com.intellij.psi.PsiClass import com.intellij.psi.PsiFile import com.intellij.psi.PsiMethod +import com.itangcent.common.kit.notNullOrBlank import com.itangcent.common.logger.traceError import com.itangcent.idea.plugin.api.export.ClassExportRuleKeys import com.itangcent.idea.psi.PsiResource @@ -62,7 +63,7 @@ class ModuleHelper { val moduleByRule = ruleComputer!!.computer(ClassExportRuleKeys.MODULE, cls) - if (!moduleByRule.isNullOrBlank()) { + if (moduleByRule.notNullOrBlank()) { return moduleByRule } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/intellij/extend/GsonKit.kt b/idea-plugin/src/main/kotlin/com/itangcent/intellij/extend/GsonKit.kt index 456528856..38a9ae276 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/intellij/extend/GsonKit.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/intellij/extend/GsonKit.kt @@ -4,8 +4,6 @@ import com.google.gson.JsonArray import com.google.gson.JsonElement import com.google.gson.JsonObject import com.google.gson.JsonPrimitive -import java.util.* -import kotlin.collections.ArrayList fun JsonObject.asMap(): HashMap { val map: HashMap = HashMap() From 923a2b7334c94a4a643d42c4ad91f931abdb97dd Mon Sep 17 00:00:00 2001 From: tangcent Date: Fri, 27 Mar 2020 23:24:33 +0800 Subject: [PATCH 3/7] fix HttpRequest querys --- .../kotlin/com/itangcent/http/ApacheHttpClient.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/common-api/src/main/kotlin/com/itangcent/http/ApacheHttpClient.kt b/common-api/src/main/kotlin/com/itangcent/http/ApacheHttpClient.kt index a1b986bc7..3d2fc48d0 100644 --- a/common-api/src/main/kotlin/com/itangcent/http/ApacheHttpClient.kt +++ b/common-api/src/main/kotlin/com/itangcent/http/ApacheHttpClient.kt @@ -4,7 +4,6 @@ import com.itangcent.annotation.script.ScriptIgnore import com.itangcent.annotation.script.ScriptTypeName import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.kit.toJson -import com.itangcent.common.utils.append import org.apache.http.HttpEntity import org.apache.http.NameValuePair import org.apache.http.client.config.RequestConfig @@ -68,9 +67,14 @@ open class ApacheHttpClient : HttpClient { open fun call(request: ApacheHttpRequest): HttpResponse { var url = request.url()!! - request.querys()?.let { params -> - params.joinToString("&") { "${it.name()}=${it.value()}" } - }?.let { url = url.append(it, "&")!! } + val querys = request.querys() + if (querys.notNullOrEmpty()) { + val urlParams = querys!!.joinToString("&") { "${it.name()}=${it.value()}" } + url = when { + url.contains('?') -> "$url&$urlParams" + else -> "$url?$urlParams" + } + } val requestBuilder = RequestBuilder.create(request.method()) .setUri(url) From 28fbe8b201fdda075fb80aae4e74c7f8b7125b90 Mon Sep 17 00:00:00 2001 From: tangcent Date: Sun, 29 Mar 2020 09:45:45 +0800 Subject: [PATCH 4/7] chore: opti StringUtils/Kits --- .../api/export/DefaultMethodDocClassExporter.kt | 2 +- .../plugin/api/export/SpringRequestClassExporter.kt | 4 ++-- .../api/export/postman/DefaultPostmanApiHelper.kt | 4 ++-- .../plugin/api/export/postman/PostmanApiExporter.kt | 4 ++-- .../idea/plugin/api/export/suv/SuvApiExporter.kt | 4 ++-- .../com/itangcent/idea/plugin/rule/RuleToolUtils.kt | 8 ++++---- .../com/itangcent/idea/plugin/utils/RegexUtils.kt | 12 ++++++------ .../kotlin/com/itangcent/idea/psi/ResourceHelper.kt | 5 ++--- 8 files changed, 21 insertions(+), 22 deletions(-) diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultMethodDocClassExporter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultMethodDocClassExporter.kt index 879054f36..4984fba21 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultMethodDocClassExporter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultMethodDocClassExporter.kt @@ -276,7 +276,7 @@ open class DefaultMethodDocClassExporter : ClassExporter, Worker { paramDocTag.dataElements .asSequence() .map { it?.text } - .filterNot { StringUtils.isBlank(it) } + .filterNot { it.isNullOrBlank() } .forEach { when { name == null -> name = it diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/SpringRequestClassExporter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/SpringRequestClassExporter.kt index ea4e4f90f..a22262f2c 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/SpringRequestClassExporter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/SpringRequestClassExporter.kt @@ -159,7 +159,7 @@ open class SpringRequestClassExporter : AbstractRequestClassExporter() { required = true } - if (StringUtils.isBlank(paramName)) { + if (paramName.isNullOrBlank()) { paramName = param.name()!! } @@ -330,7 +330,7 @@ open class SpringRequestClassExporter : AbstractRequestClassExporter() { method = method.substringBefore(",") } return when { - StringUtils.isBlank(method) -> { + method.isNullOrBlank() -> { HttpMethod.NO_METHOD } method.startsWith("RequestMethod.") -> { diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/DefaultPostmanApiHelper.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/DefaultPostmanApiHelper.kt index 597c5344a..459574f0e 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/DefaultPostmanApiHelper.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/DefaultPostmanApiHelper.kt @@ -2,6 +2,7 @@ package com.itangcent.idea.plugin.api.export.postman import com.google.gson.internal.LazilyParsedNumber import com.google.inject.Inject +import com.itangcent.common.kit.notNullOrBlank import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.logger.traceError import com.itangcent.common.utils.GsonUtils @@ -23,7 +24,6 @@ import com.itangcent.intellij.extend.rx.ThrottleHelper import com.itangcent.intellij.extend.toInt import com.itangcent.intellij.logger.Logger import com.itangcent.suv.http.HttpClientProvider -import org.apache.commons.lang3.StringUtils import org.apache.http.entity.ContentType import java.util.concurrent.Semaphore import java.util.concurrent.TimeUnit @@ -221,7 +221,7 @@ open class DefaultPostmanApiHelper : PostmanApiHelper { val returnObj = GsonUtils.parseToJsonTree(returnValue) val collectionName = returnObj?.asJsonObject?.get("collection") ?.asJsonObject?.get("name")?.asString - if (StringUtils.isNotBlank(collectionName)) { + if (collectionName.notNullOrBlank()) { return true } } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanApiExporter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanApiExporter.kt index ad7453c04..0f4dda707 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanApiExporter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanApiExporter.kt @@ -5,6 +5,7 @@ import com.google.inject.Singleton import com.intellij.openapi.project.Project import com.intellij.openapi.ui.Messages import com.itangcent.common.kit.getAs +import com.itangcent.common.kit.notNullOrBlank import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.logger.traceError import com.itangcent.common.model.Request @@ -18,7 +19,6 @@ import com.itangcent.intellij.context.ActionContext import com.itangcent.intellij.logger.Logger import com.itangcent.intellij.psi.SelectedHelper import com.itangcent.intellij.util.ActionUtils -import org.apache.commons.lang3.StringUtils import java.util.* import kotlin.collections.ArrayList @@ -94,7 +94,7 @@ class PostmanApiExporter { if (createdCollection.notNullOrEmpty()) { val collectionName = createdCollection!!.getAs("name") - if (StringUtils.isNotBlank(collectionName)) { + if (collectionName.notNullOrBlank()) { logger.info("Imported as collection:$collectionName") return@runAsync } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt index 31cc02e78..08724e74b 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.project.Project import com.intellij.psi.PsiMethod +import com.itangcent.common.kit.notNullOrBlank import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.logger.traceError import com.itangcent.common.model.Doc @@ -49,7 +50,6 @@ import com.itangcent.intellij.tip.TipsHelper import com.itangcent.intellij.util.UIUtils import com.itangcent.suv.http.ConfigurableHttpClientProvider import com.itangcent.suv.http.HttpClientProvider -import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.exception.ExceptionUtils import java.util.* import kotlin.reflect.KClass @@ -411,7 +411,7 @@ class SuvApiExporter { if (createdCollection.notNullOrEmpty()) { val collectionName = createdCollection!!["name"]?.toString() - if (StringUtils.isNotBlank(collectionName)) { + if (collectionName.notNullOrBlank()) { logger!!.info("Imported as collection:$collectionName") return } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/RuleToolUtils.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/RuleToolUtils.kt index 139c7f75c..68d22ea9d 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/RuleToolUtils.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/RuleToolUtils.kt @@ -4,9 +4,9 @@ import com.itangcent.annotation.script.ScriptIgnore import com.itangcent.annotation.script.ScriptReturn import com.itangcent.annotation.script.ScriptTypeName import com.itangcent.annotation.script.ScriptUnIgnore +import com.itangcent.common.kit.headLine import com.itangcent.common.utils.GsonUtils import com.itangcent.common.utils.KV -import com.itangcent.common.kit.headLine import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.time.DateFormatUtils import java.util.* @@ -107,7 +107,7 @@ class RuleToolUtils { * @see #uncapitalize(String) * @since 2.0 */ - fun capitalize(str: String): String { + fun capitalize(str: String?): String { return StringUtils.capitalize(str) } @@ -698,8 +698,8 @@ class RuleToolUtils { * @param str camel words * @return underline words */ - fun camel2Underline(str: String): String { - if (StringUtils.isEmpty(str)) { + fun camel2Underline(str: String?): String? { + if (str.isNullOrBlank()) { return str } val matcher = TO_LINE_PATTERN.matcher(str) diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/utils/RegexUtils.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/utils/RegexUtils.kt index 284f22674..5f9e5482d 100755 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/utils/RegexUtils.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/utils/RegexUtils.kt @@ -155,7 +155,7 @@ class RegexUtils { } private fun delFirst(pattern: Pattern?, content: String): String { - return if (null == pattern || StringUtils.isBlank(content)) { + return if (null == pattern || content.isNullOrBlank()) { content } else { pattern.matcher(content).replaceFirst("") @@ -183,7 +183,7 @@ class RegexUtils { * pattern */ private fun delAll(pattern: Pattern?, content: String): String { - return if (null == pattern || StringUtils.isBlank(content)) { + return if (null == pattern || content.isNullOrBlank()) { content } else pattern.matcher(content).replaceAll("") @@ -275,12 +275,12 @@ class RegexUtils { } else pattern.matcher(content).find() } - fun isMatch(regex: String, content: String?): Boolean { + fun isMatch(regex: String?, content: String?): Boolean { if (content == null) { return false } - if (StringUtils.isEmpty(regex)) { + if (regex.isNullOrBlank()) { return true } val pattern = getPattern(regex, Pattern.DOTALL) @@ -312,8 +312,8 @@ class RegexUtils { /** * escape for Regex keywords */ - fun escape(content: String): String { - if (StringUtils.isBlank(content)) { + fun escape(content: String?): String? { + if (content.isNullOrBlank()) { return content } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/psi/ResourceHelper.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/psi/ResourceHelper.kt index 2a9ed74a2..b654265ca 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/psi/ResourceHelper.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/psi/ResourceHelper.kt @@ -10,7 +10,6 @@ import com.itangcent.idea.plugin.api.export.DocParseHelper import com.itangcent.intellij.config.rule.RuleComputer import com.itangcent.intellij.context.ActionContext import com.itangcent.intellij.jvm.DocHelper -import org.apache.commons.lang3.StringUtils @Singleton class ResourceHelper { @@ -21,7 +20,7 @@ class ResourceHelper { @Inject private val docHelper: DocHelper? = null - @Inject + @Inject(optional = true) private val docParseHelper: DocParseHelper? = null @Inject @@ -44,7 +43,7 @@ class ResourceHelper { var docText = ruleComputer!!.computer(ClassExportRuleKeys.CLASS_DOC, cls) docText = docText.append(docHelper!!.getAttrOfDocComment(cls)) return when { - StringUtils.isBlank(docText) -> cls.name + docText.isNullOrBlank() -> cls.name docParseHelper != null -> docParseHelper.resolveLinkInAttr(docText, cls) else -> docText } From f79c3eb2cd9ec352a359ca51b4adecf5905e5ff5 Mon Sep 17 00:00:00 2001 From: tangcent Date: Mon, 30 Mar 2020 22:14:12 +0800 Subject: [PATCH 5/7] update version of intellij-idea --- common-api/build.gradle | 2 +- idea-plugin/build.gradle | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common-api/build.gradle b/common-api/build.gradle index baeba440c..86de594fa 100644 --- a/common-api/build.gradle +++ b/common-api/build.gradle @@ -28,7 +28,7 @@ dependencies { compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - compile('com.itangcent:commons:0.5.1-SNAPSHOT') { + compile('com.itangcent:commons:0.5.2-SNAPSHOT') { exclude group: 'com.google.inject' exclude group: 'com.google.code.gson' } diff --git a/idea-plugin/build.gradle b/idea-plugin/build.gradle index 3ea2a2e0b..bf2bf0ea2 100644 --- a/idea-plugin/build.gradle +++ b/idea-plugin/build.gradle @@ -100,17 +100,17 @@ dependencies { // compile fileTree(dir: 'libs', include: ['*.jar']) - compile('com.itangcent:intellij-idea:0.5.1-SNAPSHOT') { + compile('com.itangcent:intellij-idea:0.5.2-SNAPSHOT') { exclude group: 'com.google.inject' exclude group: 'com.google.code.gson' } - compile('com.itangcent:intellij-kotlin-support:0.5.1-SNAPSHOT') { + compile('com.itangcent:intellij-kotlin-support:0.5.2-SNAPSHOT') { exclude group: 'com.google.inject' exclude group: 'com.google.code.gson' } - compile('com.itangcent:intellij-scala-support:0.5.1-SNAPSHOT') { + compile('com.itangcent:intellij-scala-support:0.5.2-SNAPSHOT') { exclude group: 'com.google.inject' exclude group: 'com.google.code.gson' } From 6cbbd11221c9cb1c356e17d7d01fee24c31f03d4 Mon Sep 17 00:00:00 2001 From: tangcent Date: Mon, 30 Mar 2020 23:30:27 +0800 Subject: [PATCH 6/7] new rule tool: localStorage --- .../idea/plugin/dialog/DebugDialog.kt | 4 +- .../idea/plugin/rule/ScriptRuleParser.kt | 2 +- .../idea/plugin/rule/StandardJdkRuleParser.kt | 5 ++ .../idea/plugin/utils/LocalStorageUtils.kt | 87 +++++++++++++++++++ 4 files changed, 95 insertions(+), 3 deletions(-) create mode 100755 idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/utils/LocalStorageUtils.kt diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/DebugDialog.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/DebugDialog.kt index 747a0f75a..56c08caee 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/DebugDialog.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/DebugDialog.kt @@ -410,7 +410,7 @@ class DebugDialog : JDialog() { } override fun demoCode(): String { - return "var separator = tool.repeat(\"-\", 35) + \"\\n\\n\"\nvar sb = \"\"\nsb += \"debug `tool`:\\n\"\nsb += tool.debug(tool)\nsb += separator\nsb += \"debug `it`:\\n\"\nsb += tool.debug(it)\nsb += separator\nsb += \"debug `regex`:\\n\"\nsb += tool.debug(regex)\nsb += separator\nsb += \"debug `logger`:\\n\"\nsb += tool.debug(logger)\nsb += separator\nsb += \"debug `helper`:\\n\"\nsb += tool.debug(helper)\nsb += \"debug `httpClient`:\\n\"\nsb += tool.debug(httpClient)\nsb" + return "var separator = tool.repeat(\"-\", 35) + \"\\n\\n\"\nvar sb = \"\"\nsb += \"debug `tool`:\\n\"\nsb += tool.debug(tool)\nsb += separator\nsb += \"debug `it`:\\n\"\nsb += tool.debug(it)\nsb += separator\nsb += \"debug `regex`:\\n\"\nsb += tool.debug(regex)\nsb += separator\nsb += \"debug `logger`:\\n\"\nsb += tool.debug(logger)\nsb += separator\nsb += \"debug `helper`:\\n\"\nsb += tool.debug(helper)\nsb += separator\nsb += \"debug `httpClient`:\\n\"\nsb += tool.debug(httpClient)\nsb += separator\nsb += \"debug `localStorage`:\\n\"\nsb += tool.debug(localStorage)\nsb += separator\nsb" } } @@ -433,7 +433,7 @@ class DebugDialog : JDialog() { } override fun demoCode(): String { - return "def separator = tool.repeat(\"-\", 35) + \"\\n\\n\"\ndef sb = \"\"\nsb += \"debug `tool`:\\n\"\nsb += tool.debug(tool)\nsb += separator\nsb += \"debug `it`:\\n\"\nsb += tool.debug(it)\nsb += separator\nsb += \"debug `regex`:\\n\"\nsb += tool.debug(regex)\nsb += separator\nsb += \"debug `logger`:\\n\"\nsb += tool.debug(logger)\nsb += separator\nsb += \"debug `helper`:\\n\"\nsb += tool.debug(helper)\nsb += \"debug `httpClient`:\\n\"\nsb += tool.debug(httpClient)\nreturn sb" + return "def separator = tool.repeat(\"-\", 35) + \"\\n\\n\"\ndef sb = \"\"\nsb += \"debug `tool`:\\n\"\nsb += tool.debug(tool)\nsb += separator\nsb += \"debug `it`:\\n\"\nsb += tool.debug(it)\nsb += separator\nsb += \"debug `regex`:\\n\"\nsb += tool.debug(regex)\nsb += separator\nsb += \"debug `logger`:\\n\"\nsb += tool.debug(logger)\nsb += separator\nsb += \"debug `helper`:\\n\"\nsb += tool.debug(helper)\nsb += separator\nsb += \"debug `httpClient`:\\n\"\nsb += tool.debug(httpClient)\nsb += separator\nsb += \"debug `localStorage`:\\n\"\nsb += tool.debug(localStorage)\nsb += separator\nreturn sb" } } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/ScriptRuleParser.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/ScriptRuleParser.kt index ddd38ef44..1aab461cb 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/ScriptRuleParser.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/ScriptRuleParser.kt @@ -5,8 +5,8 @@ import com.intellij.psi.* import com.intellij.psi.util.PsiTypesUtil import com.itangcent.annotation.script.ScriptIgnore import com.itangcent.annotation.script.ScriptTypeName -import com.itangcent.common.utils.mapToTypedArray import com.itangcent.common.logger.traceError +import com.itangcent.common.utils.mapToTypedArray import com.itangcent.http.RequestUtils import com.itangcent.idea.plugin.api.MethodInferHelper import com.itangcent.intellij.config.rule.* diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/StandardJdkRuleParser.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/StandardJdkRuleParser.kt index 6a3c2bf94..5ea904536 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/StandardJdkRuleParser.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/StandardJdkRuleParser.kt @@ -5,6 +5,7 @@ import com.intellij.psi.PsiElement import com.intellij.psi.PsiMember import com.itangcent.annotation.script.ScriptReturn import com.itangcent.annotation.script.ScriptTypeName +import com.itangcent.idea.plugin.utils.LocalStorageUtils import com.itangcent.idea.plugin.utils.RegexUtils import com.itangcent.intellij.config.rule.RuleContext import com.itangcent.intellij.jvm.LinkExtractor @@ -17,6 +18,9 @@ abstract class StandardJdkRuleParser : ScriptRuleParser() { @Inject private var httpClientProvider: HttpClientProvider? = null + @Inject + protected val localStorageUtils: LocalStorageUtils? = null + private var scriptEngine: ScriptEngine? = null private var unsupported = false @@ -52,6 +56,7 @@ abstract class StandardJdkRuleParser : ScriptRuleParser() { val engineBindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE) engineBindings.putAll(toolBindings) engineBindings["logger"] = logger + engineBindings["localStorage"] = localStorageUtils engineBindings["helper"] = Helper(context.getPsiContext()) engineBindings["httpClient"] = httpClientProvider!!.getHttpClient() } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/utils/LocalStorageUtils.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/utils/LocalStorageUtils.kt new file mode 100755 index 000000000..f7f7848dc --- /dev/null +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/utils/LocalStorageUtils.kt @@ -0,0 +1,87 @@ +package com.itangcent.idea.plugin.utils + +import com.google.inject.Inject +import com.google.inject.Singleton +import com.itangcent.annotation.script.ScriptTypeName +import com.itangcent.common.utils.KV +import com.itangcent.idea.binder.DbBeanBinderFactory +import com.itangcent.intellij.file.LocalFileRepository + +@Singleton +@ScriptTypeName("localStorage") +class LocalStorageUtils { + + @Inject + private val localFileRepository: LocalFileRepository? = null + + private var dbBeanBinderFactory: DbBeanBinderFactory>? = null + + private fun getDbBeanBinderFactory(): DbBeanBinderFactory> { + if (dbBeanBinderFactory == null) { + synchronized(this) { + dbBeanBinderFactory = DbBeanBinderFactory(localFileRepository!!.getOrCreateFile(".api.local.storage.v1.1.db").path) + { KV.create() } + } + } + return this.dbBeanBinderFactory!! + } + + fun get(name: String?): Any? { + return get(DEFAULT_GROUP, name) + } + + fun get(group: String?, name: String?): Any? { + return getDbBeanBinderFactory().getBeanBinder(group ?: DEFAULT_GROUP) + .tryRead()?.get(name) + } + + fun set(name: String?, value: Any?) { + set(DEFAULT_GROUP, name, value) + } + + fun set(group: String?, name: String?, value: Any?) { + val beanBinder = getDbBeanBinderFactory().getBeanBinder(group ?: DEFAULT_GROUP) + val kv = beanBinder.read() + if (value == null) { + kv.remove(name) + } else { + kv[name] = value + } + beanBinder.save(kv) + } + + fun remove(name: String) { + remove(DEFAULT_GROUP, name) + } + + fun remove(group: String?, name: String) { + val beanBinder = getDbBeanBinderFactory().getBeanBinder(group ?: DEFAULT_GROUP) + val kv = beanBinder.tryRead() ?: return + kv.remove(name) + beanBinder.save(kv) + } + + fun keys(): Array { + return keys(DEFAULT_GROUP) + } + + fun keys(group: String?): Array { + return getDbBeanBinderFactory().getBeanBinder(group ?: DEFAULT_GROUP) + .tryRead() + ?.keys + ?.toTypedArray() + ?: emptyArray() + } + + fun clear() { + clear(DEFAULT_GROUP) + } + + fun clear(group: String?) { + getDbBeanBinderFactory().deleteBinder(group ?: DEFAULT_GROUP) + } + + companion object { + const val DEFAULT_GROUP = "default_local_group" + } +} From 029bf6c937ca6ddebcce33f7755871f0a4c8ba89 Mon Sep 17 00:00:00 2001 From: tangcent Date: Mon, 30 Mar 2020 23:52:20 +0800 Subject: [PATCH 7/7] release v1.9.1.183.0 --- IDEA_CHANGELOG.md | 4 +++ build.gradle | 2 +- gradle.properties | 2 +- idea-plugin/parts/pluginChanges.html | 31 +++---------------- .../src/main/resources/META-INF/plugin.xml | 2 +- 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/IDEA_CHANGELOG.md b/IDEA_CHANGELOG.md index 92fe4cf08..5be859e8f 100644 --- a/IDEA_CHANGELOG.md +++ b/IDEA_CHANGELOG.md @@ -102,6 +102,10 @@ * log saved file path [(#264)](https://github.com/tangcent/easy-api/pull/264) * opti: [DEBUG ACTION] [(#265)](https://github.com/tangcent/easy-api/pull/265) + + * fix HttpRequest querys [(#267)](https://github.com/tangcent/easy-api/pull/267) + + * new rule tool: localStorage [(#268)](https://github.com/tangcent/easy-api/pull/268) \ No newline at end of file diff --git a/build.gradle b/build.gradle index 1eeae4258..053d6f096 100644 --- a/build.gradle +++ b/build.gradle @@ -1,2 +1,2 @@ group 'com.itangcent' -version '1.9.0.183.0' \ No newline at end of file +version '1.9.1.183.0' \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 62cd81330..bc380842e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.daemon=true org.gradle.workers.max=8 idea_version=2017.3.5 plugin_name=EasyApi -plugin_version=1.9.0.183.0 +plugin_version=1.9.1.183.0 descriptionFile=parts/pluginDescription.html changesFile=parts/pluginChanges.html \ No newline at end of file diff --git a/idea-plugin/parts/pluginChanges.html b/idea-plugin/parts/pluginChanges.html index 0f5d2fc3b..7d9a0d7ba 100644 --- a/idea-plugin/parts/pluginChanges.html +++ b/idea-plugin/parts/pluginChanges.html @@ -1,34 +1,13 @@ -v1.9.0.183.0(2020-03-23) +v1.9.1.183.0(2020-03-31)
Full Changelog
    bug-fix: -
  • fix type parse for markdown formatter(#255) -
  • -
  • addHeaderIfMissed only if the request hasBody(#258) -
  • -
  • fix name of api without any comment(#263) +
  • fix HttpRequest querys(#267)
    enhancement: -
  • recommend config: private_protected_field_only(#256) -
  • -
  • refactor http client(#257) -
  • -
  • resolve RequestMapping#params(#259) -
  • -
  • resolve RequestMapping#headers(#260) -
  • -
  • log saved file path(#264) -
  • -
  • opti: [DEBUG ACTION](#265) +
  • new rule tool: localStorage(#268)
\ No newline at end of file diff --git a/idea-plugin/src/main/resources/META-INF/plugin.xml b/idea-plugin/src/main/resources/META-INF/plugin.xml index 52222a7e1..a51f73eda 100755 --- a/idea-plugin/src/main/resources/META-INF/plugin.xml +++ b/idea-plugin/src/main/resources/META-INF/plugin.xml @@ -1,7 +1,7 @@ com.itangcent.idea.plugin.easy-api EasyApi - 1.9.0.183.0 + 1.9.1.183.0 Tangcent