File tree Expand file tree Collapse file tree 5 files changed +72
-2
lines changed
kotlin/org/tabooproject/intellij Expand file tree Collapse file tree 5 files changed +72
-2
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ dependencies {
20
20
}
21
21
22
22
intellij {
23
- version.set(" 2023.1.5 " )
23
+ version.set(" 2023.2.2 " )
24
24
25
25
plugins.addAll(
26
26
" java" ,
Original file line number Diff line number Diff line change 1
1
package org.tabooproject.intellij
2
2
3
+ import com.intellij.psi.*
3
4
import okhttp3.OkHttpClient
4
5
import okhttp3.Request
6
+ import org.jetbrains.kotlin.psi.KtAnnotated
5
7
import java.net.InetSocketAddress
6
8
import java.net.Proxy
7
9
import java.nio.file.Files
@@ -43,4 +45,29 @@ fun createOkHttpClientWithSystemProxy(block: OkHttpClient.Builder.() -> Unit = {
43
45
44
46
fun getRequest (url : String ): Request {
45
47
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
+ }
46
73
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -52,8 +52,8 @@ data class Module(
52
52
53
53
54
54
val TEMPLATE_DOWNLOAD_MIRROR = mapOf (
55
+ " tabooproject.org" to " https://template.tabooproject.org" ,
55
56
" github.com" to " https://github.com/TabooLib/taboolib-sdk/archive/refs/heads/idea-template.zip" ,
56
- " tabooproject.org" to " https://template.tabooproject.org"
57
57
)
58
58
59
59
data class ConfigurationProperty (
Original file line number Diff line number Diff line change 19
19
20
20
<extensions defaultExtensionNs =" com.intellij" >
21
21
<moduleBuilder id =" TABOO_PROJECT_BUILDER" builderClass =" org.tabooproject.intellij.ProjectBuilder" />
22
+ <lang .inspectionSuppressor language =" kotlin"
23
+ implementationClass =" org.tabooproject.intellij.component.AnnotatedUnusedSuppressor" />
22
24
</extensions >
23
25
24
26
</idea-plugin >
You can’t perform that action at this time.
0 commit comments