Просмотр исходного кода

Rename PluginDescriptionChecker.kt to ContextualParametersChecker.kt for further extensibility

Him188 5 лет назад
Родитель
Сommit
c1f1b6954a

+ 2 - 2
tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/IDEContainerContributor.kt

@@ -9,8 +9,8 @@
 
 package net.mamoe.mirai.console.intellij
 
+import net.mamoe.mirai.console.intellij.diagnostics.ContextualParametersChecker
 import net.mamoe.mirai.console.intellij.diagnostics.PluginDataValuesChecker
-import net.mamoe.mirai.console.intellij.diagnostics.PluginDescriptionChecker
 import org.jetbrains.kotlin.container.StorageComponentContainer
 import org.jetbrains.kotlin.container.useInstance
 import org.jetbrains.kotlin.descriptors.ModuleDescriptor
@@ -22,7 +22,7 @@ class IDEContainerContributor : StorageComponentContainerContributor {
         platform: org.jetbrains.kotlin.platform.TargetPlatform,
         moduleDescriptor: ModuleDescriptor,
     ) {
-        container.useInstance(PluginDescriptionChecker())
+        container.useInstance(ContextualParametersChecker())
         container.useInstance(PluginDataValuesChecker())
     }
 }

+ 2 - 39
tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/PluginDescriptionChecker.kt → tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/ContextualParametersChecker.kt

@@ -24,11 +24,9 @@ import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
 import java.util.*
 
 /**
- * Checks:
- * - plugin id
- * - plugin name
+ * Checks paramters with [ResolveContextKind]
  */
-class PluginDescriptionChecker : DeclarationChecker {
+class ContextualParametersChecker : DeclarationChecker {
     companion object {
         private val ID_REGEX: Regex = Regex("""([a-zA-Z]+(?:\.[a-zA-Z0-9]+)*)\.([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)""")
         private val FORBIDDEN_ID_NAMES: Array<String> = arrayOf("main", "console", "plugin", "config", "data")
@@ -103,40 +101,5 @@ class PluginDescriptionChecker : DeclarationChecker {
                 fn(argument.asElement(), resolvedConstant)?.let { context.report(it) }
             }
         return
-        /*
-        when (declaration) {
-            is KtClassOrObject -> {
-                // check super type constructor
-                val superTypeCallEntry = declaration.findChild<KtSuperTypeList>()?.findChild<KtSuperTypeCallEntry>() ?: return
-                // val constructorCall = superTypeCallEntry.findChildren<KtConstructorCalleeExpression>()?.resolveToCall() ?: return
-                val valueArgumentList = superTypeCallEntry.findChild<KtValueArgumentList>() ?: return
-                valueArgumentList.arguments.asSequence().mapNotNull(KtValueArgument::getArgumentExpression).forEach {
-                    for (child in it.allChildrenWithSelf) {
-                        if (child is LambdaArgument) {
-                            child.getLambdaExpression()?.bodyExpression?.statements?.forEach { statement ->
-                                if (statement is KtCallExpression) check(statement, context)
-                            }
-                        }
-                        if (child is KtCallExpression) {
-                            check(child, context)
-                        }
-                    }
-                }
-            }
-            else -> {
-                declaration.children.flatMap {
-                    when (it) {
-                        is KtCallExpression -> listOf(it)
-                        is KtLambdaExpression -> it.bodyExpression?.statements.orEmpty()
-                        else -> emptyList()
-                    }
-                }.forEach { element ->
-                    if (element is KtDeclaration) {
-                        val desc = element.descriptor ?: return@forEach
-                        check(element, desc, context)
-                    }
-                }
-            }
-        }*/
     }
 }