-
Notifications
You must be signed in to change notification settings - Fork 251
fix(amazonq): do not model types that are directly passthrough to chat ui #5702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
4af9d17
bfad5e1
855afd6
4d99a80
34efb26
ebf94f9
3661d25
1ed1c5e
c488f60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
@file:Suppress("BannedImports") | ||
package software.aws.toolkits.jetbrains.services.amazonq.lsp.model | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue | ||
import com.google.gson.Gson | ||
import com.google.gson.TypeAdapter | ||
import com.google.gson.TypeAdapterFactory | ||
import com.google.gson.reflect.TypeToken | ||
|
||
/** | ||
* A [Gson] [TypeAdapterFactory] that uses Jackson @[JsonValue] instead of [Enum.name] for de/serialization | ||
*/ | ||
class EnumJsonValueAdapter : TypeAdapterFactory { | ||
Check warning on line 15 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/EnumJsonValueAdapter.kt
|
||
override fun <T> create( | ||
gson: Gson, | ||
type: TypeToken<T>, | ||
): TypeAdapter<T>? { | ||
val rawType = type.getRawType() | ||
Check warning on line 20 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/EnumJsonValueAdapter.kt
|
||
if (!rawType.isEnum) { | ||
return null | ||
Check warning on line 22 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/EnumJsonValueAdapter.kt
|
||
} | ||
|
||
val jsonField = rawType.declaredFields.firstOrNull { it.isAnnotationPresent(JsonValue::class.java) } | ||
?: return null | ||
Check warning on line 26 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/EnumJsonValueAdapter.kt
|
||
|
||
jsonField.isAccessible = true | ||
Check warning on line 28 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/EnumJsonValueAdapter.kt
|
||
|
||
return object : TypeAdapter<T>() { | ||
Check warning on line 30 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/EnumJsonValueAdapter.kt
|
||
override fun write(out: com.google.gson.stream.JsonWriter, value: T) { | ||
val result = jsonField.get(value) as Any | ||
(gson.getAdapter(result::class.java) as TypeAdapter<Any>).write(out, result) | ||
} | ||
Check warning on line 34 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/EnumJsonValueAdapter.kt
|
||
|
||
override fun read(`in`: com.google.gson.stream.JsonReader): T { | ||
val jsonValue = `in`.nextString() | ||
return rawType.enumConstants.first { jsonField.get(it).toString() == jsonValue } as T | ||
Check warning on line 38 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/EnumJsonValueAdapter.kt
|
||
} | ||
} as TypeAdapter<T> | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ data class UpdateConfigurationParams( | |
val settings: LSPAny, | ||
) | ||
|
||
typealias LSPAny = Any? | ||
typealias LSPAny = Any |
This file was deleted.
Check warning
Code scanning / QDJVMC
Unused symbol Warning