Skip to content

Commit

Permalink
Change Fabric Mixin detection.
Browse files Browse the repository at this point in the history
NeoForge now uses Fabric Mixin
  • Loading branch information
Earthcomputer committed Mar 8, 2024
1 parent fec33cc commit 244ec6d
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 40 deletions.
29 changes: 0 additions & 29 deletions src/main/kotlin/platform/fabric/util/fabric-util.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

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

import com.demonwav.mcdev.platform.fabric.util.isFabric
import com.demonwav.mcdev.platform.mixin.inspection.injector.CtorHeadNoUnsafeInspection
import com.demonwav.mcdev.platform.mixin.reference.MixinSelector
import com.demonwav.mcdev.platform.mixin.util.findOrConstructSourceMethod
import com.demonwav.mcdev.platform.mixin.util.findSuperConstructorCall
import com.demonwav.mcdev.platform.mixin.util.isConstructor
import com.demonwav.mcdev.platform.mixin.util.isFabricMixin
import com.demonwav.mcdev.util.createLiteralExpression
import com.demonwav.mcdev.util.enumValueOfOrNull
import com.demonwav.mcdev.util.findContainingClass
Expand Down Expand Up @@ -67,7 +67,7 @@ class CtorHeadInjectionPoint : InjectionPoint<PsiElement>() {
// avoid adding unsafe = true when it's unnecessary on Fabric
val noUnsafeInspection =
project.findInspection<CtorHeadNoUnsafeInspection>(CtorHeadNoUnsafeInspection.SHORT_NAME)
if (reference.isFabric && noUnsafeInspection?.ignoreForFabric == true) {
if (reference.isFabricMixin && noUnsafeInspection?.ignoreForFabric == true) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

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

import com.demonwav.mcdev.platform.fabric.util.isFabric
import com.demonwav.mcdev.platform.mixin.inspection.MixinInspection
import com.demonwav.mcdev.platform.mixin.inspection.fix.AnnotationAttributeFix
import com.demonwav.mcdev.platform.mixin.util.MixinConstants
import com.demonwav.mcdev.platform.mixin.util.isFabricMixin
import com.demonwav.mcdev.util.constantStringValue
import com.demonwav.mcdev.util.constantValue
import com.intellij.codeInspection.ProblemsHolder
Expand All @@ -41,7 +41,7 @@ class CtorHeadNoUnsafeInspection : MixinInspection() {

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

override fun buildVisitor(holder: ProblemsHolder): PsiElementVisitor {
if (ignoreForFabric) {
val isFabric = holder.file.isFabric
val isFabric = holder.file.isFabricMixin
if (isFabric) {
return PsiElementVisitor.EMPTY_VISITOR
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

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

import com.demonwav.mcdev.platform.fabric.util.isFabric
import com.demonwav.mcdev.platform.mixin.handlers.InjectorAnnotationHandler
import com.demonwav.mcdev.platform.mixin.handlers.MixinAnnotationHandler
import com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.AtResolver
Expand All @@ -30,6 +29,7 @@ import com.demonwav.mcdev.platform.mixin.util.MethodTargetMember
import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.INJECT
import com.demonwav.mcdev.platform.mixin.util.findSuperConstructorCall
import com.demonwav.mcdev.platform.mixin.util.isConstructor
import com.demonwav.mcdev.platform.mixin.util.isFabricMixin
import com.demonwav.mcdev.util.constantValue
import com.demonwav.mcdev.util.findAnnotation
import com.demonwav.mcdev.util.findAnnotations
Expand All @@ -50,7 +50,7 @@ class InjectIntoConstructorInspection : MixinInspection() {

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

override fun buildVisitor(holder: ProblemsHolder): PsiElementVisitor {
val isFabric = holder.file.isFabric
val isFabric = holder.file.isFabricMixin
return object : JavaElementVisitor() {
override fun visitMethod(method: PsiMethod) {
val injectAnnotation = method.findAnnotation(INJECT) ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

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

import com.demonwav.mcdev.platform.fabric.util.isFabric
import com.demonwav.mcdev.platform.mixin.handlers.MixinAnnotationHandler
import com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.AtResolver
import com.demonwav.mcdev.platform.mixin.inspection.MixinInspection
import com.demonwav.mcdev.platform.mixin.inspection.fix.AnnotationAttributeFix
import com.demonwav.mcdev.platform.mixin.util.MethodTargetMember
import com.demonwav.mcdev.platform.mixin.util.MixinConstants
import com.demonwav.mcdev.platform.mixin.util.isConstructor
import com.demonwav.mcdev.platform.mixin.util.isFabricMixin
import com.demonwav.mcdev.util.constantValue
import com.demonwav.mcdev.util.findInspection
import com.demonwav.mcdev.util.ifEmpty
Expand All @@ -49,7 +49,7 @@ class UnnecessaryUnsafeInspection : MixinInspection() {

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

override fun buildVisitor(holder: ProblemsHolder): PsiElementVisitor {
val isFabric = holder.file.isFabric
val isFabric = holder.file.isFabricMixin
val alwaysUnnecessary = isFabric && alwaysUnnecessaryOnFabric
val requiresUnsafeForCtorHeadOnFabric =
holder.project.findInspection<CtorHeadNoUnsafeInspection>(CtorHeadNoUnsafeInspection.SHORT_NAME)
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/platform/mixin/util/Mixin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,6 @@ fun isMixinEntryPoint(element: PsiElement?): Boolean {
}
return false
}

val PsiElement.isFabricMixin: Boolean get() =
JavaPsiFacade.getInstance(project).findClass(MixinConstants.Classes.FABRIC_UTIL, resolveScope) != null
2 changes: 2 additions & 0 deletions src/main/kotlin/platform/mixin/util/MixinConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ object MixinConstants {

const val SERIALIZED_NAME = "com.google.gson.annotations.SerializedName"
const val MIXIN_SERIALIZED_NAME = "org.spongepowered.include.$SERIALIZED_NAME"

const val FABRIC_UTIL = "org.spongepowered.asm.mixin.FabricUtil"
}

object Annotations {
Expand Down

0 comments on commit 244ec6d

Please sign in to comment.