Skip to content

Commit

Permalink
Merge pull request #155 from tangcent/merge-easy-api
Browse files Browse the repository at this point in the history
Merge easy api
  • Loading branch information
tangcent authored Mar 11, 2020
2 parents caada4d + 1837a0e commit d06ec1a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 26 deletions.
6 changes: 3 additions & 3 deletions idea-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ dependencies {
// compile fileTree(dir: 'libs', include: ['*.jar'])


compile('com.itangcent:intellij-idea:0.4.0-SNAPSHOT') {
compile('com.itangcent:intellij-idea:0.4.1-SNAPSHOT') {
exclude group: 'com.google.inject'
exclude group: 'com.google.code.gson'
}

compile('com.itangcent:intellij-kotlin-support:0.4.0-SNAPSHOT') {
compile('com.itangcent:intellij-kotlin-support:0.4.1-SNAPSHOT') {
exclude group: 'com.google.inject'
exclude group: 'com.google.code.gson'
}

compile('com.itangcent:intellij-scala-support:0.4.0-SNAPSHOT') {
compile('com.itangcent:intellij-scala-support:0.4.1-SNAPSHOT') {
exclude group: 'com.google.inject'
exclude group: 'com.google.code.gson'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ abstract class AbstractRequestClassExporter : ClassExporter, Worker {
try {
if (typeObject == Magics.FILE_STR) {
requestHelper!!.addFormFileParam(
request, parameter.name()!!,
request, parameter.name(),
ruleComputer!!.computer(ClassExportRuleKeys.PARAM_REQUIRED, parameter) ?: false, paramDesc
)
} else if (typeObject != null && typeObject is Map<*, *>) {
Expand All @@ -545,9 +545,9 @@ abstract class AbstractRequestClassExporter : ClassExporter, Worker {
}
})
} else {
val fields = typeObject as KV<String, Any>
val comment: KV<String, Any>? = fields.getAs(Attrs.COMMENT_ATTR)
val required: KV<String, Any>? = fields.getAs(Attrs.REQUIRED_ATTR)
val fields = typeObject as KV<String, Any?>
val comment = fields.getAsKv(Attrs.COMMENT_ATTR)
val required = fields.getAsKv(Attrs.REQUIRED_ATTR)
fields.forEachValid { filedName, fieldVal ->
val fv = deepComponent(fieldVal)
if (fv == Magics.FILE_STR) {
Expand Down Expand Up @@ -610,9 +610,9 @@ abstract class AbstractRequestClassExporter : ClassExporter, Worker {
}
})
} else {
val fields = typeObject as KV<String, Any>
val comment: KV<String, Any>? = fields.getAs(Attrs.COMMENT_ATTR)
val required: KV<String, Any>? = fields.getAs(Attrs.REQUIRED_ATTR)
val fields = typeObject as KV<String, Any?>
val comment = fields.getAsKv(Attrs.COMMENT_ATTR)
val required = fields.getAsKv(Attrs.REQUIRED_ATTR)
requestHelper!!.addHeaderIfMissed(request, "Content-Type", "application/x-www-form-urlencoded")
fields.forEachValid { filedName, fieldVal ->
val fv = deepComponent(fieldVal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.itangcent.common.model.Request
import com.itangcent.common.utils.DateUtils
import com.itangcent.common.utils.KVUtils
import com.itangcent.common.utils.KitUtils
import com.itangcent.idea.plugin.api.export.DefaultDocParseHelper
import com.itangcent.idea.plugin.api.export.DocParseHelper
import com.itangcent.idea.plugin.settings.SettingBinder
import com.itangcent.idea.psi.ResourceHelper
import com.itangcent.idea.utils.ModuleHelper
Expand All @@ -30,9 +30,6 @@ class MarkdownFormatter {
@Inject
private val actionContext: ActionContext? = null

@Inject
private val docParseHelper: DefaultDocParseHelper? = null

@Inject
private val moduleHelper: ModuleHelper? = null

Expand Down Expand Up @@ -124,7 +121,7 @@ class MarkdownFormatter {

private fun parseMethodDoc(methodDoc: MethodDoc, deep: Int, handle: (String) -> Unit) {

handle("---\n")
handle("\n---\n")
handle("${hN(deep)} ${methodDoc.name}\n\n")
handle("<a id=${methodDoc.name}> </a>\n\n")

Expand Down Expand Up @@ -155,7 +152,7 @@ class MarkdownFormatter {

private fun parseRequest(request: Request, deep: Int, handle: (String) -> Unit) {

handle("---\n")
handle("\n---\n")
handle("${hN(deep)} ${request.name}\n\n")
handle("<a id=${request.name}> </a>\n\n")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import com.intellij.psi.PsiFileFactory
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.testFramework.LightVirtualFile
import com.itangcent.common.logger.traceError
import com.itangcent.idea.plugin.rule.contextOf
import com.itangcent.intellij.config.rule.RuleParser
import com.itangcent.intellij.config.rule.StringRule
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.extend.guice.PostConstruct
import com.itangcent.intellij.extend.rx.AutoComputer
import com.itangcent.intellij.jvm.PsiClassHelper
import com.itangcent.intellij.jvm.DuckTypeHelper
import com.itangcent.intellij.logger.Logger
import com.itangcent.intellij.psi.PsiClassUtils
import org.apache.commons.lang3.exception.ExceptionUtils
Expand Down Expand Up @@ -53,7 +54,7 @@ class DebugDialog : JDialog() {
var actionContext: ActionContext? = null

@Inject
var psiClassHelper: PsiClassHelper? = null
var duckTypeHelper: DuckTypeHelper? = null

@Inject
var ruleParser: RuleParser? = null
Expand Down Expand Up @@ -255,7 +256,12 @@ class DebugDialog : JDialog() {
}
val ret: String?
try {
ret = parseStringRule.compute(ruleParser!!.contextOf(scriptInfo.context!!, scriptInfo.context!!))
val context = scriptInfo.context
ret = parseStringRule.compute(
when (context) {
is PsiClass -> ruleParser!!.contextOf(duckTypeHelper!!.explicit(context))
else -> ruleParser!!.contextOf(scriptInfo.context!!, scriptInfo.context!!)
})
} catch (e: Exception) {
return "script eval failed:" + ExceptionUtils.getStackTrace(e)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.itangcent.idea.plugin.rule

import com.itangcent.intellij.config.rule.RuleComputer
import com.itangcent.intellij.config.rule.RuleContext
import com.itangcent.intellij.config.rule.RuleKey
import com.itangcent.intellij.config.rule.RuleParser
import com.itangcent.intellij.jvm.element.ExplicitElement


fun <T> RuleComputer.computer(ruleKey: RuleKey<T>, explicitElement: ExplicitElement<*>): T? {
return this.computer(ruleKey, explicitElement, explicitElement.psi())
}


fun RuleParser.contextOf(context: ExplicitElement<*>): RuleContext {
return this.contextOf(context, context.psi())
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.itangcent.common.utils.KV
import com.itangcent.idea.plugin.api.export.ClassExportRuleKeys
import com.itangcent.intellij.jvm.duck.DuckType
import com.itangcent.intellij.psi.DefaultPsiClassHelper
import com.itangcent.intellij.util.sub

/**
* 1.support rule:["field.required"]
Expand All @@ -17,12 +18,7 @@ open class CustomizedPsiClassHelper : DefaultPsiClassHelper() {
super.afterParseFieldOrMethod(fieldName, fieldType, fieldOrMethod, resourcePsiClass, option, kv)

ruleComputer!!.computer(ClassExportRuleKeys.FIELD_REQUIRED, fieldOrMethod)?.let { required ->
var requiredKV: KV<String, Any?>? = kv.getAs(Attrs.REQUIRED_ATTR)
if (requiredKV == null) {
requiredKV = KV.create()
kv[Attrs.REQUIRED_ATTR] = requiredKV
}
requiredKV[fieldName] = required
kv.sub(Attrs.REQUIRED_ATTR)[fieldName] = required
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ fun <T> Map<*, *>.getAs(key: Any?, subKey: Any?): T? {
return this.getAs<Map<*, *>>(key)?.getAs(subKey)
}

@Suppress("UNCHECKED_CAST")
fun KV<String, Any?>.getAsKv(key: String): KV<String, Any?>? {
return this[key] as KV<String, Any?>?
}

@Suppress("UNCHECKED_CAST")
fun KV<String, Any?>.sub(key: String): KV<String, Any?> {
var subKV: KV<String, Any?>? = this[key] as KV<String, Any?>?
Expand All @@ -105,7 +110,7 @@ fun KV<String, Any?>.sub(key: String): KV<String, Any?> {
}

@Suppress("UNCHECKED_CAST")
public fun <K, V> Map<out K, V>.mutable(copy: Boolean = false): MutableMap<K, V> {
fun <K, V> Map<out K, V>.mutable(copy: Boolean = false): MutableMap<K, V> {
return when {
copy -> LinkedHashMap(this)
this is MutableMap -> this as MutableMap<K, V>
Expand Down

0 comments on commit d06ec1a

Please sign in to comment.