Skip to content

Commit

Permalink
chore: fix compatibility issues in compatibility verification (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangcent authored Mar 31, 2024
1 parent 38eb9f6 commit bd8cdc1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ class DefaultMethodInferHelper : MethodInferHelper {
private fun getSimpleFields(psiType: PsiType?, context: PsiElement): Any? {
actionContext!!.checkStatus()
when {
psiType == null || psiType == PsiType.VOID -> return null
psiType == null -> return null
psiType is PsiPrimitiveType -> return PsiTypesUtil.getDefaultValue(psiType)
psiClassHelper!!.isNormalType(psiType) -> return psiClassHelper.getDefaultValue(psiType)
psiType is PsiArrayType -> {
Expand Down Expand Up @@ -764,7 +764,7 @@ class DefaultMethodInferHelper : MethodInferHelper {
}
actionContext!!.checkStatus()
when {
psiType == null || psiType == PsiType.VOID -> return null
psiType == null -> return null
psiType is PsiPrimitiveType -> return PsiTypesUtil.getDefaultValue(psiType)
psiClassHelper!!.isNormalType(psiType) -> return psiClassHelper.getDefaultValue(psiType)
psiType is PsiArrayType -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.itangcent.idea.plugin.api.export.condition.ConditionOnSimple
import com.itangcent.idea.plugin.api.export.core.*
import com.itangcent.idea.plugin.api.export.spring.SpringRequestClassExporter
import com.itangcent.idea.plugin.condition.ConditionOnSetting
import org.apache.commons.lang.StringUtils.lowerCase

/**
* Support export apis from client that annotated with @FeignClient
Expand Down Expand Up @@ -104,7 +103,7 @@ open class FeignRequestClassExporter : SpringRequestClassExporter() {
val name = it.first
val value = it.second.trim()
if (name.equalIgnoreCase("content-type")) {
if (lowerCase(value).contains("application/json")) {
if (value.lowercase().contains("application/json")) {
methodExportContext.setExt("paramType", "body")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import com.intellij.util.io.createDirectories
import com.intellij.util.io.readText
import com.itangcent.intellij.context.ActionContext
import java.io.IOException
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.io.path.readText
import kotlin.io.path.writeText

/**
Expand Down Expand Up @@ -67,7 +69,7 @@ class HttpClientFileSaver {
val file = scratchesPath.resolve(module).resolve(fileName).apply {
parent.createDirectories()
}
file.writeText(content(file.takeIf { Files.exists(it) }?.readText()))
file.writeText(content(file.takeIf { Files.exists(it) }?.readText(StandardCharsets.UTF_8)))

return (localFileSystem.refreshAndFindFileByPath(file.toString())
?: throw IOException("Unable to find file: $file"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.itangcent.idea.utils

import com.google.gson.JsonParser
import com.itangcent.common.utils.GsonUtils

@Deprecated(replaceWith = ReplaceWith("GsonUtils"), message = "use GsonUtils")
typealias GsonExUtils = GsonUtils

fun GsonUtils.prettyJsonStr(json: String): String {
val jsonParser = JsonParser()
val jsonObject = jsonParser.parse(json).asJsonObject
return GsonUtils.prettyJson(jsonObject)
val jsonObject = parseToJsonTree(json)
return prettyJson(jsonObject)
}

fun String.resolveGsonLazily(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package com.itangcent.utils

import com.itangcent.common.constant.Attrs
import com.itangcent.common.utils.Extensible
import com.itangcent.common.utils.mapToTypedArray
import com.itangcent.common.utils.GsonUtils
import com.itangcent.intellij.extend.unbox
import kotlin.reflect.KClass

object ExtensibleKit {

private val JSON_PARSER = com.google.gson.JsonParser()
private val GSON = com.google.gson.Gson()

fun <T : Extensible> KClass<T>.fromJson(json: String): T {
val jsonElement = JSON_PARSER.parse(json)
val jsonElement = GsonUtils.parseToJsonTree(json)!!
val t = GSON.fromJson(jsonElement, this.java)
jsonElement.asJsonObject.entrySet()
.filter { it.key.startsWith(Attrs.PREFIX) }
Expand All @@ -24,7 +23,7 @@ object ExtensibleKit {
val extNames = exts.toSet() +
exts.map { it.removePrefix(Attrs.PREFIX) } +
exts.map { it.addPrefix(Attrs.PREFIX) }
val jsonElement = JSON_PARSER.parse(json)
val jsonElement = GsonUtils.parseToJsonTree(json)!!
val t = GSON.fromJson(jsonElement, this.java)
jsonElement.asJsonObject.entrySet()
.filter { extNames.contains(it.key) }
Expand Down

0 comments on commit bd8cdc1

Please sign in to comment.