Skip to content

Commit

Permalink
fix(java): resolve issue with resolving classes in JavaTypeUtil
Browse files Browse the repository at this point in the history
The `resolveByType` function in `JavaTypeUtil.kt` was not correctly resolving classes when the `outputType` is a `PsiClassReferenceType`. This was due to a bug where the `outputType.resolve()` was being called multiple times. This commit fixes the issue by storing the resolved class in a variable and using it for comparison and assignment. Additionally, the error message in `JavaWriteTestService.kt` was not correctly interpolating the `parentDirPath` variable. This commit fixes the issue by using string interpolation to correctly display the error message.
  • Loading branch information
phodal committed Jan 14, 2024
1 parent ea37212 commit e13fc40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions java/src/main/kotlin/cc/unitmesh/idea/service/JavaTypeUtil.kt
Expand Up @@ -9,17 +9,16 @@ object JavaTypeUtil {
private fun resolveByType(outputType: PsiType?): Map<String, PsiClass> {
val resolvedClasses = mutableMapOf<String, PsiClass>()
if (outputType is PsiClassReferenceType) {
if (outputType.parameters.isNotEmpty()) {
outputType.parameters.forEach {
if (it is PsiClassReferenceType && outputType.resolve() != null) {
resolvedClasses[it.canonicalText] = outputType.resolve()!!
}
val resolveClz = outputType.resolve()
outputType.parameters.filterIsInstance<PsiClassReferenceType>().forEach {
if (resolveClz != null) {
resolvedClasses[it.canonicalText] = resolveClz
}
}

val canonicalText = outputType.canonicalText
if (outputType.resolve() != null) {
resolvedClasses[canonicalText] = outputType.resolve()!!
if (resolveClz != null) {
resolvedClasses[canonicalText] = resolveClz
}
}

Expand Down
Expand Up @@ -46,14 +46,14 @@ class JavaWriteTestService : WriteTestService() {

// Check if the source file is in the src/main/java directory
if (!parentDirPath?.contains("/src/main/java/")!!) {
log.error("Source file is not in the src/main/java directory: ${parentDirPath}")
log.error("Source file is not in the src/main/java directory: $parentDirPath")
return null
}

var isNewFile = false

// Find the test directory
val testDirPath = parentDir.path.replace("/src/main/java/", "/src/test/java/")
val testDirPath = parentDirPath.replace("/src/main/java/", "/src/test/java/")
var testDir = LocalFileSystem.getInstance().findFileByPath(testDirPath)

if (testDir == null || !testDir.isDirectory) {
Expand Down

0 comments on commit e13fc40

Please sign in to comment.