Best Spek code snippet using org.spekframework.intellij.domain.ScopeDescriptorCache
ScopeDescriptorCache.kt
Source:ScopeDescriptorCache.kt
...10import org.jetbrains.kotlin.resolve.lazy.data.KtClassInfoUtil11import org.spekframework.spek2.runtime.scope.Path12import org.spekframework.spek2.runtime.scope.PathBuilder13import java.util.concurrent.ConcurrentHashMap14class ScopeDescriptorCache: ProjectComponent {15 private val cache = ConcurrentHashMap<String, Pair<Long, ScopeDescriptor.Group>?>()16 private val index = ConcurrentHashMap<String, ScopeDescriptor?>()17 fun findDescriptor(path: Path): ScopeDescriptor? {18 return index.getOrDefault(path.serialize(), null)19 }20 fun fromCallExpression(callExpression: KtCallExpression): ScopeDescriptor? {21 val context = fetchSynonymContext(callExpression)22 if (context != null) {23 return PsiTreeUtil.getParentOfType(callExpression, KtClassOrObject::class.java)?.let {24 fromClassOrObject(it)?.findDescriptorForElement(callExpression)25 }26 }27 return null28 }...
SpekRunConfigurationProducer.kt
Source:SpekRunConfigurationProducer.kt
...16import org.jetbrains.kotlin.platform.IdePlatformKind17import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind18import org.jetbrains.kotlin.psi.KtCallExpression19import org.jetbrains.kotlin.psi.KtClassOrObject20import org.spekframework.intellij.domain.ScopeDescriptorCache21import org.spekframework.intellij.support.SpekCommonProgramRunConfigurationParameters.GeneratedNameHint22import org.spekframework.intellij.util.maybeGetContext23import org.spekframework.spek2.runtime.scope.Path24import org.spekframework.spek2.runtime.scope.PathBuilder25abstract class SpekRunConfigurationProducer(val producerType: ProducerType, type: SpekConfigurationType)26 : RunConfigurationProducer<SpekRunConfiguration<*>>(type) {27 override fun isConfigurationFromContext(configuration: SpekRunConfiguration<*>,28 context: ConfigurationContext): Boolean {29 val descriptorCache = checkNotNull(30 context.project.getComponent(ScopeDescriptorCache::class.java)31 )32 return context.psiLocation?.let {33 var nameHint: GeneratedNameHint? = null34 val path = if (it is PsiDirectory) {35 getPathFromDir(context, it)36 nameHint = GeneratedNameHint.PACKAGE37 } else if (it is PsiPackage) {38 getPathFromPackage(it)39 nameHint = GeneratedNameHint.PACKAGE40 } else {41 val elementContext = maybeGetContext(it)42 val descriptor = when (elementContext) {43 is KtClassOrObject -> {44 nameHint = GeneratedNameHint.CLASS45 descriptorCache.fromClassOrObject(elementContext)46 }47 is KtCallExpression -> {48 nameHint = GeneratedNameHint.SCOPE49 descriptorCache.fromCallExpression(elementContext)50 }51 else -> null52 }53 if (descriptor != null && !descriptor.excluded && descriptor.runnable) {54 descriptor.path55 } else {56 null57 }58 }59 configuration.data.path == path && configuration.data.generatedNameHint == nameHint60 } ?: false61 }62 override fun setupConfigurationFromContext(configuration: SpekRunConfiguration<*>,63 context: ConfigurationContext,64 sourceElement: Ref<PsiElement>): Boolean {65 val descriptorCache = checkNotNull(66 context.project.getComponent(ScopeDescriptorCache::class.java)67 )68 return sourceElement.get().let {69 var nameHint: GeneratedNameHint? = null70 val path = if (it is PsiDirectory) {71 nameHint = GeneratedNameHint.PACKAGE72 getPathFromDir(context, it)73 } else if (it is PsiPackage) {74 nameHint = GeneratedNameHint.PACKAGE75 getPathFromPackage(it)76 } else {77 val elementContext = maybeGetContext(it)78 val descriptor = when (elementContext) {79 is KtClassOrObject -> {80 nameHint = GeneratedNameHint.CLASS...
SpekRunLineMarkerContributor.kt
Source:SpekRunLineMarkerContributor.kt
...9import org.jetbrains.kotlin.lexer.KtTokens10import org.jetbrains.kotlin.psi.KtCallExpression11import org.jetbrains.kotlin.psi.KtClassOrObject12import org.jetbrains.kotlin.psi.KtNameReferenceExpression13import org.spekframework.intellij.domain.ScopeDescriptorCache14import org.spekframework.intellij.util.maybeGetContext15class SpekRunLineMarkerContributor: RunLineMarkerContributor() {16 override fun getInfo(element: PsiElement): Info? {17 val descriptorCache = checkNotNull(18 element.project.getComponent(ScopeDescriptorCache::class.java)19 )20 if (element !is LeafPsiElement) {21 return null22 }23 if (element.elementType != KtTokens.IDENTIFIER) {24 return null25 }26 val parent = element.parent27 val descriptor = when (parent) {28 is KtClassOrObject -> descriptorCache.fromClassOrObject(parent)29 is KtNameReferenceExpression -> {30 val nameRefParent = parent.parent31 if (nameRefParent is KtCallExpression) {32 descriptorCache.fromCallExpression(nameRefParent)...
SpekSMTestLocator.kt
Source:SpekSMTestLocator.kt
...4import com.intellij.execution.testframework.sm.runner.SMTestLocator5import com.intellij.openapi.project.Project6import com.intellij.psi.PsiElement7import com.intellij.psi.search.GlobalSearchScope8import org.spekframework.intellij.domain.ScopeDescriptorCache9import org.spekframework.spek2.runtime.scope.PathBuilder10object SpekSMTestLocator: SMTestLocator {11 override fun getLocation(protocol: String, path: String, project: Project, scope: GlobalSearchScope): List<Location<PsiElement>> {12 if (protocol != "spek") {13 throw AssertionError("Unsupported protocol: $protocol.")14 }15 val descriptorCache = checkNotNull(16 project.getComponent(ScopeDescriptorCache::class.java)17 )18 val descriptor = descriptorCache.findDescriptor(19 PathBuilder.parse(path).build()20 )21 return if (descriptor != null) {22 listOf<Location<PsiElement>>(PsiLocation(descriptor.element.navigationElement))23 } else {24 emptyList()25 }26 }27}...
SpekImplicitUsageProvider.kt
Source:SpekImplicitUsageProvider.kt
2import com.intellij.codeInsight.daemon.ImplicitUsageProvider3import com.intellij.psi.PsiElement4import org.jetbrains.kotlin.asJava.classes.KtLightClass5import org.jetbrains.kotlin.psi.KtClassOrObject6import org.spekframework.intellij.domain.ScopeDescriptorCache7class SpekImplicitUsageProvider: ImplicitUsageProvider {8 override fun isImplicitWrite(element: PsiElement) = false9 override fun isImplicitRead(element: PsiElement) = false10 override fun isImplicitUsage(element: PsiElement): Boolean {11 val clz = when (element) {12 is KtClassOrObject -> element13 is KtLightClass -> element.kotlinOrigin14 else -> null15 }16 val descriptorCache = checkNotNull(17 element.project.getComponent(ScopeDescriptorCache::class.java)18 )19 return clz?.let {20 descriptorCache.fromClassOrObject(it) != null21 } ?: false22 }23}...
ScopeDescriptorCache
Using AI Code Generation
1val scopeDescriptorCache = Class.forName("org.spekframework.intellij.domain.ScopeDescriptorCache")2val getScopeDescriptor = scopeDescriptorCache.getMethod("getScopeDescriptor", PsiElement::class.java)3val scopeDescriptor = getScopeDescriptor.invoke(null, element)4val parentDescriptor = parent?.let { getScopeDescriptor.invoke(null, it) }5return SpekTestLocation(group, method)6}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!