Skip to content

Commit

Permalink
Simplify PsiType creation
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Jan 10, 2024
1 parent 24042da commit bb8b39b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
package com.demonwav.mcdev.platform.mixin.handlers.mixinextras

import com.demonwav.mcdev.platform.mixin.inspection.injector.ParameterGroup
import com.demonwav.mcdev.platform.mixin.util.MixinConstants
import com.demonwav.mcdev.platform.mixin.util.MixinConstants.MixinExtras.OPERATION
import com.demonwav.mcdev.util.Parameter
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiPrimitiveType
import com.intellij.psi.PsiType
import com.intellij.psi.search.GlobalSearchScope
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode
Expand Down Expand Up @@ -64,9 +63,8 @@ class WrapOperationHandler : MixinExtrasInjectorAnnotationHandler() {
} else {
type
}
val psiClass = JavaPsiFacade.getInstance(project)
.findClass(MixinConstants.MixinExtras.OPERATION, GlobalSearchScope.allScope(project))
?: return null
return JavaPsiFacade.getElementFactory(project).createType(psiClass, boxedType)

return JavaPsiFacade.getElementFactory(project)
.createTypeFromText("$OPERATION<${boxedType.canonicalText}>", context)
}
}
7 changes: 2 additions & 5 deletions src/main/kotlin/platform/mixin/util/Mixin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,8 @@ fun callbackInfoReturnableType(project: Project, context: PsiElement, returnType
returnType
}

// TODO: Can we do this without looking up the PsiClass?
val psiClass =
JavaPsiFacade.getInstance(project).findClass(CALLBACK_INFO_RETURNABLE, GlobalSearchScope.allScope(project))
?: return null
return JavaPsiFacade.getElementFactory(project).createType(psiClass, boxedType)
return JavaPsiFacade.getElementFactory(project)
.createTypeFromText("$CALLBACK_INFO_RETURNABLE<${boxedType.canonicalText}>", context)
}

fun isAssignable(left: PsiType, right: PsiType, allowPrimitiveConversion: Boolean = true): Boolean {
Expand Down

0 comments on commit bb8b39b

Please sign in to comment.