Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 222-0.5.4 #42

Open
wants to merge 3 commits into
base: 222/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ fun properties(key: String) = project.findProperty(key).toString()
plugins {
id("java")

id("org.jetbrains.kotlin.jvm") version "1.4.21"
id("org.jetbrains.intellij") version "1.1.2"
id("org.jetbrains.kotlin.jvm") version "1.7.0"
id("org.jetbrains.intellij") version "1.13.3"
id("org.jetbrains.changelog") version "1.1.2"
}

Expand All @@ -22,7 +22,7 @@ repositories {
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-project:1.4.32")
implementation("org.jetbrains.kotlin:kotlin-project:1.7.0")
}

intellij {
Expand All @@ -42,11 +42,11 @@ changelog {

tasks {
withType<JavaCompile> {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
sourceCompatibility = "11"
targetCompatibility = "11"
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.jvmTarget = "11"
}

patchPluginXml {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ pluginVersion = 222-0.5.4
pluginSinceBuild = 222
pluginUntilBuild = 222.*

pluginVerifierIdeVersions = 2022.2.5
pluginVerifierIdeVersions = 2022.2

platformType = IC
platformVersion = 2022.2.5
platformVersion = 2022.2
platformDownloadSources = true

platformPlugins = com.intellij.java, org.jetbrains.kotlin
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.idea.actions.generate.findDeclaredFunction
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.isOverridable
import org.jetbrains.kotlin.idea.debugger.sequence.psi.receiverType
import org.jetbrains.kotlin.idea.core.receiverType
import org.jetbrains.kotlin.idea.core.receiverValue
import org.jetbrains.kotlin.idea.refactoring.isAbstract
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtClass
Expand Down Expand Up @@ -50,7 +51,7 @@ class UsesReactionUsageInspection : LocalInspectionTool() {
if (callExpression.reactionIsNotOverridden(reactionName)) {
registerWarning(
callExpression,
"$reactionName reaction is not implemented by this channel"
"$reactionName reaction is not implemented by this channel",
)
}
}
Expand All @@ -59,8 +60,11 @@ class UsesReactionUsageInspection : LocalInspectionTool() {
private fun KtCallExpression.reactionIsNotOverridden(reactionName: String): Boolean {
val reactionDescriptor = getReactionDescriptor(reactionName, this) ?: return false

return if (reactionDescriptor.isFinal) false
else receiverType()?.findOverridingFunction(reactionDescriptor) == null
return if (reactionDescriptor.isFinal) {
false
} else {
receiverValue()?.type?.findOverridingFunction(reactionDescriptor) == null
}
}

private fun getReactionDescriptor(reactionName: String, callExpression: KtCallExpression): FunctionDescriptor? {
Expand Down Expand Up @@ -95,7 +99,7 @@ class NotOverriddenReactionUsageInspection : LocalInspectionTool() {

registerWarning(
callExpression,
"$reactionName reaction is not implemented by this channel"
"$reactionName reaction is not implemented by this channel",
)
}

Expand All @@ -122,7 +126,7 @@ private fun KotlinType.findOverridingFunction(descriptor: FunctionDescriptor) =
.firstOrNull { supertype ->
supertype.findDeclaredFunction(
descriptor.name.asString(),
false
false,
) { it.allOverriddenDescriptors.contains(descriptor) } != null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class StatePathInspection : LocalInspectionTool() {
NavigateToState("Go to unrelated state declaration ${suggestion.fullPath}", suggestion)
)
}
//TODO fill all transition result or create correct else result
else -> {}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.justai.jaicf.plugin.utils
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiModificationTracker
import org.jetbrains.kotlin.idea.inspections.AbstractPrimitiveRangeToInspection.Companion.constantValueOrNull
import org.jetbrains.kotlin.idea.inspections.AbstractRangeInspection.Companion.constantValueOrNull
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtBlockStringTemplateEntry
import org.jetbrains.kotlin.psi.KtExpression
Expand Down
25 changes: 13 additions & 12 deletions src/main/kotlin/com/justai/jaicf/plugin/utils/PathValueExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.justai.jaicf.plugin.utils
import com.intellij.psi.PsiElement
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.idea.core.receiverValue
import org.jetbrains.kotlin.psi.KtAnnotatedExpression
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtCallExpression
Expand All @@ -24,28 +24,29 @@ val KtCallExpression.innerPathExpressions: List<StatePathExpression>
val expressions =
argumentExpressionsOrDefaultValuesByAnnotation(PATH_ARGUMENT_ANNOTATION_NAME).toMutableList()

if (hasReceiverAnnotatedBy(PATH_ARGUMENT_ANNOTATION_NAME))
(this.receiverValue() as? ExpressionReceiver)?.expression?.let { expressions += it }

if (hasReceiverAnnotatedBy(PATH_ARGUMENT_ANNOTATION_NAME)) {
(receiverValue() as? ExpressionReceiver)?.expression?.let { expressions += it }
}
expressions += getAnnotatedExpressionsInDeclaration(PATH_ARGUMENT_ANNOTATION_NAME)

expressions.filterNot { it.isNull() }.map { StatePathExpression.create(this, it) }
} else {
emptyList()
}


val KtBinaryExpression.innerPathExpressions: List<StatePathExpression>
get() {
return if (VersionService.getInstance(project).isSupportedJaicfInclude) {
val function = operationReference.resolveToSource ?: return emptyList()
val expressions = mutableListOf<KtExpression>()

if (function.hasReceiverAnnotatedBy(PATH_ARGUMENT_ANNOTATION_NAME))
if (function.hasReceiverAnnotatedBy(PATH_ARGUMENT_ANNOTATION_NAME)) {
left?.let { expressions += it }
}

if (function.valueParameters[0].annotationNames.contains(PATH_ARGUMENT_ANNOTATION_NAME))
if (function.valueParameters[0].annotationNames.contains(PATH_ARGUMENT_ANNOTATION_NAME)) {
right?.let { expressions += it }
}

expressions.map { StatePathExpression.create(this, it) }
} else {
Expand All @@ -60,7 +61,6 @@ private fun KtCallableDeclaration.hasReceiverAnnotatedBy(annotationName: String)
receiverTypeReference?.annotationEntries
?.any { it.shortName?.identifier == annotationName } == true


/**
* @returns [KtExpression] if this PsiElement contains path expression (reactions.go, reactions.buttons(vararg buttonsToState), etc)
* or null if no path expression found.
Expand All @@ -71,15 +71,16 @@ val PsiElement.boundedPathExpression: StatePathExpression?
listOf(
KtDotQualifiedExpression::class.java,
KtBinaryExpression::class.java,
KtValueArgument::class.java
)
KtValueArgument::class.java,
),
)

when (boundedElement) {
is KtDotQualifiedExpression -> {
val callExpression = boundedElement.getChildOfType<KtCallExpression>() ?: return null
if (!callExpression.hasReceiverAnnotatedBy(PATH_ARGUMENT_ANNOTATION_NAME))
if (!callExpression.hasReceiverAnnotatedBy(PATH_ARGUMENT_ANNOTATION_NAME)) {
return null
}

return (callExpression.receiverValue() as? ExpressionReceiver)?.expression?.let {
StatePathExpression.create(boundedElement, it)
Expand Down Expand Up @@ -111,7 +112,7 @@ val PsiElement.pathExpressionsOfBoundedBlock: List<StatePathExpression>
get() {
val boundedElement = getFirstBoundedElement(
targetTypes = listOf(KtBinaryExpression::class.java, KtCallExpression::class.java),
allowedTypes = listOf(KtNameReferenceExpression::class.java, KtOperationReferenceExpression::class.java)
allowedTypes = listOf(KtNameReferenceExpression::class.java, KtOperationReferenceExpression::class.java),
)

return when (boundedElement) {
Expand Down
29 changes: 17 additions & 12 deletions src/main/kotlin/com/justai/jaicf/plugin/utils/PsiElementUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.impl.source.tree.LeafPsiElement
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.SlowOperations.allowSlowOperations
import java.lang.Integer.min
import org.jetbrains.kotlin.idea.core.receiverValue
import org.jetbrains.kotlin.idea.debugger.sequence.psi.callName
import org.jetbrains.kotlin.idea.debugger.sequence.psi.receiverType
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.nj2k.postProcessing.resolve
import org.jetbrains.kotlin.nj2k.postProcessing.type
Expand Down Expand Up @@ -118,8 +117,11 @@ val KtCallElement.referenceExpression: KtReferenceExpression?

val KtReferenceExpression.resolveToSource: KtFunction?
get() = (safeResolve() as? KtFunction)?.let {
if (it.isBinary) it.source
else it
if (it.isBinary) {
it.source
} else {
it
}
}

fun KtReferenceExpression.safeResolve() =
Expand All @@ -139,19 +141,19 @@ inline fun <reified T : PsiElement> PsiElement.findChildrenOfType(): Collection<

fun KtCallExpression.isOverride(receiver: FqName, funName: String, parameters: List<String>? = null) =
try {
isExist && callName() == funName
&& isReceiverInheritedOf(receiver)
&& (parameters?.let { it == parametersTypes } ?: true)
isExist && callName() == funName &&
isReceiverInheritedOf(receiver) &&
(parameters?.let { it == parametersTypes } ?: true)
} catch (e: NullPointerException) {
false
}

fun KtCallExpression.isReceiverInheritedOf(baseClass: FqName): Boolean = allowSlowOperations<Boolean, Throwable> {
receiverFqName == baseClass || receiverType()?.supertypes()?.any { it.fqName == baseClass } ?: false
receiverFqName == baseClass || receiverValue()?.type?.supertypes()?.any { it.fqName == baseClass } ?: false
}

val KtCallExpression.receiverFqName: FqName?
get() = receiverType()?.fqName ?: declaration?.fqName?.parent()
get() = receiverValue()?.type?.fqName ?: declaration?.fqName?.parent()

fun KtCallExpression.nameReferenceExpression() = getChildOfType<KtNameReferenceExpression>()

Expand Down Expand Up @@ -219,15 +221,18 @@ fun KtValueArgument.parameter(): KtParameter? {
val callElement = getParentOfType<KtCallElement>(true) ?: return null
val params = callElement.declaration?.valueParameters ?: return null

if (params.isEmpty())
if (params.isEmpty()) {
return null
}

if (this is KtLambdaArgument)
if (this is KtLambdaArgument) {
return params.last()
}

val identifier = definedIdentifier
if (identifier != null)
if (identifier != null) {
return params.firstOrNull { it.name == identifier }
}

val indexOfArgument = callElement.valueArguments.indexOf(this)
return params[min(indexOfArgument, params.lastIndex)]
Expand Down