Skip to content

Commit

Permalink
🐛 fix(main): 修复不支持2022版本的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
imyuyu committed Jun 11, 2024
1 parent 5850951 commit 4cc1b83
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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

/**
Expand All @@ -14,7 +16,7 @@ interface SqlIncrementChecker : Checker {

@Required
@SubTag("sql")
@Language(SqlLanguageDialect.SQL_ID)
@Language("SQL")
fun getSql() : ValueElement

@Attribute("datasource")
Expand Down
Original file line number Diff line number Diff line change
@@ -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

/**
Expand All @@ -20,6 +21,6 @@ interface SqlTranslate : Translate {

@Required
@SubTag("sql")
@Language(SqlLanguageDialect.SQL_ID)
@Language("SQL")
fun getSql() : ValueElement
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object SQLToyIndexKeyDescriptor : KeyDescriptor<Pair<SQLToyBeanIndexType, String
}

override fun read(`in`: DataInput): Pair<SQLToyBeanIndexType, String> {
val type = SQLToyBeanIndexType.entries[DataInputOutputUtil.readINT(`in`)]
val type = SQLToyBeanIndexType.get(DataInputOutputUtil.readINT(`in`))
val value = IOUtil.readUTF(`in`)
return Pair.create(type, value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){

Expand All @@ -13,6 +17,14 @@ class SQLToyTranslateFindUsagesHandler(element: PsiElement, forHighlightUsages:
processor: Processor<in UsageInfo>,
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/com/github/imyuyu/sqltoy/util/JavaUtils.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 4cc1b83

Please sign in to comment.