How to use fetchSynonymContext method of org.spekframework.intellij.domain.ScopeDescriptorCache class

Best Spek code snippet using org.spekframework.intellij.domain.ScopeDescriptorCache.fetchSynonymContext

ScopeDescriptorCache.kt

Source:ScopeDescriptorCache.kt Github

copy

Full Screen

...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 }29 fun fromClassOrObject(clz: KtClassOrObject): ScopeDescriptor.Group? {30 if (clz.isAbstract() || clz.isObjectLiteral() || !isSpekSubclass(clz)) {31 return null32 }33 val fqName = checkNotNull(clz.fqName).asString()34 var cached = cache.getOrDefault(fqName, null)35 if (cached == null || cached.first < clz.modificationStamp) {36 cached = clz.modificationStamp to buildDescriptor(clz)37 cache[fqName] = cached38 }39 return checkNotNull(cached).second40 }41 private fun buildDescriptor(clz: KtClassOrObject): ScopeDescriptor.Group {42 val info = KtClassInfoUtil.createClassOrObjectInfo(clz)43 val builder = PathBuilder()44 if (info.containingPackageFqName.asString().isNotBlank()) {45 builder.appendPackage(info.containingPackageFqName.asString())46 }47 val path = builder48 .append(checkNotNull(clz.fqName).shortName().asString())49 .build()50 val superTypeCall = clz.superTypeListEntries.filterIsInstance<KtSuperTypeCallEntry>()51 .firstOrNull()52 val children = mutableListOf<ScopeDescriptor>()53 if (superTypeCall != null) {54 val lambda = superTypeCall.valueArguments.map { it.getArgumentExpression() }55 .filterIsInstance<KtLambdaExpression>()56 .firstOrNull()57 if (lambda != null) {58 lambda.bodyExpression?.let { body ->59 children.addAll(buildScopes(path, body))60 }61 }62 }63 return ScopeDescriptor.Group(path, clz, false, true, children.toList()).apply {64 index[path.serialize()] = this65 }66 }67 private fun buildScopes(parent: Path, block: KtBlockExpression): List<ScopeDescriptor> {68 val callExpressions = PsiTreeUtil.getChildrenOfTypeAsList(block, KtCallExpression::class.java)69 return callExpressions.mapNotNull { callExpression ->70 val synonymContext = fetchSynonymContext(callExpression)71 when {72 synonymContext != null -> callExpression to synonymContext73 else -> null74 }75 }.mapNotNull { (callExpression, synonymContext) ->76 try {77 val description = synonymContext.constructDescription(callExpression)78 val path = PathBuilder(parent)79 .append(description)80 .build()81 val descriptor = when (synonymContext.synonym.type) {82 PsiSynonymType.GROUP -> {83 val lambdaArgument = callExpression.lambdaArguments.firstOrNull()84 val children = mutableListOf<ScopeDescriptor>()85 if (lambdaArgument != null) {86 val lambdaExpression = lambdaArgument.getLambdaExpression()87 if (lambdaExpression != null) {88 lambdaExpression.bodyExpression?.let { body ->89 children.addAll(buildScopes(path, body))90 }91 }92 }93 ScopeDescriptor.Group(94 path, callExpression, synonymContext.isExcluded(),95 synonymContext.isRunnable(), children.toList()96 )97 }98 PsiSynonymType.TEST -> ScopeDescriptor.Test(99 path, callExpression, synonymContext.isExcluded(), synonymContext.isRunnable()100 )101 }102 index[path.serialize()] = descriptor103 descriptor104 } catch (e: UnsupportedFeatureException) {105 // avoid ide from throwing up106 null107 }108 }109 }110 private fun fetchSynonymContext(callExpression: KtCallExpression): SynonymContext? {111 return fetchNamedFunction(callExpression)?.let(::extractSynonymContext)112 }113 private fun fetchNamedFunction(callExpression: KtCallExpression): KtNamedFunction? {114 val mainReference = callExpression.calleeExpression?.mainReference115 val resolved = mainReference?.resolve()116 if (resolved is KtNamedFunction) {117 return resolved118 }119 return null120 }121 private fun extractSynonymContext(function: KtNamedFunction): SynonymContext? {122 val lightMethod = function.toLightMethods().firstOrNull()123 if (lightMethod != null) {124 val synonym = lightMethod.annotations...

Full Screen

Full Screen

fetchSynonymContext

Using AI Code Generation

copy

Full Screen

1ScopeDescriptorCache scopeDescriptorCache = new ScopeDescriptorCache();2SynonymContext synonymContext = scopeDescriptorCache.fetchSynonymContext(testMethod);3ScopeDescriptor scopeDescriptor = scopeDescriptorCache.fetchScopeDescriptor(synonymContext);4ScopeDescriptor scopeDescriptor = scopeDescriptorCache.fetchScopeDescriptor(synonymContext);5ScopeDescriptorCache scopeDescriptorCache = new ScopeDescriptorCache();6SynonymContext synonymContext = scopeDescriptorCache.fetchSynonymContext(testMethod);7ScopeDescriptor scopeDescriptor = scopeDescriptorCache.fetchScopeDescriptor(synonymContext);

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Spek automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful