Skip to content

Commit 4cf1a61

Browse files
committed
update: 对tb注解Suppress unused警告
将tabooproject.org设为第一个下载镜像(github会失败)
1 parent 0fa9db9 commit 4cf1a61

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies {
2020
}
2121

2222
intellij {
23-
version.set("2023.1.5")
23+
version.set("2023.2.2")
2424

2525
plugins.addAll(
2626
"java",

src/main/kotlin/org/tabooproject/intellij/Utils.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.tabooproject.intellij
22

3+
import com.intellij.psi.*
34
import okhttp3.OkHttpClient
45
import okhttp3.Request
6+
import org.jetbrains.kotlin.psi.KtAnnotated
57
import java.net.InetSocketAddress
68
import java.net.Proxy
79
import java.nio.file.Files
@@ -43,4 +45,29 @@ fun createOkHttpClientWithSystemProxy(block: OkHttpClient.Builder.() -> Unit = {
4345

4446
fun getRequest(url: String): Request {
4547
return Request.Builder().url(url).build()
48+
}
49+
50+
fun PsiElement.findContainingAnnotated(): KtAnnotated? = findParent(resolveReferences = false) { it is KtAnnotated }
51+
52+
private inline fun <reified T : PsiElement> PsiElement.findParent(
53+
resolveReferences: Boolean,
54+
stop: (PsiElement) -> Boolean,
55+
): T? {
56+
var el: PsiElement = this
57+
58+
while (true) {
59+
if (resolveReferences && el is PsiReference) {
60+
el = el.resolve() ?: return null
61+
}
62+
63+
if (el is T) {
64+
return el
65+
}
66+
67+
if (el is PsiFile || el is PsiDirectory || stop(el)) {
68+
return null
69+
}
70+
71+
el = el.parent ?: return null
72+
}
4673
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.tabooproject.intellij.component
2+
3+
import com.intellij.codeInspection.InspectionSuppressor
4+
import com.intellij.codeInspection.SuppressQuickFix
5+
import com.intellij.psi.PsiElement
6+
import org.jetbrains.kotlin.psi.*
7+
import org.tabooproject.intellij.findContainingAnnotated
8+
9+
10+
private val ANNOTATIONS = hashSetOf(
11+
"SubscribeEvent",
12+
"Schedule",
13+
"Awake",
14+
"CommandBody",
15+
"CommandHeader",
16+
"KetherParser",
17+
"KetherProperty"
18+
)
19+
20+
private const val INSPECTION = "unused"
21+
22+
class AnnotatedUnusedSuppressor: InspectionSuppressor {
23+
override fun isSuppressedFor(element: PsiElement, toolId: String): Boolean {
24+
if (toolId != INSPECTION) {
25+
return false
26+
}
27+
28+
return element.findContainingAnnotated()?.hasSuppressUnusedAnnotation() ?: false
29+
}
30+
31+
override fun getSuppressActions(element: PsiElement?, toolId: String): Array<SuppressQuickFix> =
32+
SuppressQuickFix.EMPTY_ARRAY
33+
34+
private fun KtAnnotated.hasSuppressUnusedAnnotation(): Boolean {
35+
val annotationEntries = annotationEntries
36+
return annotationEntries.any {
37+
ANNOTATIONS.contains(it.shortName?.asString() ?: return false)
38+
}
39+
}
40+
41+
}

src/main/kotlin/org/tabooproject/intellij/step/ConfigurationPropertiesStep.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ data class Module(
5252

5353

5454
val TEMPLATE_DOWNLOAD_MIRROR = mapOf(
55+
"tabooproject.org" to "https://template.tabooproject.org",
5556
"github.com" to "https://github.com/TabooLib/taboolib-sdk/archive/refs/heads/idea-template.zip",
56-
"tabooproject.org" to "https://template.tabooproject.org"
5757
)
5858

5959
data class ConfigurationProperty(

src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
<extensions defaultExtensionNs="com.intellij">
2121
<moduleBuilder id="TABOO_PROJECT_BUILDER" builderClass="org.tabooproject.intellij.ProjectBuilder"/>
22+
<lang.inspectionSuppressor language="kotlin"
23+
implementationClass="org.tabooproject.intellij.component.AnnotatedUnusedSuppressor"/>
2224
</extensions>
2325

2426
</idea-plugin>

0 commit comments

Comments
 (0)