⁠
llamalad7: Feature/method signature intersection (#2647 )
* Refactor: Rework expected MethodSignatures.
- ParameterGroups are gone, with every signature now effectively containing a required leading group and an optional vararg trailing group. The prior flexibility made working them easy to get wrong, for example in the matching logic which would have been incorrect for leading vararg groups.
- Inject previously contained 2 optional groups (the target's params and the captured locals) but this was in fact incorrect, since the captured params are required if we want to capture any locals, so it is now (better) represented as 2 separate signature options.
- The distinction between `WARN_IF_ABSENT` and `ERROR_IF_ABSENT` is entirely removed. It was effectively unused since it only applied to captured Inject locals, which are varargs and therefore never "absent" (a separate inspection handles unused LocalCapture).
- ModifyArgs is in fact all-or-nothing wrt capturing the target parameters, and this is now reflected.
* Fix: Disallow non-int int-like types in @ModifyConstant.
Not sure why these are there, Mixin doesn't allow them.
* Fix: Disallow `nullValue` in `@ModifyConstant`.
It does not work and cannot ever work.
* stash
* stash
* finish general intersection
* cleanup
* stash
* stash
* fix general intersection
* stash
* fix tests
* return type only suggestions
* prioritise existing return type in modifier suggestions
* restore BeforeConstant's behaviour of ensuring only 1 discriminator is specified, and supporting wildcard matches
* Fix: Support `.class` constants in `@ModifyConstant`.
* Switch `@ModifyConstant` to a general signature type.
* int coercion kinda fixed ish
* fix int coercion properly
* cleanup
* proper int-like logic
* cleanup
* some docs and fixes
* fix return type solving
* Cache walked supertypes and improve handling of Object as a supertype.
* Cleanup
* Cleanup
* Small fixes
* Small fixes
* Fix: Suggest "ci" for coerced callba...
* Refactor: Rework expected MethodSignatures.
- ParameterGroups are gone, with every signature now effectively containing a required leading group and an optional vararg trailing group. The prior flexibility made working them easy to get wrong, for example in the matching logic which would have been incorrect for leading vararg groups.
- Inject previously contained 2 optional groups (the target's params and the captured locals) but this was in fact incorrect, since the captured params are required if we want to capture any locals, so it is now (better) represented as 2 separate signature options.
- The distinction between `WARN_IF_ABSENT` and `ERROR_IF_ABSENT` is entirely removed. It was effectively unused since it only applied to captured Inject locals, which are varargs and therefore never "absent" (a separate inspection handles unused LocalCapture).
- ModifyArgs is in fact all-or-nothing wrt capturing the target parameters, and this is now reflected.
* Fix: Disallow non-int int-like types in @ModifyConstant.
Not sure why these are there, Mixin doesn't allow them.
* Fix: Disallow `nullValue` in `@ModifyConstant`.
It does not work and cannot ever work.
* stash
* stash
* finish general intersection
* cleanup
* stash
* stash
* fix general intersection
* stash
* fix tests
* return type only suggestions
* prioritise existing return type in modifier suggestions
* restore BeforeConstant's behaviour of ensuring only 1 discriminator is specified, and supporting wildcard matches
* Fix: Support `.class` constants in `@ModifyConstant`.
* Switch `@ModifyConstant` to a general signature type.
* int coercion kinda fixed ish
* fix int coercion properly
* cleanup
* proper int-like logic
* cleanup
* some docs and fixes
* fix return type solving
* Cache walked supertypes and improve handling of Object as a supertype.
* Cleanup
* Cleanup
* Small fixes
* Small fixes
* Fix: Suggest "ci" for coerced callba...
- /*
- * Minecraft Development for IntelliJ
- *
- * https://mcdev.io/
- *
- * Copyright (C) 2025 minecraft-dev
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation, version 3.0 only.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
- package com.demonwav.mcdev.platform.mixin
-
- import com.demonwav.mcdev.framework.EdtInterceptor
- import com.demonwav.mcdev.framework.testInspectionFix
- import com.demonwav.mcdev.platform.mixin.inspection.injector.InvalidInjectorMethodSignatureInspection
- import org.junit.jupiter.api.DisplayName
- import org.junit.jupiter.api.Test
- import org.junit.jupiter.api.extension.ExtendWith
-
- @ExtendWith(EdtInterceptor::class)
- @DisplayName("Invalid Injector Method Signature Inspection Test")
- class InvalidInjectorMethodSignatureFixTest : BaseMixinTest() {
-
- private fun doTest(testName: String) {
- fixture.enableInspections(InvalidInjectorMethodSignatureInspection::class)
- testInspectionFix(fixture, "invalidInjectorMethodSignature/$testName", "Fix method signature")
- }
-
- @Test
- @DisplayName("Simple case")
- fun simpleCase() = doTest("simpleCase")
-
- @Test
- @DisplayName("Simple case with MixinExtras Sugar")
- fun simpleCaseWithMixinExtrasSugar() = doTest("simpleCaseWithMixinExtrasSugar")
-
- @Test
- @DisplayName("With captured locals")
- fun withCapturedLocals() = doTest("withCapturedLocals")
-
- @Test
- @DisplayName("Simple inner ctor")
- fun simpleInnerCtor() = doTest("simpleInnerCtor")
-
- @Test
- @DisplayName("Inner ctor with locals")
- fun innerCtorWithLocals() = doTest("innerCtorWithLocals")
-
- @Test
- @DisplayName("Inject without CallbackInfo")
- fun injectWithoutCI() = doTest("injectWithoutCI")
-
- @Test
- @DisplayName("ModifyArgs")
- fun modifyArgs() = doTest("modifyArgs")
-
- @Test
- @DisplayName("Generic method")
- fun genericCase() = doTest("genericCase")
-
- @Test
- @DisplayName("Generic method complex return type")
- fun genericCaseComplexReturnType() = doTest("genericCaseComplexReturnType")
-
- @Test
- @DisplayName("Simple method with inner type")
- fun simpleMethodWithInnerType() = doTest("simpleMethodWithInnerType")
- }
- /*
- * Minecraft Development for IntelliJ
- *
- * https://mcdev.io/
- *
- * Copyright (C) 2026 minecraft-dev
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation, version 3.0 only.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
- package com.demonwav.mcdev.platform.mixin
-
- import com.demonwav.mcdev.framework.EdtInterceptor
- import com.demonwav.mcdev.framework.testAllInspectionFixes
- import com.demonwav.mcdev.framework.testInspectionFix
- import com.demonwav.mcdev.platform.mixin.inspection.injector.InvalidInjectorMethodSignatureInspection
- import org.junit.jupiter.api.DisplayName
- import org.junit.jupiter.api.Test
- import org.junit.jupiter.api.extension.ExtendWith
-
- @ExtendWith(EdtInterceptor::class)
- @DisplayName("Invalid Injector Method Signature Inspection Test")
- class InvalidInjectorMethodSignatureFixTest : BaseMixinTest() {
-
- private fun doSingleTest(testName: String) {
- fixture.enableInspections(InvalidInjectorMethodSignatureInspection::class)
- testInspectionFix(fixture, "invalidInjectorMethodSignature/$testName", "Fix method signature")
- }
-
- private fun doMultiTest(testName: String) {
- fixture.enableInspections(InvalidInjectorMethodSignatureInspection::class)
- testAllInspectionFixes(fixture, "invalidInjectorMethodSignature/$testName", "Fix method signature")
- }
-
- @Test
- @DisplayName("Inject simple case")
- fun injectSimpleCase() = doSingleTest("inject/simpleCase")
-
- @Test
- @DisplayName("Inject simple case with MixinExtras Sugar")
- fun injectSimpleCaseWithMixinExtrasSugar() = doSingleTest("inject/simpleCaseWithMixinExtrasSugar")
-
- @Test
- @DisplayName("Inject with captured locals")
- fun injectWithCapturedLocals() = doSingleTest("inject/withCapturedLocals")
-
- @Test
- @DisplayName("Inject simple inner ctor")
- fun injectSimpleInnerCtor() = doSingleTest("inject/simpleInnerCtor")
-
- @Test
- @DisplayName("Inject inner ctor with locals")
- fun injectInnerCtorWithLocals() = doSingleTest("inject/innerCtorWithLocals")
-
- @Test
- @DisplayName("Inject without CallbackInfo")
- fun injectWithoutCI() = doSingleTest("inject/withoutCI")
-
- @Test
- @DisplayName("Inject generic method")
- fun injectGenericCase() = doSingleTest("inject/genericCase")
-
- @Test
- @DisplayName("Inject generic method complex return type")
- fun injectGenericCaseComplexReturnType() = doSingleTest("inject/genericCaseComplexReturnType")
-
- @Test
- @DisplayName("Inject simple method with inner type")
- fun injectSimpleMethodWithInnerType() = doSingleTest("inject/simpleMethodWithInnerType")
-
- @Test
- @DisplayName("ModifyArgs simple")
- fun modifyArgsSimple() = doSingleTest("modifyargs/simple")
-
- @Test
- @DisplayName("ModifyArgs return type only")
- fun modifyArgsReturnTypeOnly() = doSingleTest("modifyargs/returnTypeOnly")
-
- @Test
- @DisplayName("Inject multi-target")
- fun injectMultiTarget() = doMultiTest("inject/multiTarget")
-
- @Test
- @DisplayName("ModifyArg")
- fun modifyArg() = doMultiTest("modifyArg")
-
- @Test
- @DisplayName("ModifyVariable")
- fun modifyVariable() = doMultiTest("modifyVariable")
-
- @Test
- @DisplayName("WrapMethod")
- fun wrapMethod() = doMultiTest("wrapMethod")
-
- @Test
- @DisplayName("ModifyReturnValue")
- fun modifyReturnValue() = doMultiTest("modifyReturnValue")
-
- @Test
- @DisplayName("ModifyExpressionValue")
- fun modifyExpressionValue() = doMultiTest("modifyExpressionValue")
-
- @Test
- @DisplayName("ModifyConstant")
- fun modifyConstant() = doMultiTest("modifyConstant")
-
- @Test
- @DisplayName("ModifyReceiver")
- fun modifyReceiver() = doMultiTest("modifyReceiver")
-
- @Test
- @DisplayName("WrapWithCondition")
- fun wrapWithCondition() = doMultiTest("wrapWithCondition")
-
- @Test
- @DisplayName("Redirect")
- fun redirect() = doMultiTest("redirect")
-
- @Test
- @DisplayName("WrapOperation")
- fun wrapOperation() = doMultiTest("wrapOperation")
- }