diff --git a/build.sbt b/build.sbt index d37f00c..c165df8 100644 --- a/build.sbt +++ b/build.sbt @@ -1,13 +1,13 @@ import org.jetbrains.sbtidea.{AutoJbr, JbrPlatform} lazy val scala213 = "2.13.12" -lazy val scalaPluginVersion = "2024.2.5" +lazy val scalaPluginVersion = "2024.2.11" lazy val minorVersion = "0" lazy val buildVersion = sys.env.getOrElse("ZIO_INTELLIJ_BUILD_NUMBER", minorVersion) lazy val pluginVersion = s"2024.2.34.$buildVersion" ThisBuild / intellijPluginName := "zio-intellij" -ThisBuild / intellijBuild := "242.16677.21" +ThisBuild / intellijBuild := "242.20224.91" ThisBuild / jbrInfo := AutoJbr(explicitPlatform = Some(JbrPlatform.osx_aarch64)) Global / intellijAttachSources := true diff --git a/src/main/scala/zio/intellij/inspections/mistakes/NothingInContravariantPositionInspection.scala b/src/main/scala/zio/intellij/inspections/mistakes/NothingInContravariantPositionInspection.scala index 561bfde..e6959a0 100644 --- a/src/main/scala/zio/intellij/inspections/mistakes/NothingInContravariantPositionInspection.scala +++ b/src/main/scala/zio/intellij/inspections/mistakes/NothingInContravariantPositionInspection.scala @@ -4,11 +4,11 @@ import com.intellij.codeInspection._ import com.intellij.psi.PsiElement import org.jetbrains.annotations.Nls import org.jetbrains.plugins.scala.codeInspection.PsiElementVisitorSimple -import org.jetbrains.plugins.scala.codeInspection.collections.isOfClassFrom import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScParameterizedTypeElement import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypeParametersOwner +import zio.intellij.inspections.isOfClassFrom import zio.intellij.utils.TypeCheckUtils.zioLikePackages class NothingInContravariantPositionInspection extends LocalInspectionTool { diff --git a/src/main/scala/zio/intellij/inspections/package.scala b/src/main/scala/zio/intellij/inspections/package.scala index 9730e38..cd8ef42 100644 --- a/src/main/scala/zio/intellij/inspections/package.scala +++ b/src/main/scala/zio/intellij/inspections/package.scala @@ -1,13 +1,16 @@ package zio.intellij -import com.intellij.psi.{PsiAnnotation, PsiElement} -import org.jetbrains.plugins.scala.codeInspection.collections.{isOfClassFrom, _} +import com.intellij.psi.{PsiAnnotation, PsiClass, PsiElement} +import org.jetbrains.plugins.scala.codeInspection.collections._ +import org.jetbrains.plugins.scala.extensions.PsiClassExt import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.{ScPattern, ScReferencePattern, ScWildcardPattern} import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScNamedElement import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScMember, ScObject, ScTemplateDefinition, ScTrait} +import org.jetbrains.plugins.scala.lang.psi.types.ScType +import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import zio.intellij.utils.TypeCheckUtils._ import zio.intellij.utils.types._ @@ -17,6 +20,25 @@ package object inspections { private[inspections] val `.map` = invocation("map").from(likeCollectionClasses) } + def isOfClassFrom(expr: ScExpression, patterns: Seq[String]): Boolean = { + val typ = expr.`type`().toOption + typ.exists(isOfClassFrom(_, patterns)) + } + + def isOfClassFrom(`type`: ScType, patterns: Seq[String]): Boolean = { + val typeExtracted = `type`.tryExtractDesignatorSingleton + isOfClassFromForExtractedType(typeExtracted, patterns) + } + + private def isOfClassFromForExtractedType(typeExtracted: ScType, patterns: Seq[String]): Boolean = { + val clazz = typeExtracted.extractClass + clazz.exists(qualifiedNameFitToPatterns(_, patterns)) + } + + private def qualifiedNameFitToPatterns(clazz: PsiClass, patterns: Seq[String]) = + Option(clazz).flatMap(c => Option(c.qualifiedName)) + .exists(ScalaNamesUtil.nameFitToPatterns(_, patterns, strict = false)) + object zioMethods { val `.*>` : Qualified = invocation("*>").from(zioLikePackages) val `.zipRight`: Qualified = invocation("zipRight").from(zioLikePackages) diff --git a/src/main/scala/zio/intellij/testsupport/ZTestFramework.scala b/src/main/scala/zio/intellij/testsupport/ZTestFramework.scala index 4468a25..e315f2b 100644 --- a/src/main/scala/zio/intellij/testsupport/ZTestFramework.scala +++ b/src/main/scala/zio/intellij/testsupport/ZTestFramework.scala @@ -1,7 +1,6 @@ package zio.intellij.testsupport import com.intellij.psi.PsiElement -import org.jetbrains.plugins.scala.codeInspection.collections.isOfClassFrom import org.jetbrains.plugins.scala.extensions.{ObjectExt, PsiElementExt, ResolvesTo} import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition @@ -10,7 +9,8 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.ScClassImpl import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.testingSupport.test.AbstractTestFramework import zio.intellij.ZioIcon -import zio.intellij.testsupport.ZTestFramework.{expandsToTestMethod, ZIO1SpecFQN, ZIO2SpecFQN} +import zio.intellij.inspections.isOfClassFrom +import zio.intellij.testsupport.ZTestFramework.{ZIO1SpecFQN, ZIO2SpecFQN, expandsToTestMethod} import zio.intellij.utils.TypeCheckUtils.zioTestPackage import javax.swing.Icon diff --git a/src/main/scala/zio/intellij/utils/TypeCheckUtils.scala b/src/main/scala/zio/intellij/utils/TypeCheckUtils.scala index 5583ba3..1d6d004 100644 --- a/src/main/scala/zio/intellij/utils/TypeCheckUtils.scala +++ b/src/main/scala/zio/intellij/utils/TypeCheckUtils.scala @@ -1,9 +1,9 @@ package zio.intellij.utils -import org.jetbrains.plugins.scala.codeInspection.collections.isOfClassFrom import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult +import zio.intellij.inspections.isOfClassFrom import zio.intellij.utils.types.{ZLayerTypes, ZioTypes} object TypeCheckUtils {