Skip to content

Commit 244ec6d

Browse files
committed
Change Fabric Mixin detection.
NeoForge now uses Fabric Mixin
1 parent fec33cc commit 244ec6d

File tree

7 files changed

+16
-40
lines changed

7 files changed

+16
-40
lines changed

src/main/kotlin/platform/fabric/util/fabric-util.kt

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/kotlin/platform/mixin/handlers/injectionPoint/CtorHeadInjectionPoint.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
package com.demonwav.mcdev.platform.mixin.handlers.injectionPoint
2222

23-
import com.demonwav.mcdev.platform.fabric.util.isFabric
2423
import com.demonwav.mcdev.platform.mixin.inspection.injector.CtorHeadNoUnsafeInspection
2524
import com.demonwav.mcdev.platform.mixin.reference.MixinSelector
2625
import com.demonwav.mcdev.platform.mixin.util.findOrConstructSourceMethod
2726
import com.demonwav.mcdev.platform.mixin.util.findSuperConstructorCall
2827
import com.demonwav.mcdev.platform.mixin.util.isConstructor
28+
import com.demonwav.mcdev.platform.mixin.util.isFabricMixin
2929
import com.demonwav.mcdev.util.createLiteralExpression
3030
import com.demonwav.mcdev.util.enumValueOfOrNull
3131
import com.demonwav.mcdev.util.findContainingClass
@@ -67,7 +67,7 @@ class CtorHeadInjectionPoint : InjectionPoint<PsiElement>() {
6767
// avoid adding unsafe = true when it's unnecessary on Fabric
6868
val noUnsafeInspection =
6969
project.findInspection<CtorHeadNoUnsafeInspection>(CtorHeadNoUnsafeInspection.SHORT_NAME)
70-
if (reference.isFabric && noUnsafeInspection?.ignoreForFabric == true) {
70+
if (reference.isFabricMixin && noUnsafeInspection?.ignoreForFabric == true) {
7171
return
7272
}
7373

src/main/kotlin/platform/mixin/inspection/injector/CtorHeadNoUnsafeInspection.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
package com.demonwav.mcdev.platform.mixin.inspection.injector
2222

23-
import com.demonwav.mcdev.platform.fabric.util.isFabric
2423
import com.demonwav.mcdev.platform.mixin.inspection.MixinInspection
2524
import com.demonwav.mcdev.platform.mixin.inspection.fix.AnnotationAttributeFix
2625
import com.demonwav.mcdev.platform.mixin.util.MixinConstants
26+
import com.demonwav.mcdev.platform.mixin.util.isFabricMixin
2727
import com.demonwav.mcdev.util.constantStringValue
2828
import com.demonwav.mcdev.util.constantValue
2929
import com.intellij.codeInspection.ProblemsHolder
@@ -41,7 +41,7 @@ class CtorHeadNoUnsafeInspection : MixinInspection() {
4141

4242
override fun createOptionsPanel(): JComponent {
4343
val panel = JPanel(FlowLayout(FlowLayout.LEFT))
44-
val checkbox = JCheckBox("Ignore in Fabric mods", ignoreForFabric)
44+
val checkbox = JCheckBox("Ignore when Fabric Mixin is present", ignoreForFabric)
4545
checkbox.addActionListener {
4646
ignoreForFabric = checkbox.isSelected
4747
}
@@ -53,7 +53,7 @@ class CtorHeadNoUnsafeInspection : MixinInspection() {
5353

5454
override fun buildVisitor(holder: ProblemsHolder): PsiElementVisitor {
5555
if (ignoreForFabric) {
56-
val isFabric = holder.file.isFabric
56+
val isFabric = holder.file.isFabricMixin
5757
if (isFabric) {
5858
return PsiElementVisitor.EMPTY_VISITOR
5959
}

src/main/kotlin/platform/mixin/inspection/injector/InjectIntoConstructorInspection.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
package com.demonwav.mcdev.platform.mixin.inspection.injector
2222

23-
import com.demonwav.mcdev.platform.fabric.util.isFabric
2423
import com.demonwav.mcdev.platform.mixin.handlers.InjectorAnnotationHandler
2524
import com.demonwav.mcdev.platform.mixin.handlers.MixinAnnotationHandler
2625
import com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.AtResolver
@@ -30,6 +29,7 @@ import com.demonwav.mcdev.platform.mixin.util.MethodTargetMember
3029
import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.INJECT
3130
import com.demonwav.mcdev.platform.mixin.util.findSuperConstructorCall
3231
import com.demonwav.mcdev.platform.mixin.util.isConstructor
32+
import com.demonwav.mcdev.platform.mixin.util.isFabricMixin
3333
import com.demonwav.mcdev.util.constantValue
3434
import com.demonwav.mcdev.util.findAnnotation
3535
import com.demonwav.mcdev.util.findAnnotations
@@ -50,7 +50,7 @@ class InjectIntoConstructorInspection : MixinInspection() {
5050

5151
override fun createOptionsPanel(): JComponent {
5252
val panel = JPanel(FlowLayout(FlowLayout.LEFT))
53-
val checkbox = JCheckBox("Always allow @Inject into constructors in Fabric", allowOnFabric)
53+
val checkbox = JCheckBox("Allow @Inject into constructors when Fabric Mixin is present", allowOnFabric)
5454
checkbox.addActionListener {
5555
allowOnFabric = checkbox.isSelected
5656
}
@@ -59,7 +59,7 @@ class InjectIntoConstructorInspection : MixinInspection() {
5959
}
6060

6161
override fun buildVisitor(holder: ProblemsHolder): PsiElementVisitor {
62-
val isFabric = holder.file.isFabric
62+
val isFabric = holder.file.isFabricMixin
6363
return object : JavaElementVisitor() {
6464
override fun visitMethod(method: PsiMethod) {
6565
val injectAnnotation = method.findAnnotation(INJECT) ?: return

src/main/kotlin/platform/mixin/inspection/injector/UnnecessaryUnsafeInspection.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
package com.demonwav.mcdev.platform.mixin.inspection.injector
2222

23-
import com.demonwav.mcdev.platform.fabric.util.isFabric
2423
import com.demonwav.mcdev.platform.mixin.handlers.MixinAnnotationHandler
2524
import com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.AtResolver
2625
import com.demonwav.mcdev.platform.mixin.inspection.MixinInspection
2726
import com.demonwav.mcdev.platform.mixin.inspection.fix.AnnotationAttributeFix
2827
import com.demonwav.mcdev.platform.mixin.util.MethodTargetMember
2928
import com.demonwav.mcdev.platform.mixin.util.MixinConstants
3029
import com.demonwav.mcdev.platform.mixin.util.isConstructor
30+
import com.demonwav.mcdev.platform.mixin.util.isFabricMixin
3131
import com.demonwav.mcdev.util.constantValue
3232
import com.demonwav.mcdev.util.findInspection
3333
import com.demonwav.mcdev.util.ifEmpty
@@ -49,7 +49,7 @@ class UnnecessaryUnsafeInspection : MixinInspection() {
4949

5050
override fun createOptionsPanel(): JComponent {
5151
val panel = JPanel(FlowLayout(FlowLayout.LEFT))
52-
val checkbox = JCheckBox("Always unnecessary in Fabric mods", alwaysUnnecessaryOnFabric)
52+
val checkbox = JCheckBox("Always unnecessary when Fabric Mixin is present", alwaysUnnecessaryOnFabric)
5353
checkbox.addActionListener {
5454
alwaysUnnecessaryOnFabric = checkbox.isSelected
5555
}
@@ -58,7 +58,7 @@ class UnnecessaryUnsafeInspection : MixinInspection() {
5858
}
5959

6060
override fun buildVisitor(holder: ProblemsHolder): PsiElementVisitor {
61-
val isFabric = holder.file.isFabric
61+
val isFabric = holder.file.isFabricMixin
6262
val alwaysUnnecessary = isFabric && alwaysUnnecessaryOnFabric
6363
val requiresUnsafeForCtorHeadOnFabric =
6464
holder.project.findInspection<CtorHeadNoUnsafeInspection>(CtorHeadNoUnsafeInspection.SHORT_NAME)

src/main/kotlin/platform/mixin/util/Mixin.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,6 @@ fun isMixinEntryPoint(element: PsiElement?): Boolean {
234234
}
235235
return false
236236
}
237+
238+
val PsiElement.isFabricMixin: Boolean get() =
239+
JavaPsiFacade.getInstance(project).findClass(MixinConstants.Classes.FABRIC_UTIL, resolveScope) != null

src/main/kotlin/platform/mixin/util/MixinConstants.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ object MixinConstants {
4747

4848
const val SERIALIZED_NAME = "com.google.gson.annotations.SerializedName"
4949
const val MIXIN_SERIALIZED_NAME = "org.spongepowered.include.$SERIALIZED_NAME"
50+
51+
const val FABRIC_UTIL = "org.spongepowered.asm.mixin.FabricUtil"
5052
}
5153

5254
object Annotations {

0 commit comments

Comments
 (0)