User: rednesto Date: 16 Jul 23 21:01 Revision: d350450e76e8271ed4ef41bdcc02c5d8b43ff9bb Summary: Merge branch '2022.3' into 2023.1 TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=8656&personal=false Index: gradle.properties =================================================================== --- gradle.properties (revision d78fb0f535d2069d5a5a14f8af3094dc7075bfe9) +++ gradle.properties (revision d350450e76e8271ed4ef41bdcc02c5d8b43ff9bb) @@ -24,7 +24,7 @@ ideaVersion = 2023.1 ideaVersionName = 2023.1 -coreVersion = 1.6.7 +coreVersion = 1.6.8 downloadIdeaSources = true pluginTomlVersion = 231.8109.1 Index: src/main/kotlin/platform/mixin/handlers/ModifyConstantHandler.kt =================================================================== --- src/main/kotlin/platform/mixin/handlers/ModifyConstantHandler.kt (revision d78fb0f535d2069d5a5a14f8af3094dc7075bfe9) +++ src/main/kotlin/platform/mixin/handlers/ModifyConstantHandler.kt (revision d350450e76e8271ed4ef41bdcc02c5d8b43ff9bb) @@ -38,10 +38,12 @@ import com.intellij.psi.PsiElement import com.intellij.psi.PsiEnumConstant import com.intellij.psi.PsiManager +import com.intellij.psi.PsiMethod import com.intellij.psi.PsiReferenceExpression import com.intellij.psi.PsiType import com.intellij.psi.PsiTypes import com.intellij.psi.search.GlobalSearchScope +import com.intellij.psi.util.parentOfType import org.objectweb.asm.Opcodes import org.objectweb.asm.Type import org.objectweb.asm.tree.AbstractInsnNode @@ -142,7 +144,28 @@ targetClass: ClassNode, targetMethod: MethodNode, ): List? { - val constantInfos = getConstantInfos(annotation) ?: return null + val constantInfos = getConstantInfos(annotation) + if (constantInfos == null) { + val method = annotation.parentOfType() + ?: return emptyList() + val returnType = method.returnType + ?: return emptyList() + val constantParamName = method.parameterList.getParameter(0)?.name ?: "constant" + return listOf( + MethodSignature( + listOf( + ParameterGroup(listOf(sanitizedParameter(returnType, constantParamName))), + ParameterGroup( + collectTargetMethodParameters(annotation.project, targetClass, targetMethod), + isVarargs = true, + required = ParameterGroup.RequiredLevel.OPTIONAL, + ), + ), + returnType, + ) + ) + } + val psiManager = PsiManager.getInstance(annotation.project) return constantInfos.asSequence().map { when (it.constantInfo.constant) { @@ -175,8 +198,6 @@ targetClass: ClassNode, targetMethod: MethodNode, ): List { - val constantInfos = getConstantInfos(annotation) ?: return emptyList() - val targetElement = targetMethod.findSourceElement( targetClass, annotation.project, @@ -184,6 +205,31 @@ canDecompile = true, ) ?: return emptyList() + val constantInfos = getConstantInfos(annotation) + if (constantInfos == null) { + val returnType = annotation.parentOfType()?.returnType + ?: return emptyList() + + val collectVisitor = ConstantInjectionPoint.MyCollectVisitor( + annotation.project, + CollectVisitor.Mode.MATCH_ALL, + null, + Type.getType(returnType.descriptor) + ) + collectVisitor.visit(targetMethod) + val bytecodeResults = collectVisitor.result + + val navigationVisitor = ConstantInjectionPoint.MyNavigationVisitor( + null, + Type.getType(returnType.descriptor) + ) + targetElement.accept(navigationVisitor) + + return bytecodeResults.asSequence().mapNotNull { bytecodeResult -> + navigationVisitor.result.getOrNull(bytecodeResult.index) + }.sortedBy { it.textOffset }.toList() + } + val constantInjectionPoint = InjectionPoint.byAtCode("CONSTANT") as? ConstantInjectionPoint ?: return emptyList() @@ -216,7 +262,21 @@ targetMethod: MethodNode, mode: CollectVisitor.Mode, ): List> { - val constantInfos = getConstantInfos(annotation) ?: return emptyList() + val constantInfos = getConstantInfos(annotation) + if (constantInfos == null) { + val returnType = annotation.parentOfType()?.returnType + ?: return emptyList() + + val collectVisitor = ConstantInjectionPoint.MyCollectVisitor( + annotation.project, + mode, + null, + Type.getType(returnType.descriptor) + ) + collectVisitor.visit(targetMethod) + return collectVisitor.result.sortedBy { targetMethod.instructions.indexOf(it.insn) } + } + val constantInjectionPoint = InjectionPoint.byAtCode("CONSTANT") as? ConstantInjectionPoint ?: return emptyList() return constantInfos.asSequence().flatMap { modifyConstantInfo -> @@ -240,10 +300,28 @@ targetClass: ClassNode, targetMethod: MethodNode, ): InsnResolutionInfo.Failure? { - val constantInfos = getConstantInfos(annotation) ?: return InsnResolutionInfo.Failure() + val constantInfos = getConstantInfos(annotation) + if (constantInfos == null) { + val returnType = annotation.parentOfType()?.returnType + ?: return InsnResolutionInfo.Failure() + + val collectVisitor = ConstantInjectionPoint.MyCollectVisitor( + annotation.project, + CollectVisitor.Mode.MATCH_FIRST, + null, + Type.getType(returnType.descriptor) + ) + collectVisitor.visit(targetMethod) + return if (collectVisitor.result.isEmpty()) { + InsnResolutionInfo.Failure(collectVisitor.filterToBlame) + } else { + null + } + } + val constantInjectionPoint = InjectionPoint.byAtCode("CONSTANT") as? ConstantInjectionPoint ?: return null - return constantInfos.asSequence().mapNotNull { modifyConstantInfo -> + return constantInfos.firstNotNullOfOrNull { modifyConstantInfo -> val collectVisitor = ConstantInjectionPoint.MyCollectVisitor( annotation.project, CollectVisitor.Mode.MATCH_FIRST, @@ -256,12 +334,12 @@ ) collectVisitor.visit(targetMethod) if (collectVisitor.result.isEmpty()) { - collectVisitor.filterToBlame + InsnResolutionInfo.Failure(collectVisitor.filterToBlame) } else { null } - }.firstOrNull()?.let(InsnResolutionInfo::Failure) - } + } + } override fun isInsnAllowed(insn: AbstractInsnNode): Boolean { return insn.opcode in allowedOpcodes Index: src/main/kotlin/platform/sponge/reference/SpongeReferenceContributor.kt =================================================================== --- src/main/kotlin/platform/sponge/reference/SpongeReferenceContributor.kt (revision d78fb0f535d2069d5a5a14f8af3094dc7075bfe9) +++ src/main/kotlin/platform/sponge/reference/SpongeReferenceContributor.kt (revision d350450e76e8271ed4ef41bdcc02c5d8b43ff9bb) @@ -22,6 +22,7 @@ import com.demonwav.mcdev.insight.uastEventListener import com.demonwav.mcdev.platform.sponge.util.SpongeConstants +import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions import com.intellij.codeInsight.completion.JavaLookupElementBuilder import com.intellij.patterns.PlatformPatterns import com.intellij.psi.CommonClassNames @@ -98,7 +99,7 @@ private object GetterAnnotationFilter : ElementFilter { override fun isAcceptable(element: Any, context: PsiElement?): Boolean { val type = context.toUElement() ?: return false - val annotation = type.getParentOfType() ?: return false + val annotation = runCatchingKtIdeaExceptions { type.getParentOfType() } ?: return false return annotation.qualifiedName == SpongeConstants.GETTER_ANNOTATION }