diff --git a/CHANGELOG.md b/CHANGELOG.md index 31eadd1..17fea2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +## [1.67.3] +### Fixed +- Added exception handling when analyzing Kotlin classes if they are step definition classes. + ## [1.67.2] ### Changed - Added a minor performance improvement to pattern variant building. diff --git a/gradle.properties b/gradle.properties index f5b8399..8720603 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ pluginGroup = com.github.kumaraman21.intellijbehave pluginName = JBehave Support pluginRepositoryUrl = https://github.com/witspirit/IntelliJBehave # SemVer format -> https://semver.org -pluginVersion = 1.67.2 +pluginVersion = 1.67.3 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild = 242.21829.142 diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinPsiClassesHandler.kt b/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinPsiClassesHandler.kt index 50d91eb..e631e03 100644 --- a/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinPsiClassesHandler.kt +++ b/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinPsiClassesHandler.kt @@ -17,8 +17,15 @@ import kotlin.jvm.internal.Ref.BooleanRef class KotlinPsiClassesHandler private constructor() { companion object { + private val GIVEN = FqName("org.jbehave.core.annotations.Given") + private val WHEN = FqName("org.jbehave.core.annotations.When") + private val THEN = FqName("org.jbehave.core.annotations.Then") + private val ALIAS = FqName("org.jbehave.core.annotations.Alias") + private val ALIASES = FqName("org.jbehave.core.annotations.Aliases") + private val COMPOSITE = FqName("org.jbehave.core.annotations.Composite") + /** - * Returns the classes in [psiFile] if it is a Kotlin files, otherwise returns null. + * Returns the classes in [psiFile] if it is a Kotlin file, otherwise returns null. */ @JvmStatic fun getPsiClasses(psiFile: PsiFile): Array? = if (psiFile is KtFile) { @@ -56,14 +63,18 @@ class KotlinPsiClassesHandler private constructor() { * Returns if any of the functions in the provided Kotlin class is a step definition function. */ private fun isKotlinJBehaveStepDefClass(aClass: KtClass): Boolean { - return !aClass.isEnum() && !aClass.isInterface() && aClass.fqName != null && aClass.body?.functions?.any { - it.findAnnotation(FqName("org.jbehave.core.annotations.Given")) != null - || it.findAnnotation(FqName("org.jbehave.core.annotations.When")) != null - || it.findAnnotation(FqName("org.jbehave.core.annotations.Then")) != null - || it.findAnnotation(FqName("org.jbehave.core.annotations.Alias")) != null - || it.findAnnotation(FqName("org.jbehave.core.annotations.Aliases")) != null - || it.findAnnotation(FqName("org.jbehave.core.annotations.Composite")) != null - } == true + return try { + !aClass.isEnum() && !aClass.isInterface() && aClass.fqName != null && aClass.body?.functions?.any { + it.findAnnotation(GIVEN) != null + || it.findAnnotation(WHEN) != null + || it.findAnnotation(THEN) != null + || it.findAnnotation(ALIAS) != null + || it.findAnnotation(ALIASES) != null + || it.findAnnotation(COMPOSITE) != null + } == true + } catch (e: Exception) { + false + } } } }