⁠
joe: 2025
- /*
- * 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.mcp.aw.psi.mixins.impl
- import com.demonwav.mcdev.platform.mcp.aw.psi.mixins.AwDescElementMixin
- import com.demonwav.mcdev.util.cached
- import com.demonwav.mcdev.util.findQualifiedClass
- import com.intellij.extapi.psi.ASTWrapperPsiElement
- import com.intellij.lang.ASTNode
- import com.intellij.openapi.util.TextRange
- import com.intellij.psi.PsiClass
- import com.intellij.psi.PsiElement
- import com.intellij.psi.PsiReference
- import com.intellij.psi.util.PsiModificationTracker
- import com.intellij.util.IncorrectOperationException
- abstract class AwDescElementImplMixin(node: ASTNode) : ASTWrapperPsiElement(node), AwDescElementMixin {
- override fun getElement(): PsiElement = this
- override fun getReference(): PsiReference? = this
- override fun resolve(): PsiElement? = cached(PsiModificationTracker.MODIFICATION_COUNT) {
- val name = asQualifiedName() ?: return@cached null
- return@cached findQualifiedClass(name, this)
- }
- override fun getRangeInElement(): TextRange = TextRange(0, text.length)
- override fun getCanonicalText(): String = text
- override fun handleElementRename(newElementName: String): PsiElement {
- throw IncorrectOperationException()
- }
- override fun bindToElement(element: PsiElement): PsiElement {
- throw IncorrectOperationException()
- }
- override fun isReferenceTo(element: PsiElement): Boolean {
- return element is PsiClass && element.qualifiedName == asQualifiedName()
- }
- private fun asQualifiedName(): String? =
- if (text.length > 1) {
- text.substring(1, text.length - 1).replace('/', '.')
- } else {
- null
- }
- override fun isSoft(): Boolean = 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.mcp.aw.psi.mixins.impl
- import com.demonwav.mcdev.platform.mcp.aw.psi.mixins.AwDescElementMixin
- import com.demonwav.mcdev.util.cached
- import com.demonwav.mcdev.util.findQualifiedClass
- import com.intellij.extapi.psi.ASTWrapperPsiElement
- import com.intellij.lang.ASTNode
- import com.intellij.openapi.util.TextRange
- import com.intellij.psi.PsiClass
- import com.intellij.psi.PsiElement
- import com.intellij.psi.PsiReference
- import com.intellij.psi.util.PsiModificationTracker
- import com.intellij.util.IncorrectOperationException
- abstract class AwDescElementImplMixin(node: ASTNode) : ASTWrapperPsiElement(node), AwDescElementMixin {
- override fun getElement(): PsiElement = this
- override fun getReference(): PsiReference? = this
- override fun resolve(): PsiElement? = cached(PsiModificationTracker.MODIFICATION_COUNT) {
- val name = asQualifiedName() ?: return@cached null
- return@cached findQualifiedClass(name, this)
- }
- override fun getRangeInElement(): TextRange = TextRange(0, text.length)
- override fun getCanonicalText(): String = text
- override fun handleElementRename(newElementName: String): PsiElement {
- throw IncorrectOperationException()
- }
- override fun bindToElement(element: PsiElement): PsiElement {
- throw IncorrectOperationException()
- }
- override fun isReferenceTo(element: PsiElement): Boolean {
- return element is PsiClass && element.qualifiedName == asQualifiedName()
- }
- private fun asQualifiedName(): String? =
- if (text.length > 1) {
- text.substring(1, text.length - 1).replace('/', '.')
- } else {
- null
- }
- override fun isSoft(): Boolean = false
- }