diff --git a/plugins/devkit/devkit-core/resources/META-INF/plugin.xml b/plugins/devkit/devkit-core/resources/META-INF/plugin.xml index a3c41c5a2eff..0d21cc715489 100644 --- a/plugins/devkit/devkit-core/resources/META-INF/plugin.xml +++ b/plugins/devkit/devkit-core/resources/META-INF/plugin.xml @@ -179,6 +179,10 @@ displayName="Using PsiElement string representation to generate new expression is incorrect" groupKey="inspections.group.name" enabledByDefault="true" level="WARNING" implementationClass="org.jetbrains.idea.devkit.inspections.PsiElementConcatenationInspection"/> + + +Validates that bean extension class has only default constructor. + + \ No newline at end of file diff --git a/plugins/devkit/devkit-core/src/inspections/NonDefaultConstructorInspection.kt b/plugins/devkit/devkit-core/src/inspections/NonDefaultConstructorInspection.kt new file mode 100644 index 000000000000..2e490d8e2e85 --- /dev/null +++ b/plugins/devkit/devkit-core/src/inspections/NonDefaultConstructorInspection.kt @@ -0,0 +1,44 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.idea.devkit.inspections + +import com.intellij.codeInspection.InspectionManager +import com.intellij.codeInspection.ProblemDescriptor +import com.intellij.codeInspection.ProblemHighlightType +import com.intellij.lang.jvm.JvmClassKind +import com.intellij.util.SmartList +import org.jetbrains.uast.UClass + +internal class NonDefaultConstructorInspection : DevKitUastInspectionBase() { + override fun checkClass(aClass: UClass, manager: InspectionManager, isOnTheFly: Boolean): Array? { + if (!isExtensionBean(aClass)) { + return null + } + + var errors: MutableList? = null + for (method in aClass.javaPsi.constructors) { + if (method.hasParameters()) { + if (errors == null) { + errors = SmartList() + } + errors.add(manager.createProblemDescriptor(method ?: continue, + "Bean extension class should not have constructor with parameters", true, + ProblemHighlightType.ERROR, isOnTheFly)) + } + } + return errors?.toTypedArray() + } +} + +private fun isExtensionBean(aClass: UClass): Boolean { + if (aClass.javaPsi.classKind != JvmClassKind.CLASS) { + return false + } + + var p = aClass + while (true) { + p = p.superClass ?: return false + if (p.qualifiedName == "com.intellij.openapi.extensions.AbstractExtensionPointBean") { + return true + } + } +} \ No newline at end of file