Skip to content

Suggest tests for nested classes & static methods inside abstracts #1400 #1406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import org.jetbrains.kotlin.utils.addIfNotNull
import org.utbot.framework.plugin.api.util.LockFile
import org.utbot.intellij.plugin.models.packageName
import org.utbot.intellij.plugin.ui.InvalidClassNotifier
import org.utbot.intellij.plugin.util.isAbstract
import org.utbot.intellij.plugin.language.agnostic.LanguageAssistant
import org.utbot.intellij.plugin.util.findSdkVersionOrNull

Expand Down Expand Up @@ -170,12 +169,6 @@ object JvmLanguageAssistant : LanguageAssistant() {
return true
}

val isAbstractOrInterface = this.isInterface || this.isAbstract
if (isAbstractOrInterface) {
if (withWarnings) InvalidClassNotifier.notify("abstract class or interface ${this.name}")
return true
}

val isInvisible = !this.isVisible
if (isInvisible) {
if (withWarnings) InvalidClassNotifier.notify("private or protected class ${this.name}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.utbot.intellij.plugin.util

import com.intellij.psi.PsiClass
import com.intellij.psi.PsiMember
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiModifier
import com.intellij.psi.SyntheticElement
import com.intellij.refactoring.util.classMembers.MemberInfo
Expand All @@ -17,6 +18,9 @@ import org.utbot.framework.UtSettings
val PsiMember.isAbstract: Boolean
get() = modifierList?.hasModifierProperty(PsiModifier.ABSTRACT)?: false

val PsiMember.isStatic: Boolean
get() = modifierList?.hasModifierProperty(PsiModifier.STATIC)?: false

private val PsiMember.isKotlinGetterOrSetter: Boolean
get() {
if (this !is KtLightMethod)
Expand All @@ -32,11 +36,20 @@ private val PsiMember.isKotlinAndProtected: Boolean
private val PsiMember.isKotlinAutogeneratedMethod: Boolean
get() = this is KtLightMethod && navigationElement is KtClass

fun Iterable<MemberInfo>.filterTestableMethods(): List<MemberInfo> = this
private val PsiMethod.canBeCalledStatically: Boolean
get() = isStatic || containingClass?.isStatic ?: throw IllegalStateException("No containing class found for method $this")

private val PsiMethod.isUntestableMethodOfAbstractOrInterface: Boolean
get() {
val hasAbstractContext = generateSequence(containingClass) { it.containingClass }.any { it.isAbstract || it.isInterface }
return hasAbstractContext && !canBeCalledStatically
}

private fun Iterable<MemberInfo>.filterTestableMethods(): List<MemberInfo> = this
.filterWhen(UtSettings.skipTestGenerationForSyntheticAndImplicitlyDeclaredMethods) {
it.member !is SyntheticElement && !it.member.isKotlinAutogeneratedMethod
}
.filterNot { it.member.isAbstract }
.filterNot { (it.member as PsiMethod).isUntestableMethodOfAbstractOrInterface }
.filterNot { it.member.isKotlinGetterOrSetter }
.filterNot { it.member.isKotlinAndProtected }

Expand Down