Skip to content

Commit

Permalink
Merge pull request #21 from just-ai/193/dev
Browse files Browse the repository at this point in the history
Relese 193-0.5.2
  • Loading branch information
veptechno authored Nov 16, 2021
2 parents 5b11b88 + 5791b55 commit eaf15d1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
JAICF IDEA Plugin enabled enhanced Scenario DSL support for Intellij IDEA. It provides intelligent state completions,
inspections and templates to improve speed and quality of Scenario writing.

<img src="https://raw.githubusercontent.com/veptechno/static/main/old-jaicf-plugin-in-scenario.png" alt="Plugin Demonstration" height="325" width="592">
<img src="https://raw.githubusercontent.com/veptechno/static/main/jaicf-plugin-in-scenario.png" alt="Plugin Demonstration" height="382" width="625">

### Feature list:

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pluginGroup = com.justai.jaicf.plugin
pluginName = Jaicf Plugin
pluginVersion = 193-0.5.1
pluginVersion = 193-0.5.2

pluginSinceBuild = 192
pluginUntilBuild = 193.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,18 @@ private val MemberDescriptor.isOpenOrAbstract: Boolean
private val MemberDescriptor.isFinal: Boolean
get() = modality == Modality.FINAL

private fun KotlinType.findOverridingFunction(descriptor: FunctionDescriptor) = (supertypes() + this)
private fun KotlinType.findOverridingFunction(descriptor: FunctionDescriptor) = (listOf(this) + supertypes())
.mapNotNull { it.toClassDescriptor }
.firstOrNull { supertype ->
supertype.findDeclaredFunction(
descriptor.name.asString(),
false
) { it.overriddenDescriptors.contains(descriptor) } != null
) { it.allOverriddenDescriptors.contains(descriptor) } != null
}

private val FunctionDescriptor.allOverriddenDescriptors: Collection<FunctionDescriptor>
get() = overriddenDescriptors.flatMap { it.allOverriddenDescriptors + it }

private fun KtTypeReference.classForRefactor(): KtClass? {
val bindingContext = analyze(BodyResolveMode.PARTIAL)
val type = bindingContext[BindingContext.TYPE, this] ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ class ScenarioReferenceResolver(project: Project) : JaicfService(project) {
private val scenarioService = ScenarioDataService.getInstance(project)

private val resolvedReferences by cached(PsiModificationTracker.MODIFICATION_COUNT) {
mutableMapOf<KtReferenceExpression, Scenario?>()
mutableMapOf<Pair<KtReferenceExpression, State?>, Scenario?>()
}

fun resolve(scenarioReference: KtReferenceExpression, boundedState: State? = null): Scenario? {
if (scenarioReference.isRemoved || !enabled) return null

resolvedReferences?.get(scenarioReference)?.let { return it }
resolvedReferences?.get(scenarioReference to boundedState)?.let { return it }

val body = getScenarioBody(scenarioReference, boundedState) ?: return null
return resolveScenario(body)?.also {
resolvedReferences?.set(scenarioReference, it)
resolvedReferences?.set(scenarioReference to boundedState, it)
}
}

Expand All @@ -64,10 +64,14 @@ class ScenarioReferenceResolver(project: Project) : JaicfService(project) {
}

is KtParameter -> {
(resolvedElement.defaultValue as? KtReferenceExpression)?.let {
return getScenarioBody(it)
}

val parameterName = resolvedElement.name ?: return null
// TODO Maybe make a better search for value of parameter
val argumentExpression =
boundedState?.stateExpression?.argumentExpressionOrDefaultValue(parameterName) as? KtReferenceExpression

return argumentExpression?.let { getScenarioBody(it) }
}

Expand All @@ -76,23 +80,25 @@ class ScenarioReferenceResolver(project: Project) : JaicfService(project) {
}

else -> {
if (scenarioReference !is KtCallExpression) return null
return (scenarioReference as? KtCallExpression)?.let(::getScenarioBody)
}
}
}

if (scenarioReference.isStateDeclaration) return scenarioReference
private fun getScenarioBody(callExpression: KtCallExpression): KtExpression? {
if (callExpression.isStateDeclaration) return callExpression

return when (val resolved = scenarioReference.referenceExpression()?.resolve()) {
is KtNamedFunction -> (resolved.initializer as? KtCallExpression)?.let {
if (it.isStateDeclaration) it else null
}
return when (val resolved = callExpression.referenceExpression()?.resolve()) {
is KtNamedFunction -> (resolved.initializer as? KtCallExpression)?.let {
if (it.isStateDeclaration) it else null
}

is KtClass -> resolved.body?.scenarioBody
is KtClass -> resolved.body?.scenarioBody

is KtPrimaryConstructor ->
scenarioReference.argumentExpressionOrDefaultValue(SCENARIO_MODEL_FIELD_NAME)
is KtPrimaryConstructor ->
callExpression.argumentExpressionOrDefaultValue(SCENARIO_MODEL_FIELD_NAME)

else -> null
}
}
else -> null
}
}

Expand Down

0 comments on commit eaf15d1

Please sign in to comment.