Skip to content

Commit

Permalink
Add exception handling when analyzing Kotlin classes if they are step…
Browse files Browse the repository at this point in the history
… definition classes
  • Loading branch information
picimako committed Dec 29, 2024
1 parent 9c0206a commit 00870c0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PsiClass>? = if (psiFile is KtFile) {
Expand Down Expand Up @@ -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
}
}
}
}

0 comments on commit 00870c0

Please sign in to comment.