Skip to content

Commit

Permalink
Merge pull request #65 from tangcent/release/stable
Browse files Browse the repository at this point in the history
release v1.1.0.183.0.2
  • Loading branch information
tangcent authored Oct 23, 2019
2 parents 25219c4 + 4de3568 commit 1742812
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group 'com.itangcent'
version '1.1.0.183.0.1'
version '1.1.0.183.0.2'

29 changes: 25 additions & 4 deletions common-api/src/main/kotlin/com/itangcent/common/utils/KVUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ object KVUtils {

val optionDesc = getOptionDesc(optionList)
if (!optionDesc.isNullOrBlank()) {
if (desc.isNullOrBlank()) {
desc = optionDesc
desc = if (desc.isNullOrBlank()) {
optionDesc
} else {
desc = desc + "\n" + optionDesc
desc + "\n" + optionDesc
}
}

Expand All @@ -34,9 +34,30 @@ object KVUtils {
*/
fun getOptionDesc(options: List<Map<String, Any?>>): String? {
return options.stream()
.map { it["value"].toString() + " :" + it["desc"] }
.map { concat(it["value"]?.toString(), it["desc"]?.toString()) }
.filter { it != null }
.reduce { s1, s2 -> s1 + "\n" + s2 }
.orElse(null)
}

/**
* get description of constants
*/
fun getConstantDesc(constants: List<Map<String, Any?>>): String? {
return constants.stream()
.map { concat(it["name"]?.toString(), it["desc"]?.toString()) }
.filter { it != null }
.reduce { s1, s2 -> s1 + "\n" + s2 }
.orElse(null)
}

private fun concat(name: String?, desc: String?): String? {
if (name.isNullOrEmpty()) {
return null
}
if (desc.isNullOrEmpty()) {
return name
}
return "$name :$desc"
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.daemon=true
org.gradle.workers.max=8
idea_version=2017.3.5
plugin_name=EasyYapi
plugin_version=1.1.0.183.0.1
plugin_version=1.1.0.183.0.2

descriptionFile=parts/pluginDescription.html
changesFile=parts/pluginChanges.html
Binary file modified idea-plugin/libs/intellij-idea.jar
Binary file not shown.
Binary file modified idea-plugin/libs/intellij-jvm.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion idea-plugin/parts/pluginChanges.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<a href="https://github.com/tangcent/easy-yapi/releases/tag/v1.1.0.183.0.1">v1.1.0.183.0.1(2019-10-20)</a>
<a href="https://github.com/tangcent/easy-yapi/releases/tag/v1.1.0.2">v1.1.0.183.0.2(2019-10-23)</a>
<br/>
<a href="https://github.com/tangcent/easy-yapi/blob/master/IDEA_CHANGELOG.md">Full Changelog</a>
<ul>enhancement:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.itangcent.intellij.config.rule.RuleComputer
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.jvm.*
import com.itangcent.intellij.logger.Logger
import com.itangcent.intellij.psi.ClassRuleConfig
import com.itangcent.intellij.psi.JsonOption
import com.itangcent.intellij.psi.PsiClassUtils
import com.itangcent.intellij.util.Magics
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.itangcent.idea.plugin.api.export

import com.google.inject.Inject
import com.google.inject.Singleton
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiType
import com.itangcent.common.utils.KVUtils
import com.itangcent.intellij.config.rule.RuleComputer
import com.itangcent.intellij.jvm.JvmClassHelper
import com.itangcent.intellij.jvm.PsiClassHelper
import com.itangcent.intellij.jvm.PsiResolver
import com.itangcent.intellij.logger.Logger
import com.itangcent.intellij.psi.ClassRuleKeys

@Singleton
class CommentResolver {

@Inject
protected val logger: Logger? = null

@Inject
protected val ruleComputer: RuleComputer? = null

@Inject
protected val jvmClassHelper: JvmClassHelper? = null

@Inject
protected val psiResolver: PsiResolver? = null

@Inject
protected val psiClassHelper: PsiClassHelper? = null


fun resolveCommentForType(psiType: PsiType, context: PsiElement): String? {

if (jvmClassHelper!!.isEnum(psiType)) {

val convertTo = ruleComputer!!.computer(ClassRuleKeys.ENUM_CONVERT, psiType, context)

if (!convertTo.isNullOrBlank()) {
if (convertTo.contains("#")) {
val options = psiClassHelper!!.resolveEnumOrStatic(convertTo, context, "")
if (!options.isNullOrEmpty()) {
return KVUtils.getOptionDesc(options)
}
} else {
val resolveClass = psiResolver!!.resolveClass(convertTo, context)
if (resolveClass == null) {
logger!!.error("failed to resolve class:$convertTo")
return null
}
val constants = psiClassHelper!!.parseEnumConstant(resolveClass)
if (constants.isEmpty()) {
logger!!.error("nothing be found at:$convertTo")
return null
}

return KVUtils.getConstantDesc(constants)
}
}

val enumClass = jvmClassHelper.resolveClassInType(psiType)!!
val constants = psiClassHelper!!.parseEnumConstant(enumClass)
if (constants.isEmpty()) {
logger!!.error("nothing be found at:$convertTo")
return null
}

return KVUtils.getConstantDesc(constants)
}

return null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ import com.intellij.psi.util.PsiTypesUtil
import com.itangcent.common.constant.HttpMethod
import com.itangcent.common.model.Header
import com.itangcent.common.model.Request
import com.itangcent.common.utils.KV
import com.itangcent.common.utils.any
import com.itangcent.common.utils.isNullOrEmpty
import com.itangcent.common.utils.tinyString
import com.itangcent.idea.plugin.utils.SpringClassName
import com.itangcent.intellij.jvm.AnnotationHelper
import com.itangcent.intellij.psi.ClassRuleKeys
import com.itangcent.common.utils.KV
import org.apache.commons.lang3.StringUtils

open class SpringRequestClassExporter : AbstractRequestClassExporter() {

@Inject
private val annotationHelper: AnnotationHelper? = null

@Inject
private val commentResolver: CommentResolver? = null

override fun processClass(cls: PsiClass, kv: KV<String, Any?>) {

val ctrlRequestMappingAnn = findRequestMapping(cls)
Expand Down Expand Up @@ -69,6 +72,10 @@ open class SpringRequestClassExporter : AbstractRequestClassExporter() {
return
}

var ultimateComment = (paramDesc ?: "")
commentResolver!!.resolveCommentForType(param.type, param)?.let {
ultimateComment = "$ultimateComment $it"
}
val requestHeaderAnn = findRequestHeader(param)
if (requestHeaderAnn != null) {

Expand All @@ -94,7 +101,7 @@ open class SpringRequestClassExporter : AbstractRequestClassExporter() {
header.name = headName?.toString()
header.value = defaultValue.toString()
header.example = defaultValue.toString()
header.desc = paramDesc
header.desc = ultimateComment
header.required = required
requestHelper!!.addHeader(request, header)
return
Expand All @@ -109,7 +116,7 @@ open class SpringRequestClassExporter : AbstractRequestClassExporter() {
pathName = param.name
}

requestHelper!!.addPathParam(request, pathName!!, paramDesc ?: "")
requestHelper!!.addPathParam(request, pathName!!, ultimateComment)
return
}

Expand Down Expand Up @@ -167,7 +174,7 @@ open class SpringRequestClassExporter : AbstractRequestClassExporter() {
}

requestHelper!!.addHeader(request, "Content-Type", "multipart/form-data")
requestHelper.addFormFileParam(request, paramName!!, required, paramDesc)
requestHelper.addFormFileParam(request, paramName!!, required, ultimateComment)
return
} else if (SpringClassName.SPRING_REQUEST_RESPONSE.contains(unboxType.presentableText)) {
//ignore @HttpServletRequest and @HttpServletResponse
Expand All @@ -179,15 +186,15 @@ open class SpringRequestClassExporter : AbstractRequestClassExporter() {
paramName!!
, defaultVal.toString()
, required
, paramDesc)
, ultimateComment)
} else {
if (request.method == HttpMethod.GET) {
addParamAsQuery(param, request, paramDesc)
addParamAsQuery(param, request, ultimateComment)
} else {
if (request.method == HttpMethod.NO_METHOD) {
request.method = HttpMethod.POST
}
addParamAsForm(param, request, paramDesc)
addParamAsForm(param, request, ultimateComment)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class RecommendConfigReader : ConfigReader {
json.rule.convert[org.bson.types.ObjectId]=java.lang.String
json.rule.convert[java.util.Date]=java.lang.String
json.rule.convert[java.sql.Timestamp]=java.lang.String
json.rule.convert[java.time.LocalDateTime]=java.lang.String
json.rule.convert[java.time.LocalDate]=java.lang.String
#resolve HttpEntity/RequestEntity/ResponseEntity/Mono/Flux
###set resolveProperty = false
Expand Down
2 changes: 1 addition & 1 deletion idea-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>com.itangcent.idea.plugin.easy-yapi</id>
<name>EasyYapi</name>
<version>1.1.0.183.0.1</version>
<version>1.1.0.183.0.2</version>
<vendor email="[email protected]" url="https://github.com/tangcent">Tangcent</vendor>

<description><![CDATA[ Description will be added by gradle build]]></description>
Expand Down
7 changes: 6 additions & 1 deletion plugin-script/package_plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ echo "baseDir:"${basedir}

cd ${basedir}/idea-plugin
../gradlew clean buildPlugin --stacktrace

version=`cat ${basedir}/build.gradle | grep -Eo '[0-9][0-9.]+'`
echo "version:"${version}


if [[ ! -d "$basedir/plugin" ]];then
mkdir ${basedir}/plugin
fi
mv ${basedir}/idea-plugin/build/libs/*.jar ${basedir}/plugin/easy-yapi.jar
mv ${basedir}/idea-plugin/build/libs/*.jar ${basedir}/plugin/easy-yapi.${version}.jar

0 comments on commit 1742812

Please sign in to comment.