Skip to content

Commit

Permalink
Merge pull request #31 from just-ai/201/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
veptechno authored Dec 6, 2021
2 parents 3e3573b + c7b588d commit 616ef06
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 32 deletions.
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 = 201-0.5.2
pluginVersion = 201-0.5.3

pluginSinceBuild = 201
pluginUntilBuild = 201.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.intellij.notification.NotificationGroup
import com.intellij.notification.NotificationType
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project
import com.justai.jaicf.plugin.scenarios.psi.PathValueMethodsService
import com.justai.jaicf.plugin.scenarios.psi.MethodsUsedPathValueService
import com.justai.jaicf.plugin.utils.VersionService
import com.justai.jaicf.plugin.utils.isJaicfInclude
import com.justai.jaicf.plugin.utils.isSupportedJaicfInclude
Expand Down Expand Up @@ -42,7 +42,7 @@ class JaicfSourcesMissedNotifier(private val project: Project) : ValidatingNotif
NotificationGroup("Jaicf Plugin Group", NotificationDisplayType.STICKY_BALLOON, true)

private val versionService = VersionService.getInstance(project)
private val valueMethodsService = PathValueMethodsService.getInstance(project)
private val valueMethodsService = MethodsUsedPathValueService.getInstance(project)

override fun isValid() = valueMethodsService.jaicfMethods.isNotEmpty() || !versionService.isSupportedJaicfInclude

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.justai.jaicf.plugin.scenarios.linker

import com.intellij.openapi.project.Project
import com.justai.jaicf.plugin.scenarios.psi.StatePathExpressionsService
import com.justai.jaicf.plugin.scenarios.psi.PathValueExpressionsService
import com.justai.jaicf.plugin.scenarios.psi.ScenarioDataService
import com.justai.jaicf.plugin.scenarios.psi.TopLevelAppendDataService
import com.justai.jaicf.plugin.scenarios.psi.dto.Scenario
Expand All @@ -20,7 +20,7 @@ val State.allStates

val State.usages: List<StatePathExpression>
get() {
val expressionsService = StatePathExpressionsService.getInstance(project)
val expressionsService = PathValueExpressionsService.getInstance(project)
return expressionsService.getExpressions()
.filter { this in transitToState(it.usePoint, it.declaration).statesOrSuggestions() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import org.jetbrains.kotlin.idea.search.projectScope
import org.jetbrains.kotlin.psi.KtFunction
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType

class StatePathExpressionsService(project: Project) : JaicfService(project) {
class PathValueExpressionsService(project: Project) : JaicfService(project) {

private val pathValueService = PathValueMethodsService(project)
private val pathValueService = MethodsUsedPathValueService(project)

private val expressionsMap = LiveMapByFiles(project) { file ->
pathValueService.methods
Expand All @@ -30,22 +30,22 @@ class StatePathExpressionsService(project: Project) : JaicfService(project) {
.flatMap { it.pathExpressionsOfBoundedBlock }
}

fun getExpressions() = expressionsMap.getValues().flatten()
fun getExpressions() = expressionsMap.getNotNullValues().flatten()

companion object {
fun getInstance(element: PsiElement): StatePathExpressionsService? =
fun getInstance(element: PsiElement): PathValueExpressionsService? =
if (element.isExist) getInstance(element.project)
else null

fun getInstance(project: Project): StatePathExpressionsService =
ServiceManager.getService(project, StatePathExpressionsService::class.java)
fun getInstance(project: Project): PathValueExpressionsService =
ServiceManager.getService(project, PathValueExpressionsService::class.java)
}
}

class PathValueMethodsService(project: Project) : JaicfService(project) {
class MethodsUsedPathValueService(project: Project) : JaicfService(project) {

val methods
get() = (jaicfMethods + projectMethods.getValues().flatten()).filter { it.isExist }
get() = (jaicfMethods + projectMethods.getNotNullValues().flatten()).filter { it.isExist }

val jaicfMethods: List<KtFunction> by cached(LibraryModificationTracker.getInstance(project)) {
if (enabled) findUsages(project.allScope() - project.projectScope())
Expand All @@ -68,7 +68,7 @@ class PathValueMethodsService(project: Project) : JaicfService(project) {
}

companion object {
fun getInstance(project: Project): PathValueMethodsService =
ServiceManager.getService(project, PathValueMethodsService::class.java)
fun getInstance(project: Project): MethodsUsedPathValueService =
ServiceManager.getService(project, MethodsUsedPathValueService::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ScenarioDataService(project: Project) : JaicfService(project) {
else null

fun getScenarios() =
if (enabled) scenariosMap.getValues().flatten()
if (enabled) scenariosMap.getNotNullValues().flatten()
else emptyList()

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TopLevelAppendDataService(project: Project) : JaicfService(project) {
}

fun getAppends() =
if (enabled) appendsMap.getValues().flatten()
if (enabled) appendsMap.getNotNullValues().flatten()
else emptyList()

private fun getTopLevelAppendsUsages(scope: GlobalSearchScope): List<KtCallExpression> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ private val KtCallExpression.annotatedLambdaArgument: KtLambdaExpression?
val KtCallExpression.annotatedLambdaBlockInDeclaration: KtLambdaExpression?
get() = this.declaration?.bodyExpression?.findChildOfType<KtAnnotatedExpression>()?.baseExpression as? KtLambdaExpression

fun KtCallExpression.getAnnotatedStringTemplatesInDeclaration(name: String): List<KtStringTemplateExpression> {
val bodyExpression = this.declaration?.bodyExpression ?: return emptyList()

val annotationsExpressions = bodyExpression.findChildrenOfType<KtAnnotatedExpression>().filter {
it.annotationEntries.any { entry -> entry.shortName?.asString() == name }
}

return annotationsExpressions.mapNotNull { it.baseExpression as? KtStringTemplateExpression }
}

val KtCallExpression.isStateDeclaration: Boolean
get() = getMethodAnnotations(STATE_DECLARATION_ANNOTATION_NAME).isNotEmpty()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class LiveMapByFiles<T>(val project: Project, private val valueProvider: (KtFile

operator fun get(file: KtFile): T? = cachedMap[file]?.value

fun getValues() = cachedMap.values.map { it.value }
fun getNotNullValues() = cachedMap.values.mapNotNull { it.value }

private fun createCachedValue(file: KtFile) =
CachedValuesManager.getManager(project).createCachedValue {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.justai.jaicf.plugin.utils

import com.intellij.psi.PsiElement
import com.justai.jaicf.plugin.scenarios.psi.builders.getAnnotatedStringTemplatesInDeclaration
import com.justai.jaicf.plugin.utils.StatePathExpression.Joined
import com.justai.jaicf.plugin.utils.StatePathExpression.Separated
import org.jetbrains.kotlin.idea.debugger.sequence.psi.receiverValue
import org.jetbrains.kotlin.psi.KtAnnotatedExpression
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtCallableDeclaration
Expand All @@ -27,7 +27,7 @@ val KtCallExpression.innerPathExpressions: List<StatePathExpression>
if (hasReceiverAnnotatedBy(PATH_ARGUMENT_ANNOTATION_NAME))
(this.receiverValue() as? ExpressionReceiver)?.expression?.let { expressions += it }

expressions += getAnnotatedStringTemplatesInDeclaration(PATH_ARGUMENT_ANNOTATION_NAME)
expressions += getAnnotatedExpressionsInDeclaration(PATH_ARGUMENT_ANNOTATION_NAME)

expressions.filterNot { it.isNull() }.map { StatePathExpression.create(this, it) }
} else {
Expand Down Expand Up @@ -144,3 +144,13 @@ val StatePathExpression.holderExpression: KtExpression
is Joined -> declaration
is Separated -> (usePoint as? KtCallExpression)?.nameReferenceExpression() ?: usePoint
}

private fun KtCallExpression.getAnnotatedExpressionsInDeclaration(name: String): List<KtExpression> {
val bodyExpression = this.declaration?.bodyExpression ?: return emptyList()

val annotatedExpressions = bodyExpression.findChildrenOfType<KtAnnotatedExpression>().filter {
it.annotationEntries.any { entry -> entry.shortName?.asString() == name }
}

return annotatedExpressions.mapNotNull { it.baseExpression }
}
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<projectService serviceImplementation="com.justai.jaicf.plugin.utils.VersionService"/>
<projectService
serviceImplementation="com.justai.jaicf.plugin.providers.ReferenceContributorsAvailabilityService"/>
<projectService serviceImplementation="com.justai.jaicf.plugin.scenarios.psi.StatePathExpressionsService"/>
<projectService serviceImplementation="com.justai.jaicf.plugin.scenarios.psi.PathValueMethodsService"/>
<projectService serviceImplementation="com.justai.jaicf.plugin.scenarios.psi.PathValueExpressionsService"/>
<projectService serviceImplementation="com.justai.jaicf.plugin.scenarios.psi.MethodsUsedPathValueService"/>
<projectService serviceImplementation="com.justai.jaicf.plugin.scenarios.psi.TopLevelAppendDataService"/>
<projectService serviceImplementation="com.justai.jaicf.plugin.scenarios.psi.ScenarioDataService"/>
<projectService serviceImplementation="com.justai.jaicf.plugin.scenarios.linker.ScenarioReferenceResolver"/>
Expand Down

0 comments on commit 616ef06

Please sign in to comment.