- /*
- * Minecraft Development for IntelliJ
- *
- * https://mcdev.io/
- *
- * Copyright (C) 2024 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.reference
- import com.demonwav.mcdev.platform.mixin.handlers.InjectorAnnotationHandler
- import com.demonwav.mcdev.platform.mixin.handlers.MixinAnnotationHandler
- import com.demonwav.mcdev.util.constantStringValue
- import com.demonwav.mcdev.util.insideAnnotationAttribute
- import com.intellij.openapi.project.Project
- import com.intellij.patterns.ElementPattern
- import com.intellij.patterns.PatternCondition
- import com.intellij.patterns.PsiJavaPatterns
- import com.intellij.patterns.StandardPatterns
- import com.intellij.psi.PsiAnnotation
- import com.intellij.psi.PsiElement
- import com.intellij.psi.PsiLiteral
- import com.intellij.util.ProcessingContext
- object MethodReference : AbstractMethodReference() {
- val ELEMENT_PATTERN: ElementPattern<PsiLiteral> =
- PsiJavaPatterns.psiLiteral(StandardPatterns.string()).withAncestor(
- 1,
- PsiJavaPatterns.psiElement().insideAnnotationAttribute(
- PsiJavaPatterns.psiAnnotation().with(
- object : PatternCondition<PsiAnnotation>("injector") {
- override fun accepts(t: PsiAnnotation, context: ProcessingContext?): Boolean {
- val qName = t.qualifiedName ?: return false
- return isValidAnnotation(qName, t.project)
- }
- },
- ),
- "method",
- ),
- )
- override val description = "method '%s' in target class"
- override fun isValidAnnotation(name: String, project: Project) =
- MixinAnnotationHandler.forMixinAnnotation(name, project) is InjectorAnnotationHandler
- override fun parseSelector(context: PsiElement): MixinSelector? {
- return parseMixinSelector(context)
- }
- override fun parseSelector(stringValue: String, context: PsiElement): MixinSelector? {
- return parseMixinSelector(stringValue, context)
- }
- override fun isUnresolved(context: PsiElement): Boolean {
- return if (super.isUnresolved(context)) {
- val stringValue = context.constantStringValue ?: return true
- !isMiscDynamicSelector(context.project, stringValue)
- } else {
- false
- }
- }
- }
- /*
- * 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.reference
- import com.demonwav.mcdev.platform.mixin.handlers.InjectorAnnotationHandler
- import com.demonwav.mcdev.platform.mixin.handlers.MixinAnnotationHandler
- import com.demonwav.mcdev.util.constantStringValue
- import com.demonwav.mcdev.util.insideAnnotationAttribute
- import com.intellij.openapi.project.Project
- import com.intellij.patterns.ElementPattern
- import com.intellij.patterns.PatternCondition
- import com.intellij.patterns.PsiJavaPatterns
- import com.intellij.patterns.StandardPatterns
- import com.intellij.psi.PsiAnnotation
- import com.intellij.psi.PsiElement
- import com.intellij.psi.PsiLiteral
- import com.intellij.util.ProcessingContext
- object MethodReference : AbstractMethodReference() {
- val ELEMENT_PATTERN: ElementPattern<PsiLiteral> =
- PsiJavaPatterns.psiLiteral(StandardPatterns.string()).withAncestor(
- 1,
- PsiJavaPatterns.psiElement().insideAnnotationAttribute(
- PsiJavaPatterns.psiAnnotation().with(
- object : PatternCondition<PsiAnnotation>("injector") {
- override fun accepts(t: PsiAnnotation, context: ProcessingContext?): Boolean {
- val qName = t.qualifiedName ?: return false
- return isValidAnnotation(qName, t.project)
- }
- },
- ),
- "method",
- ),
- )
- override val description = "method '%s' in target class"
- override fun isValidAnnotation(name: String, project: Project) =
- MixinAnnotationHandler.forMixinAnnotation(name, project) is InjectorAnnotationHandler
- override fun parseSelector(context: PsiElement): MixinSelector? {
- return parseMixinSelector(context)
- }
- override fun parseSelector(stringValue: String, context: PsiElement): MixinSelector? {
- return parseMixinSelector(stringValue, context)
- }
- override fun isUnresolved(context: PsiElement): Boolean {
- return if (super.isUnresolved(context)) {
- val stringValue = context.constantStringValue ?: return true
- !isMiscDynamicSelector(context.project, stringValue)
- } else {
- false
- }
- }
- }