diff --git a/gradle.properties b/gradle.properties index 569517d..e80dc5c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ pluginGroup = com.justai.jaicf.plugin pluginName = Jaicf Plugin -pluginVersion = 202-0.5.2 +pluginVersion = 202-0.5.3 pluginSinceBuild = 202 pluginUntilBuild = 202.* diff --git a/src/main/kotlin/com/justai/jaicf/plugin/notifications/JaicfNotifiers.kt b/src/main/kotlin/com/justai/jaicf/plugin/notifications/JaicfNotifiers.kt index efb6a58..b1e6531 100644 --- a/src/main/kotlin/com/justai/jaicf/plugin/notifications/JaicfNotifiers.kt +++ b/src/main/kotlin/com/justai/jaicf/plugin/notifications/JaicfNotifiers.kt @@ -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 @@ -39,7 +39,7 @@ class JaicfUnsupportedNotifier(private val project: Project) : ValidatingNotifie class JaicfSourcesMissedNotifier(private val project: Project) : ValidatingNotifier() { 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 diff --git a/src/main/kotlin/com/justai/jaicf/plugin/scenarios/linker/Linker.kt b/src/main/kotlin/com/justai/jaicf/plugin/scenarios/linker/Linker.kt index 0bb9ac3..d3b3603 100644 --- a/src/main/kotlin/com/justai/jaicf/plugin/scenarios/linker/Linker.kt +++ b/src/main/kotlin/com/justai/jaicf/plugin/scenarios/linker/Linker.kt @@ -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 @@ -20,7 +20,7 @@ val State.allStates val State.usages: List get() { - val expressionsService = StatePathExpressionsService.getInstance(project) + val expressionsService = PathValueExpressionsService.getInstance(project) return expressionsService.getExpressions() .filter { this in transitToState(it.usePoint, it.declaration).statesOrSuggestions() } } diff --git a/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/StatePathExpressionsService.kt b/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/PathValueExpressionsService.kt similarity index 74% rename from src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/StatePathExpressionsService.kt rename to src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/PathValueExpressionsService.kt index 4a9a217..7153876 100644 --- a/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/StatePathExpressionsService.kt +++ b/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/PathValueExpressionsService.kt @@ -18,9 +18,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 @@ -29,22 +29,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 = - project.getService(StatePathExpressionsService::class.java) + fun getInstance(project: Project): PathValueExpressionsService = + project.getService(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 by cached(LibraryModificationTracker.getInstance(project)) { if (enabled) findUsages(project.allScope() - project.projectScope()) @@ -67,7 +67,7 @@ class PathValueMethodsService(project: Project) : JaicfService(project) { } companion object { - fun getInstance(project: Project): PathValueMethodsService = - project.getService(PathValueMethodsService::class.java) + fun getInstance(project: Project): MethodsUsedPathValueService = + project.getService(MethodsUsedPathValueService::class.java) } } diff --git a/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/ScenarioDataService.kt b/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/ScenarioDataService.kt index aac2973..cb9f0b2 100644 --- a/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/ScenarioDataService.kt +++ b/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/ScenarioDataService.kt @@ -36,7 +36,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 { diff --git a/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/TopLevelAppendDataService.kt b/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/TopLevelAppendDataService.kt index e32a7cd..783bd3f 100644 --- a/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/TopLevelAppendDataService.kt +++ b/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/TopLevelAppendDataService.kt @@ -27,7 +27,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 = diff --git a/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/builders/StateBuilder.kt b/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/builders/StateBuilder.kt index 72b2901..7f80d4e 100644 --- a/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/builders/StateBuilder.kt +++ b/src/main/kotlin/com/justai/jaicf/plugin/scenarios/psi/builders/StateBuilder.kt @@ -55,16 +55,6 @@ private val KtCallExpression.annotatedLambdaArgument: KtLambdaExpression? val KtCallExpression.annotatedLambdaBlockInDeclaration: KtLambdaExpression? get() = this.declaration?.bodyExpression?.findChildOfType()?.baseExpression as? KtLambdaExpression -fun KtCallExpression.getAnnotatedStringTemplatesInDeclaration(name: String): List { - val bodyExpression = this.declaration?.bodyExpression ?: return emptyList() - - val annotationsExpressions = bodyExpression.findChildrenOfType().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() diff --git a/src/main/kotlin/com/justai/jaicf/plugin/utils/CachedValues.kt b/src/main/kotlin/com/justai/jaicf/plugin/utils/CachedValues.kt index ba45507..b6cd3c9 100644 --- a/src/main/kotlin/com/justai/jaicf/plugin/utils/CachedValues.kt +++ b/src/main/kotlin/com/justai/jaicf/plugin/utils/CachedValues.kt @@ -51,7 +51,7 @@ class LiveMapByFiles(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 { diff --git a/src/main/kotlin/com/justai/jaicf/plugin/utils/StatePathExtractor.kt b/src/main/kotlin/com/justai/jaicf/plugin/utils/PathValueExtractor.kt similarity index 90% rename from src/main/kotlin/com/justai/jaicf/plugin/utils/StatePathExtractor.kt rename to src/main/kotlin/com/justai/jaicf/plugin/utils/PathValueExtractor.kt index 15b7af9..b3570a5 100644 --- a/src/main/kotlin/com/justai/jaicf/plugin/utils/StatePathExtractor.kt +++ b/src/main/kotlin/com/justai/jaicf/plugin/utils/PathValueExtractor.kt @@ -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 @@ -27,7 +27,7 @@ val KtCallExpression.innerPathExpressions: List 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 { @@ -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 { + val bodyExpression = this.declaration?.bodyExpression ?: return emptyList() + + val annotatedExpressions = bodyExpression.findChildrenOfType().filter { + it.annotationEntries.any { entry -> entry.shortName?.asString() == name } + } + + return annotatedExpressions.mapNotNull { it.baseExpression } +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 0602cbd..9f21d11 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -12,8 +12,8 @@ - - + +