From 4cc1b83a3624ee47c0109c095336fb4e6306d181 Mon Sep 17 00:00:00 2001 From: imyuyu <2075904@qq.com> Date: Tue, 11 Jun 2024 22:29:17 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20fix(main):=20=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=812022=E7=89=88=E6=9C=AC=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sqltoy/indexer/SQLToyBeanIndexType.java | 24 +++++++++++++++++++ .../sqltoy/annotator/SqlIdExistAnnotator.kt | 11 --------- .../model/translate/SqlIncrementChecker.kt | 8 ++++--- .../dom/model/translate/SqlTranslate.kt | 9 +++---- .../imyuyu/sqltoy/indexer/SQLIdRecord.kt | 1 - .../sqltoy/indexer/SQLToyBeanIndexType.kt | 16 ------------- .../indexer/SQLToyIndexKeyDescriptor.kt | 2 +- .../jam/SQLToyTranslateFindUsagesHandler.kt | 12 ++++++++++ .../imyuyu/sqltoy/provider/SqlIdQuickDoc.kt | 5 ++-- .../SQLToyTranslateIdReferenceInjector.kt | 1 - .../github/imyuyu/sqltoy/util/JavaUtils.kt | 3 --- 11 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 src/main/java/com/github/imyuyu/sqltoy/indexer/SQLToyBeanIndexType.java delete mode 100644 src/main/kotlin/com/github/imyuyu/sqltoy/indexer/SQLToyBeanIndexType.kt diff --git a/src/main/java/com/github/imyuyu/sqltoy/indexer/SQLToyBeanIndexType.java b/src/main/java/com/github/imyuyu/sqltoy/indexer/SQLToyBeanIndexType.java new file mode 100644 index 0000000..f4a054f --- /dev/null +++ b/src/main/java/com/github/imyuyu/sqltoy/indexer/SQLToyBeanIndexType.java @@ -0,0 +1,24 @@ +package com.github.imyuyu.sqltoy.indexer; + +public enum SQLToyBeanIndexType { + + /** + * sqlId + */ + SQL_ID, + + /** + * 缓存翻译ID + */ + TRANSLATE_ID + + ; + public static SQLToyBeanIndexType get(int ordinal) { + for (SQLToyBeanIndexType type : SQLToyBeanIndexType.values()) { + if (type.ordinal() == ordinal) { + return type; + } + } + return null; + } +} diff --git a/src/main/kotlin/com/github/imyuyu/sqltoy/annotator/SqlIdExistAnnotator.kt b/src/main/kotlin/com/github/imyuyu/sqltoy/annotator/SqlIdExistAnnotator.kt index 9eb64e2..f57989f 100644 --- a/src/main/kotlin/com/github/imyuyu/sqltoy/annotator/SqlIdExistAnnotator.kt +++ b/src/main/kotlin/com/github/imyuyu/sqltoy/annotator/SqlIdExistAnnotator.kt @@ -1,23 +1,14 @@ package com.github.imyuyu.sqltoy.annotator -import com.github.imyuyu.sqltoy.service.EditorService import com.github.imyuyu.sqltoy.util.XmlUtil import com.intellij.codeInsight.daemon.impl.analysis.RemoveTagIntentionFix -import com.intellij.codeInsight.daemon.impl.quickfix.DeleteElementFix -import com.intellij.codeInsight.intention.IntentionAction import com.intellij.codeInspection.ProblemHighlightType import com.intellij.lang.annotation.AnnotationHolder import com.intellij.lang.annotation.Annotator import com.intellij.lang.annotation.HighlightSeverity -import com.intellij.modcommand.ActionContext -import com.intellij.modcommand.ModPsiUpdater -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.project.Project import com.intellij.openapi.util.TextRange import com.intellij.openapi.util.text.StringUtil -import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement -import com.intellij.psi.PsiFile import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.PsiSearchHelper import com.intellij.psi.util.parentOfTypes @@ -26,8 +17,6 @@ import com.intellij.psi.xml.XmlAttributeValue import com.intellij.psi.xml.XmlTag import com.intellij.refactoring.suggested.endOffset import com.intellij.refactoring.suggested.startOffset -import com.intellij.util.IncorrectOperationException -import org.jetbrains.annotations.Nls class SqlIdExistAnnotator : Annotator { override fun annotate(element: PsiElement, holder: AnnotationHolder) { diff --git a/src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/translate/SqlIncrementChecker.kt b/src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/translate/SqlIncrementChecker.kt index 9682f95..40b0756 100644 --- a/src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/translate/SqlIncrementChecker.kt +++ b/src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/translate/SqlIncrementChecker.kt @@ -1,8 +1,10 @@ package com.github.imyuyu.sqltoy.dom.model.translate import com.github.imyuyu.sqltoy.dom.model.ValueElement -import com.intellij.sql.dialects.SqlLanguageDialect -import com.intellij.util.xml.* +import com.intellij.util.xml.Attribute +import com.intellij.util.xml.GenericAttributeValue +import com.intellij.util.xml.Required +import com.intellij.util.xml.SubTag import org.intellij.lang.annotations.Language /** @@ -14,7 +16,7 @@ interface SqlIncrementChecker : Checker { @Required @SubTag("sql") - @Language(SqlLanguageDialect.SQL_ID) + @Language("SQL") fun getSql() : ValueElement @Attribute("datasource") diff --git a/src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/translate/SqlTranslate.kt b/src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/translate/SqlTranslate.kt index 1f30c50..3e96259 100644 --- a/src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/translate/SqlTranslate.kt +++ b/src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/translate/SqlTranslate.kt @@ -1,9 +1,10 @@ package com.github.imyuyu.sqltoy.dom.model.translate import com.github.imyuyu.sqltoy.dom.model.ValueElement -import com.intellij.spring.model.converters.SpringBeanIdConverter -import com.intellij.sql.dialects.SqlLanguageDialect -import com.intellij.util.xml.* +import com.intellij.util.xml.Attribute +import com.intellij.util.xml.GenericAttributeValue +import com.intellij.util.xml.Required +import com.intellij.util.xml.SubTag import org.intellij.lang.annotations.Language /** @@ -20,6 +21,6 @@ interface SqlTranslate : Translate { @Required @SubTag("sql") - @Language(SqlLanguageDialect.SQL_ID) + @Language("SQL") fun getSql() : ValueElement } \ No newline at end of file diff --git a/src/main/kotlin/com/github/imyuyu/sqltoy/indexer/SQLIdRecord.kt b/src/main/kotlin/com/github/imyuyu/sqltoy/indexer/SQLIdRecord.kt index 908c79e..eb48d98 100644 --- a/src/main/kotlin/com/github/imyuyu/sqltoy/indexer/SQLIdRecord.kt +++ b/src/main/kotlin/com/github/imyuyu/sqltoy/indexer/SQLIdRecord.kt @@ -12,7 +12,6 @@ import com.intellij.psi.PsiTarget import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiUtil import com.intellij.psi.xml.XmlTag -import com.intellij.testFramework.utils.vfs.getPsiFile import com.intellij.util.xml.DomElement import com.intellij.util.xml.DomManager import com.intellij.util.xml.DomTarget diff --git a/src/main/kotlin/com/github/imyuyu/sqltoy/indexer/SQLToyBeanIndexType.kt b/src/main/kotlin/com/github/imyuyu/sqltoy/indexer/SQLToyBeanIndexType.kt deleted file mode 100644 index b0c27b7..0000000 --- a/src/main/kotlin/com/github/imyuyu/sqltoy/indexer/SQLToyBeanIndexType.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.imyuyu.sqltoy.indexer - -/** - * 缓存类型 - */ -enum class SQLToyBeanIndexType { - /** - * sqlId - */ - SQL_ID, - - /** - * 缓存翻译ID - */ - TRANSLATE_ID -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/imyuyu/sqltoy/indexer/SQLToyIndexKeyDescriptor.kt b/src/main/kotlin/com/github/imyuyu/sqltoy/indexer/SQLToyIndexKeyDescriptor.kt index ecc9146..dec9a3e 100644 --- a/src/main/kotlin/com/github/imyuyu/sqltoy/indexer/SQLToyIndexKeyDescriptor.kt +++ b/src/main/kotlin/com/github/imyuyu/sqltoy/indexer/SQLToyIndexKeyDescriptor.kt @@ -16,7 +16,7 @@ object SQLToyIndexKeyDescriptor : KeyDescriptor { - val type = SQLToyBeanIndexType.entries[DataInputOutputUtil.readINT(`in`)] + val type = SQLToyBeanIndexType.get(DataInputOutputUtil.readINT(`in`)) val value = IOUtil.readUTF(`in`) return Pair.create(type, value) } diff --git a/src/main/kotlin/com/github/imyuyu/sqltoy/model/highlighting/jam/SQLToyTranslateFindUsagesHandler.kt b/src/main/kotlin/com/github/imyuyu/sqltoy/model/highlighting/jam/SQLToyTranslateFindUsagesHandler.kt index 88b78b4..895628c 100644 --- a/src/main/kotlin/com/github/imyuyu/sqltoy/model/highlighting/jam/SQLToyTranslateFindUsagesHandler.kt +++ b/src/main/kotlin/com/github/imyuyu/sqltoy/model/highlighting/jam/SQLToyTranslateFindUsagesHandler.kt @@ -3,8 +3,12 @@ package com.github.imyuyu.sqltoy.model.highlighting.jam import com.intellij.find.findUsages.FindUsagesHandler import com.intellij.find.findUsages.FindUsagesOptions import com.intellij.psi.PsiElement +import com.intellij.psi.search.searches.ReferencesSearch +import com.intellij.psi.util.PsiTreeUtil +import com.intellij.psi.xml.XmlTag import com.intellij.usageView.UsageInfo import com.intellij.util.Processor +import com.intellij.util.xml.DomManager class SQLToyTranslateFindUsagesHandler(element: PsiElement, forHighlightUsages: Boolean) : FindUsagesHandler(element){ @@ -13,6 +17,14 @@ class SQLToyTranslateFindUsagesHandler(element: PsiElement, forHighlightUsages: processor: Processor, options: FindUsagesOptions ): Boolean { + ReferencesSearch.search( + DomManager.getDomManager(project).getDomElement( + PsiTreeUtil.getParentOfType( + element.navigationElement, + XmlTag::class.java + ) + )?.xmlTag as XmlTag, options.searchScope + ).toList() return super.processElementUsages(element, processor, options) } } diff --git a/src/main/kotlin/com/github/imyuyu/sqltoy/provider/SqlIdQuickDoc.kt b/src/main/kotlin/com/github/imyuyu/sqltoy/provider/SqlIdQuickDoc.kt index 84362f6..1f000c2 100644 --- a/src/main/kotlin/com/github/imyuyu/sqltoy/provider/SqlIdQuickDoc.kt +++ b/src/main/kotlin/com/github/imyuyu/sqltoy/provider/SqlIdQuickDoc.kt @@ -6,7 +6,6 @@ import com.intellij.codeInsight.documentation.DocumentationManagerProtocol import com.intellij.codeInsight.documentation.DocumentationManagerUtil import com.intellij.lang.documentation.AbstractDocumentationProvider import com.intellij.lang.documentation.DocumentationMarkup -import com.intellij.lang.documentation.DocumentationMarkup.DEFINITION_ELEMENT import com.intellij.openapi.util.text.HtmlBuilder import com.intellij.openapi.util.text.HtmlChunk import com.intellij.psi.PsiElement @@ -56,13 +55,13 @@ class SqlIdQuickDoc : AbstractDocumentationProvider() { return HtmlBuilder().append( - HtmlChunk.div().setClass(DocumentationMarkup.CLASS_DEFINITION).children(HtmlChunk.tag("pre") + DocumentationMarkup.DEFINITION_ELEMENT.children(HtmlChunk.tag("pre") .addText("SQL ID ") .child(HtmlChunk.link(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL+PsiUtil.getName(element), id)) .addText(" is defined in ") .child(HtmlChunk.link("psi_element://"+ (PsiUtil.getVirtualFile(element)?.path ?: ""), file!!.name))) ) - .append(HtmlChunk.div().setClass(DocumentationMarkup.CLASS_CONTENT).addRaw(sql.getSqlValue().getValue()!! + .append(DocumentationMarkup.CONTENT_ELEMENT.addRaw(sql.getSqlValue().getValue()!! .replace(" ", "") .replace(" ", HtmlChunk.nbsp().toString()) .replace("\n", HtmlChunk.br().toString()))).toString(); diff --git a/src/main/kotlin/com/github/imyuyu/sqltoy/references/injector/SQLToyTranslateIdReferenceInjector.kt b/src/main/kotlin/com/github/imyuyu/sqltoy/references/injector/SQLToyTranslateIdReferenceInjector.kt index ff80cc0..a66a59f 100644 --- a/src/main/kotlin/com/github/imyuyu/sqltoy/references/injector/SQLToyTranslateIdReferenceInjector.kt +++ b/src/main/kotlin/com/github/imyuyu/sqltoy/references/injector/SQLToyTranslateIdReferenceInjector.kt @@ -1,7 +1,6 @@ package com.github.imyuyu.sqltoy.references.injector import com.github.imyuyu.sqltoy.indexer.SQLIdIndexHolder -import com.github.imyuyu.sqltoy.indexer.SQLToyBeanIndexType import com.github.imyuyu.sqltoy.reference.PsiJavaInjectReference import com.github.imyuyu.sqltoy.reference.SQLToyTranslateReference import com.github.imyuyu.sqltoy.util.SearchUtil diff --git a/src/main/kotlin/com/github/imyuyu/sqltoy/util/JavaUtils.kt b/src/main/kotlin/com/github/imyuyu/sqltoy/util/JavaUtils.kt index 0b50596..f32e53f 100644 --- a/src/main/kotlin/com/github/imyuyu/sqltoy/util/JavaUtils.kt +++ b/src/main/kotlin/com/github/imyuyu/sqltoy/util/JavaUtils.kt @@ -1,11 +1,8 @@ package com.github.imyuyu.sqltoy.util -import ai.grazie.utils.toDistinctTypedArray import com.intellij.ide.highlighter.JavaFileType import com.intellij.openapi.project.Project import com.intellij.openapi.util.NlsSafe -import com.intellij.patterns.PsiClassPattern -import com.intellij.patterns.PsiJavaPatterns import com.intellij.psi.* import com.intellij.psi.search.FilenameIndex import com.intellij.psi.search.GlobalSearchScope