|
| 1 | +/* |
| 2 | + * Minecraft Development for IntelliJ |
| 3 | + * |
| 4 | + * https://mcdev.io/ |
| 5 | + * |
| 6 | + * Copyright (C) 2024 minecraft-dev |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Lesser General Public License as published |
| 10 | + * by the Free Software Foundation, version 3.0 only. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Lesser General Public License |
| 18 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +package com.demonwav.mcdev.platform.mcp.at |
| 22 | + |
| 23 | +import com.demonwav.mcdev.platform.mcp.at.gen.psi.AtVisitor |
| 24 | +import com.intellij.codeInspection.LocalInspectionTool |
| 25 | +import com.intellij.codeInspection.ProblemHighlightType |
| 26 | +import com.intellij.codeInspection.ProblemsHolder |
| 27 | +import com.intellij.psi.PsiElement |
| 28 | +import com.intellij.psi.PsiElementVisitor |
| 29 | + |
| 30 | +class AtUnresolvedReferenceInspection : LocalInspectionTool() { |
| 31 | + |
| 32 | + override fun getStaticDescription(): String? = "Unresolved reference" |
| 33 | + |
| 34 | + override fun buildVisitor( |
| 35 | + holder: ProblemsHolder, |
| 36 | + isOnTheFly: Boolean |
| 37 | + ): PsiElementVisitor = object : AtVisitor() { |
| 38 | + override fun visitElement(element: PsiElement) { |
| 39 | + super.visitElement(element) |
| 40 | + |
| 41 | + for (reference in element.references) { |
| 42 | + if (reference.resolve() == null) { |
| 43 | + holder.registerProblem(reference, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL) |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments