Skip to content

Commit

Permalink
IDEA 2042.x upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
hmemcpy committed Jul 19, 2024
1 parent b939973 commit b1955e3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 24 additions & 2 deletions src/main/scala/zio/intellij/inspections/package.scala
Original file line number Diff line number Diff line change
@@ -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._

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/zio/intellij/testsupport/ZTestFramework.scala
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/zio/intellij/utils/TypeCheckUtils.scala
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit b1955e3

Please sign in to comment.