User: joe Date: 24 Sep 23 10:05 Revision: 6a04b37ddbfe159e72fbf5e0cce97bf9cd068aa0 Summary: Merge branch '2022.3' into 2023.1 # Conflicts: # src/main/kotlin/platform/mixin/handlers/ModifyConstantHandler.kt TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=8767&personal=false Index: build.gradle.kts =================================================================== --- build.gradle.kts (revision b0c7c8c3a799cc4bdd996572333a4b1f5151248c) +++ build.gradle.kts (revision 6a04b37ddbfe159e72fbf5e0cce97bf9cd068aa0) @@ -23,6 +23,7 @@ import org.gradle.internal.jvm.Jvm import org.jetbrains.gradle.ext.settings import org.jetbrains.gradle.ext.taskTriggers +import org.jetbrains.intellij.tasks.PrepareSandboxTask import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask import org.jlleitschuh.gradle.ktlint.tasks.KtLintFormatTask @@ -71,6 +72,12 @@ archiveClassifier.set("gradle-tooling-extension") } +val externalAnnotationsJar = tasks.register("externalAnnotationsJar") { + from("externalAnnotations") + destinationDirectory.set(layout.buildDirectory.dir("externalAnnotations")) + archiveFileName.set("externalAnnotations.jar") +} + repositories { maven("https://repo.denwav.dev/repository/maven-public/") maven("https://maven.fabricmc.net/") { @@ -301,8 +308,11 @@ register("grammars") { files.from(project.fileTree("src/main/grammars")) } + register("externalAnnotations") { + files.from(project.fileTree("externalAnnotations")) - } -} + } + } +} ktlint { disabledRules.add("filename") @@ -359,6 +369,12 @@ delete(layout.projectDirectory.dir(".sandbox")) } +tasks.withType { + from(externalAnnotationsJar) { + into("Minecraft Development/lib/resources") + } +} + tasks.runIde { maxHeapSize = "4G" Index: src/main/kotlin/facet/MinecraftFacetDetector.kt =================================================================== --- src/main/kotlin/facet/MinecraftFacetDetector.kt (revision b0c7c8c3a799cc4bdd996572333a4b1f5151248c) +++ src/main/kotlin/facet/MinecraftFacetDetector.kt (revision 6a04b37ddbfe159e72fbf5e0cce97bf9cd068aa0) @@ -70,6 +70,9 @@ fun doCheck(project: Project) { val moduleManager = ModuleManager.getInstance(project) + + var needsReimport = false + for (module in moduleManager.modules) { val facetManager = FacetManager.getInstance(module) val minecraftFacet = facetManager.getFacetByType(MinecraftFacet.ID) @@ -78,10 +81,17 @@ checkNoFacet(module) } else { checkExistingFacet(module, minecraftFacet) + if (ProjectReimporter.needsReimport(minecraftFacet)) { + needsReimport = true - } - } - } + } + } + } + if (needsReimport) { + ProjectReimporter.reimport(project) + } + } + private fun checkNoFacet(module: Module) { val platforms = autoDetectTypes(module).ifEmpty { return } Index: src/main/kotlin/platform/mixin/handlers/ModifyConstantHandler.kt =================================================================== --- src/main/kotlin/platform/mixin/handlers/ModifyConstantHandler.kt (revision b0c7c8c3a799cc4bdd996572333a4b1f5151248c) +++ src/main/kotlin/platform/mixin/handlers/ModifyConstantHandler.kt (revision 6a04b37ddbfe159e72fbf5e0cce97bf9cd068aa0) @@ -20,29 +20,16 @@ package com.demonwav.mcdev.platform.mixin.handlers -import com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.CollectVisitor import com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.ConstantInjectionPoint import com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.InjectionPoint -import com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.InsnResolutionInfo import com.demonwav.mcdev.platform.mixin.inspection.injector.MethodSignature import com.demonwav.mcdev.platform.mixin.inspection.injector.ParameterGroup -import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Classes.CONSTANT_CONDITION -import com.demonwav.mcdev.platform.mixin.util.findSourceElement -import com.demonwav.mcdev.util.constantValue -import com.demonwav.mcdev.util.descriptor import com.demonwav.mcdev.util.findAnnotations -import com.demonwav.mcdev.util.fullQualifiedName -import com.demonwav.mcdev.util.parseArray -import com.demonwav.mcdev.util.resolveClass import com.intellij.psi.PsiAnnotation -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 @@ -75,70 +62,18 @@ Opcodes.IFLE, ) - private class ModifyConstantInfo( - val constantInfo: ConstantInjectionPoint.ConstantInfo, - val constantAnnotation: PsiAnnotation, - ) - - private fun getConstantInfos(modifyConstant: PsiAnnotation): List? { + private fun getConstantInfos(modifyConstant: PsiAnnotation): List? { val constants = modifyConstant.findDeclaredAttributeValue("constant") ?.findAnnotations() ?.takeIf { it.isNotEmpty() } ?: return null return constants.map { constant -> - val nullValue = constant.findDeclaredAttributeValue("nullValue")?.constantValue as? Boolean ?: false - val intValue = (constant.findDeclaredAttributeValue("intValue")?.constantValue as? Number)?.toInt() - val floatValue = (constant.findDeclaredAttributeValue("floatValue")?.constantValue as? Number)?.toFloat() - val longValue = (constant.findDeclaredAttributeValue("longValue")?.constantValue as? Number)?.toLong() - val doubleValue = (constant.findDeclaredAttributeValue("doubleValue")?.constantValue as? Number)?.toDouble() - val stringValue = constant.findDeclaredAttributeValue("stringValue")?.constantValue as? String - val classValue = constant.findDeclaredAttributeValue("classValue")?.resolveClass()?.descriptor?.let { - Type.getType( - it, - ) + (InjectionPoint.byAtCode("CONSTANT") as ConstantInjectionPoint).getConstantInfo(constant) ?: return null - } + } - - fun Boolean.toInt(): Int { - return if (this) 1 else 0 - } + } - val count = nullValue.toInt() + - (intValue != null).toInt() + - (floatValue != null).toInt() + - (longValue != null).toInt() + - (doubleValue != null).toInt() + - (stringValue != null).toInt() + - (classValue != null).toInt() - if (count != 1) { - return null - } + override fun getAtKey(annotation: PsiAnnotation) = "constant" - val value = if (nullValue) { - null - } else { - intValue ?: floatValue ?: longValue ?: doubleValue ?: stringValue ?: classValue - } - - val expandConditions = constant.findDeclaredAttributeValue("expandZeroConditions")?.parseArray { - if (it !is PsiReferenceExpression) { - return@parseArray null - } - val field = it.resolve() as? PsiEnumConstant ?: return@parseArray null - val enumClass = field.containingClass ?: return@parseArray null - if (enumClass.fullQualifiedName != CONSTANT_CONDITION) { - return@parseArray null - } - try { - ConstantInjectionPoint.ExpandCondition.valueOf(field.name) - } catch (e: IllegalArgumentException) { - null - } - }?.toSet() ?: emptySet() - - ModifyConstantInfo(ConstantInjectionPoint.ConstantInfo(value, expandConditions), constant) - } - } - override fun expectedMethodSignature( annotation: PsiAnnotation, targetClass: ClassNode, @@ -168,7 +103,7 @@ val psiManager = PsiManager.getInstance(annotation.project) return constantInfos.asSequence().map { - when (it.constantInfo.constant) { + when (it.constant) { null -> PsiType.getJavaLangObject(psiManager, annotation.resolveScope) is Int -> PsiTypes.intType() is Float -> PsiTypes.floatType() @@ -176,7 +111,7 @@ is Double -> PsiTypes.doubleType() is String -> PsiType.getJavaLangString(psiManager, annotation.resolveScope) is Type -> PsiType.getJavaLangClass(psiManager, annotation.resolveScope) - else -> throw IllegalStateException("Unknown constant type: ${it.constantInfo.constant.javaClass.name}") + else -> throw IllegalStateException("Unknown constant type: ${it.constant.javaClass.name}") } }.distinct().map { type -> MethodSignature( @@ -193,154 +128,6 @@ }.toList() } - override fun resolveForNavigation( - annotation: PsiAnnotation, - targetClass: ClassNode, - targetMethod: MethodNode, - ): List { - val targetElement = targetMethod.findSourceElement( - targetClass, - annotation.project, - GlobalSearchScope.allScope(annotation.project), - 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() - - return constantInfos.asSequence().flatMap { modifyConstantInfo -> - val collectVisitor = ConstantInjectionPoint.MyCollectVisitor( - annotation.project, - CollectVisitor.Mode.MATCH_ALL, - modifyConstantInfo.constantInfo, - ) - constantInjectionPoint.addStandardFilters( - modifyConstantInfo.constantAnnotation, - targetClass, - collectVisitor, - ) - collectVisitor.visit(targetMethod) - val bytecodeResults = collectVisitor.result - - val navigationVisitor = ConstantInjectionPoint.MyNavigationVisitor(modifyConstantInfo.constantInfo) - targetElement.accept(navigationVisitor) - - bytecodeResults.asSequence().mapNotNull { bytecodeResult -> - navigationVisitor.result.getOrNull(bytecodeResult.index) - } - }.sortedBy { it.textOffset }.toList() - } - - override fun resolveInstructions( - annotation: PsiAnnotation, - targetClass: ClassNode, - targetMethod: MethodNode, - mode: CollectVisitor.Mode, - ): List> { - 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 -> - val collectVisitor = ConstantInjectionPoint.MyCollectVisitor( - annotation.project, - mode, - modifyConstantInfo.constantInfo, - ) - constantInjectionPoint.addStandardFilters( - modifyConstantInfo.constantAnnotation, - targetClass, - collectVisitor, - ) - collectVisitor.visit(targetMethod) - collectVisitor.result.asSequence() - }.sortedBy { targetMethod.instructions.indexOf(it.insn) }.toList() - } - - override fun isUnresolved( - annotation: PsiAnnotation, - targetClass: ClassNode, - targetMethod: MethodNode, - ): 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.firstNotNullOfOrNull { modifyConstantInfo -> - val collectVisitor = ConstantInjectionPoint.MyCollectVisitor( - annotation.project, - CollectVisitor.Mode.MATCH_FIRST, - modifyConstantInfo.constantInfo, - ) - constantInjectionPoint.addStandardFilters( - modifyConstantInfo.constantAnnotation, - targetClass, - collectVisitor, - ) - collectVisitor.visit(targetMethod) - if (collectVisitor.result.isEmpty()) { - InsnResolutionInfo.Failure(collectVisitor.filterToBlame) - } else { - null - } - } - } - override fun isInsnAllowed(insn: AbstractInsnNode): Boolean { return insn.opcode in allowedOpcodes } Index: src/main/resources/META-INF/plugin.xml =================================================================== --- src/main/resources/META-INF/plugin.xml (revision b0c7c8c3a799cc4bdd996572333a4b1f5151248c) +++ src/main/resources/META-INF/plugin.xml (revision 6a04b37ddbfe159e72fbf5e0cce97bf9cd068aa0) @@ -80,6 +80,7 @@ + @@ -135,6 +136,11 @@ + + + + + @@ -147,6 +153,8 @@ + + @@ -264,6 +272,8 @@ order="before javaSkipAutopopupInStrings"/> + + @@ -483,14 +493,14 @@ groupName="Minecraft" language="JAVA" enabledByDefault="true" - level="ERROR" + level="WARNING" hasStaticDescription="true" implementationClass="com.demonwav.mcdev.translations.inspections.NoTranslationInspection"/> + + - + + - + + - + + - + + - + + - + + - + + - + + + + + +