Skip to content

Commit c6d26e0

Browse files
committed
fix: fully qualified name
1 parent 78a1812 commit c6d26e0

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/VertxEndpoint.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ import spp.jetbrains.marker.source.mark.guide.MethodGuideMark
3535

3636
class VertxEndpoint : JVMEndpointDetector.JVMEndpointNameDetector {
3737

38-
private val log = logger<VertxEndpoint>()
39-
private val httpMethods = HttpMethod.values().map { it.name() }.toSet()
40-
private val DETECTED_ENDPOINT = Key.create<EndpointDetector.DetectedEndpoint>("VertxEndpoint.DetectedEndpoint")
38+
companion object {
39+
private val log = logger<VertxEndpoint>()
40+
private val httpMethods = HttpMethod.values().map { it.name() }.toSet()
41+
private val DETECTED_ENDPOINT = Key.create<EndpointDetector.DetectedEndpoint>("VertxEndpoint.DetectedEndpoint")
42+
}
4143

4244
override fun detectEndpointNames(guideMark: GuideMark): Future<List<EndpointDetector.DetectedEndpoint>> {
4345
if (guideMark !is MethodGuideMark) {

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt

+20-6
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,10 @@ object JVMMarkerUtils {
197197
methodParams += "[]"
198198
}
199199
} else if (it.typeElement != null) {
200-
methodParams += if (it.typeElement!!.text == "String") {
201-
"java.lang.String"
202-
} else if (it.typeElement!!.text == "String[]") {
203-
"java.lang.String[]"
204-
} else {
205-
it.typeElement!!.text
200+
methodParams += findFullyQualifiedName(it.type, it.containingFile) ?: when (it.typeElement!!.text) {
201+
"String" -> "java.lang.String"
202+
"String[]" -> "java.lang.String[]"
203+
else -> it.typeElement!!.text
206204
}
207205
} else if (it.type is PsiPrimitiveType) {
208206
methodParams += if (ArtifactTypeService.isKotlin(it)) {
@@ -217,6 +215,22 @@ object JVMMarkerUtils {
217215
return "$methodName($methodParams)"
218216
}
219217

218+
/**
219+
* Search imports for a fully qualified name that ends with the simple name of the type.
220+
*/
221+
private fun findFullyQualifiedName(psiType: PsiType, psiFile: PsiFile): String? {
222+
val simpleName = psiType.presentableText
223+
val psiJavaFile = psiFile as? PsiJavaFile ?: return null
224+
val importList = psiJavaFile.importList ?: return null
225+
for (importStatement in importList.allImportStatements) {
226+
val qualifiedName = importStatement.importReference?.qualifiedName
227+
if (qualifiedName?.endsWith(".$simpleName") == true) {
228+
return qualifiedName
229+
}
230+
}
231+
return null
232+
}
233+
220234
//todo: better
221235
private fun getQualifiedName(method: KtNamedFunction): String {
222236
val methodName = method.nameIdentifier?.text ?: method.name ?: "unknown"

0 commit comments

Comments
 (0)