Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move non-private static error to the access modifier (when there is one) #2425

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.INVOKER
import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.OVERWRITE
import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.SHADOW
import com.demonwav.mcdev.platform.mixin.util.isMixin
import com.demonwav.mcdev.util.findKeyword
import com.intellij.codeInsight.intention.QuickFixFactory
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.JavaElementVisitor
Expand Down Expand Up @@ -54,8 +55,14 @@ class StaticMemberInspection : MixinInspection() {

private fun visitMember(member: PsiMember) {
if (isProblematic(member)) {
val accessModifier = when {
member.hasModifierProperty(PsiModifier.PUBLIC) -> PsiModifier.PUBLIC
member.hasModifierProperty(PsiModifier.PROTECTED) -> PsiModifier.PROTECTED
member.hasModifierProperty(PsiModifier.PRIVATE) -> PsiModifier.PRIVATE
else -> PsiModifier.PACKAGE_LOCAL
}
holder.registerProblem(
member,
member.modifierList?.findKeyword(accessModifier) ?: member,
"Non-private static members are not allowed in Mixin classes",
QuickFixFactory.getInstance().createModifierListFix(member, PsiModifier.PRIVATE, true, false),
)
Expand Down
Loading