generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
1,038 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/com/github/imyuyu/sqltoy/SQLToyFindUsagesHandlerFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.imyuyu.sqltoy | ||
|
||
import com.github.imyuyu.sqltoy.model.highlighting.jam.SQLToyTranslateFindUsagesHandler | ||
import com.github.imyuyu.sqltoy.util.XmlUtil | ||
import com.intellij.find.findUsages.FindUsagesHandler | ||
import com.intellij.find.findUsages.FindUsagesHandlerFactory | ||
import com.intellij.openapi.module.ModuleUtilCore | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiFile | ||
|
||
class SQLToyFindUsagesHandlerFactory: FindUsagesHandlerFactory() { | ||
|
||
override fun canFindUsages(element: PsiElement): Boolean { | ||
val module = ModuleUtilCore.findModuleForPsiElement(element); | ||
val containingFile: VirtualFile = element.containingFile.virtualFile | ||
return XmlUtil.isSqltoyXml(containingFile); | ||
} | ||
|
||
override fun createFindUsagesHandler(element: PsiElement, forHighlightUsages: Boolean): FindUsagesHandler? { | ||
if(XmlUtil.isTranslateXml(element)){ | ||
// | ||
return SQLToyTranslateFindUsagesHandler(element, forHighlightUsages); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/kotlin/com/github/imyuyu/sqltoy/action/MainActionGroup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.github.imyuyu.sqltoy.action | ||
|
||
import com.intellij.database.psi.DbTable | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.actionSystem.LangDataKeys | ||
import com.intellij.openapi.project.Project | ||
|
||
|
||
/** | ||
* create java code | ||
*/ | ||
class MainActionGroup : AnAction() { | ||
|
||
override fun actionPerformed(event: AnActionEvent) { | ||
val project: Project = event.getProject() ?: return | ||
|
||
//获取选中的PSI元素 | ||
val psiElement = event.getData(LangDataKeys.PSI_ELEMENT) | ||
var selectDbTable: DbTable? = null | ||
if (psiElement is DbTable) { | ||
selectDbTable = psiElement | ||
} | ||
if (selectDbTable == null) { | ||
return; | ||
} | ||
|
||
//获取选中的所有表 | ||
val psiElements = event.getData(LangDataKeys.PSI_ELEMENT_ARRAY) | ||
if (psiElements.isNullOrEmpty()) { | ||
return; | ||
} | ||
|
||
val dbTableList: MutableList<DbTable> = ArrayList() | ||
for (element in psiElements) { | ||
if (element !is DbTable) { | ||
continue | ||
} | ||
dbTableList.add(element) | ||
} | ||
if (dbTableList.isEmpty()) { | ||
return; | ||
} | ||
|
||
// 弹出form处理 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/TranslateConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.github.imyuyu.sqltoy.dom.model | ||
|
||
import com.github.imyuyu.sqltoy.dom.model.converters.SQLToyTranslateConverter | ||
import com.intellij.util.xml.* | ||
|
||
/** | ||
* The interface translate element. | ||
*/ | ||
interface TranslateConfig:DomElement{ | ||
|
||
@Referencing(SQLToyTranslateConverter::class) | ||
@Required | ||
@Attribute("cache") | ||
fun getCache() : GenericAttributeValue<String> | ||
|
||
@Required | ||
@Attribute("cache") | ||
fun getColumns():GenericAttributeValue<String> | ||
|
||
@Attribute("cache-type") | ||
fun getCacheType() : GenericAttributeValue<String> | ||
|
||
@Attribute("split-regex") | ||
fun getSplitRegex() : GenericAttributeValue<String> | ||
|
||
@Attribute("link-sign") | ||
fun getLinkSign() : GenericAttributeValue<String> | ||
|
||
@Attribute("cache-indexs") | ||
fun getCacheIndexs() : GenericAttributeValue<String> | ||
|
||
@Attribute("uncached-template") | ||
fun getUncachedTemplate() : GenericAttributeValue<String> | ||
|
||
@Attribute("original-columns") | ||
fun getOriginalColumns() : GenericAttributeValue<String> | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/converters/SQLToySqlIdConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.github.imyuyu.sqltoy.dom.model.converters | ||
|
||
import com.intellij.util.xml.CustomReferenceConverter | ||
|
||
abstract class SQLToySqlIdConverter : CustomReferenceConverter<String?> |
50 changes: 50 additions & 0 deletions
50
src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/converters/SQLToySqlIdConverterImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.github.imyuyu.sqltoy.dom.model.converters | ||
|
||
import com.github.imyuyu.sqltoy.dom.model.Sql | ||
import com.intellij.pom.PomTargetPsiElement | ||
import com.intellij.pom.references.PomService | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiReference | ||
import com.intellij.psi.PsiReferenceBase | ||
import com.intellij.psi.ResolvingHint | ||
import com.intellij.spring.model.BeanService | ||
import com.intellij.util.ReflectionUtil | ||
import com.intellij.util.xml.ConvertContext | ||
import com.intellij.util.xml.DomTarget | ||
import com.intellij.util.xml.GenericDomValue | ||
|
||
class SQLToySqlIdConverterImpl : SQLToySqlIdConverter() { | ||
|
||
override fun createReferences( | ||
value: GenericDomValue<String?>?, | ||
element: PsiElement, | ||
context: ConvertContext? | ||
): Array<PsiReference> { | ||
return arrayOf<PsiReference>(SQLIdReference(element, value)); | ||
Check warning on line 23 in src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/converters/SQLToySqlIdConverterImpl.kt GitHub Actions / Qodana Community for JVMRedundant semicolon
|
||
} | ||
|
||
class SQLIdReference(element:PsiElement, genericDomValue:GenericDomValue<String?>?): PsiReferenceBase<PsiElement>(element, true), ResolvingHint { | ||
|
||
private val myGenericDomValue = genericDomValue; | ||
|
||
override fun resolve(): PsiElement? { | ||
val sql = getSQLIdBean(); | ||
if(sql == null){ | ||
return null; | ||
} | ||
val target = DomTarget.getTarget(sql); | ||
return PomService.convertToPsi(target!!); | ||
} | ||
|
||
override fun canResolveTo(elementClass: Class<out PsiElement>?): Boolean { | ||
return ReflectionUtil.isAssignable( | ||
PomTargetPsiElement::class.java, | ||
elementClass!! | ||
) | ||
} | ||
|
||
private fun getSQLIdBean(): Sql? { | ||
return myGenericDomValue?.getParentOfType<Sql>(Sql::class.java, false) | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/converters/SQLToyTranslateConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.github.imyuyu.sqltoy.dom.model.converters | ||
|
||
import com.intellij.util.xml.CustomReferenceConverter | ||
|
||
abstract class SQLToyTranslateConverter : CustomReferenceConverter<String?> |
103 changes: 103 additions & 0 deletions
103
...main/kotlin/com/github/imyuyu/sqltoy/dom/model/converters/SQLToyTranslateConverterImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.github.imyuyu.sqltoy.dom.model.converters | ||
|
||
import com.github.imyuyu.sqltoy.dom.model.TranslateConfig | ||
import com.github.imyuyu.sqltoy.dom.model.translate.Checker | ||
import com.github.imyuyu.sqltoy.indexer.SQLIdIndexHolder | ||
import com.github.imyuyu.sqltoy.indexer.SQLToyBeanIndexType | ||
import com.github.imyuyu.sqltoy.ui.Icons | ||
import com.github.imyuyu.sqltoy.util.SearchUtil | ||
import com.intellij.codeInsight.daemon.EmptyResolveMessageProvider | ||
import com.intellij.codeInsight.highlighting.HighlightedReference | ||
import com.intellij.codeInsight.lookup.LookupElementBuilder | ||
import com.intellij.pom.PomTargetPsiElement | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiReference | ||
import com.intellij.psi.PsiReferenceBase | ||
import com.intellij.psi.ResolvingHint | ||
import com.intellij.psi.search.GlobalSearchScope | ||
import com.intellij.util.ReflectionUtil | ||
import com.intellij.util.xml.ConvertContext | ||
import com.intellij.util.xml.GenericDomValue | ||
|
||
class SQLToyTranslateConverterImpl : SQLToyTranslateConverter() { | ||
|
||
override fun createReferences( | ||
value: GenericDomValue<String?>?, | ||
element: PsiElement, | ||
context: ConvertContext? | ||
): Array<PsiReference> { | ||
return arrayOf<PsiReference>(SQLToyTranslateReference(element, value)); | ||
Check warning on line 29 in src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/converters/SQLToyTranslateConverterImpl.kt GitHub Actions / Qodana Community for JVMRedundant semicolon
|
||
} | ||
|
||
class SQLToyTranslateReference(element:PsiElement, genericDomValue:GenericDomValue<String?>?): PsiReferenceBase<PsiElement>(element, true), ResolvingHint, HighlightedReference, | ||
EmptyResolveMessageProvider { | ||
|
||
private val myGenericDomValue = genericDomValue; | ||
|
||
override fun resolve(): PsiElement? { | ||
var cacheName: String? = null; | ||
val checker = getTranslateCheckerBean(); | ||
if(checker != null){ | ||
// | ||
cacheName = checker.getCache().toString(); | ||
} | ||
|
||
if(cacheName == null){ | ||
val translateConfigBean = getTranslateConfigBean() | ||
if (translateConfigBean != null) { | ||
cacheName = translateConfigBean.getCache().toString(); | ||
} | ||
} | ||
|
||
if(cacheName == null){ | ||
return null; | ||
} | ||
|
||
SQLIdIndexHolder.findRecordsByQualifiedId(SQLToyBeanIndexType.TRANSLATE_ID, cacheName, element.project, SearchUtil.getSearchScope(element.project, element)) | ||
.forEach { record -> | ||
record.getElements(element.project) | ||
.forEach { | ||
return it; | ||
} | ||
} | ||
|
||
return null; | ||
/*val target = DomTarget.getTarget(sql); | ||
return PomService.convertToPsi(target!!);*/ | ||
} | ||
|
||
override fun getVariants(): Array<Any> { | ||
val allIds = SQLIdIndexHolder.getAllTranslateIds(element.project, GlobalSearchScope.projectScope(element.project)) | ||
return allIds.map { | ||
LookupElementBuilder.create(it).withIcon(Icons.XML_ICON); | ||
}.toTypedArray(); | ||
} | ||
|
||
private fun getTranslateConfigBean(): TranslateConfig? { | ||
return myGenericDomValue?.getParentOfType(TranslateConfig::class.java, false) | ||
} | ||
|
||
override fun canResolveTo(elementClass: Class<out PsiElement>?): Boolean { | ||
return ReflectionUtil.isAssignable( | ||
PomTargetPsiElement::class.java, | ||
elementClass!! | ||
) | ||
} | ||
|
||
private fun getTranslateCheckerBean(): Checker? { | ||
return myGenericDomValue?.getParentOfType(Checker::class.java, false) | ||
} | ||
|
||
override fun getUnresolvedMessagePattern(): String { | ||
return "Cannot resolve translate '${value}'" | ||
} | ||
|
||
override fun bindToElement(element: PsiElement): PsiElement { | ||
return getElement() | ||
} | ||
|
||
override fun isHighlightedWhenSoft(): Boolean { | ||
return true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
src/main/kotlin/com/github/imyuyu/sqltoy/dom/model/translate/Checker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.