diff options
author | Jonas Herzig <jonas@spark-squared.com> | 2021-11-12 10:30:37 +0100 |
---|---|---|
committer | Jonas Herzig <jonas@spark-squared.com> | 2021-11-12 15:23:25 +0100 |
commit | 0e7f8ea1d9ebd42bcd88506e771a8b5a1e9ba0b9 (patch) | |
tree | 626a29fd1237c072cc5e0e968291044822c610c3 /src | |
parent | f4c86df102889429d125c9c62a96a702aad562d4 (diff) | |
download | Remap-0e7f8ea1d9ebd42bcd88506e771a8b5a1e9ba0b9.tar.gz Remap-0e7f8ea1d9ebd42bcd88506e771a8b5a1e9ba0b9.tar.bz2 Remap-0e7f8ea1d9ebd42bcd88506e771a8b5a1e9ba0b9.zip |
Add `findPsiClass` method to PsiMapper
Diffstat (limited to 'src')
-rw-r--r-- | src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt index bf5ddda..29ee7cf 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt @@ -77,6 +77,12 @@ internal class PsiMapper( return Pair(result, errors) } + private fun findPsiClass(name: String, project: Project = file.project) = + JavaPsiFacade.getInstance(project).findClass( + name.replace('/', '.').replace('$', '.'), + GlobalSearchScope.allScope(project), + ) + private fun map(expr: PsiElement, field: PsiField) { val fieldName = field.name ?: return val declaringClass = field.containingClass ?: return @@ -270,10 +276,7 @@ internal class PsiMapper( if (mapped != qualifiedName) { replace(value, "\"$mapped\"") } - val psiClass = JavaPsiFacade.getInstance(file.project).findClass( - qualifiedName.replace('$', '.'), - GlobalSearchScope.allScope(file.project), - ) ?: continue + val psiClass = findPsiClass(qualifiedName) ?: continue return Pair(psiClass, mapping) } } @@ -408,10 +411,7 @@ internal class PsiMapper( val name = signature.substring(ownerEnd + 1, argsBegin) val returnType = signature.substring(argsEnd + 1) - val ownerPsi = JavaPsiFacade.getInstance(file.project).findClass( - owner.drop(1).dropLast(1).replace('/', '.').replace('$', '.'), - GlobalSearchScope.allScope(file.project), - ) + val ownerPsi = findPsiClass(owner.drop(1).dropLast(1)) val methodPsi = if (method) { val desc = signature.substring(argsBegin) ownerPsi?.findMethodsByName(name, true)?.find { ClassUtil.getAsmMethodSignature(it) == desc } |