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

Fix most of the compilation warnings #241

Merged
merged 9 commits into from
Aug 10, 2022
13 changes: 11 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ lazy val ci = project("ci", "ci", publish = false)
lazy val api = project("api", "core/api", publish = true)
.settings(
libraryDependencies ++= Dependencies.pureConfig,
libraryDependencies += Dependencies.gson
libraryDependencies += Dependencies.gson,
libraryDependencies += Dependencies.scalaCollectionCompat
)
.cross

Expand Down Expand Up @@ -312,7 +313,15 @@ lazy val benchmarks212 = benchmarks(scala212)
def project(id: String, path: String, publish: Boolean): Project = {
Project(id, sbt.file(path))
.settings(scalafmtOnCompile := true)
.settings(scalacOptions ++= Seq("-Xlint:unused", "-Ywarn-unused"))
.settings(
scalacOptions ++= Seq(
"-Xlint:unused",
"-Ywarn-unused",
"-deprecation",
"-Ywarn-macros:after",
"-Wconf:msg=@nowarn annotation does not suppress any warnings:s" // due to false positive for IdeaLogInterceptor.scala
)
)
.settings(
(Keys.publish / skip) := !publish,
libraryDependencies ++= Dependencies.junit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import java.nio.file.StandardOpenOption
import java.nio.file.attribute.BasicFileAttributes
import java.util.zip.ZipInputStream

import scala.collection.JavaConverters._
import scala.collection.mutable
import scala.jdk.CollectionConverters._
import scala.util.Failure
import scala.util.Try
import scala.util.control.NonFatal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.virtuslab.ideprobe.jsonrpc

import java.io.Reader

import scala.reflect.ClassTag
import scala.util.Try

import com.google.gson._
Expand Down Expand Up @@ -69,7 +68,7 @@ object JsonRpc {
}
}

sealed abstract class Method[Parameters: ClassTag: ConfigConvert, Result: ClassTag: ConfigConvert] {
sealed abstract class Method[Parameters: ConfigConvert, Result: ConfigConvert] {
def name: String

def apply(f: Parameters => Result): SerializedJson => SerializedJson = { json =>
Expand All @@ -93,8 +92,8 @@ object JsonRpc {
}

object Method {
case class Notification[Parameters: ClassTag: ConfigConvert](name: String) extends Method[Parameters, Unit]
case class Request[Parameters: ClassTag: ConfigConvert, Result: ClassTag: ConfigConvert](name: String)
case class Notification[Parameters: ConfigConvert](name: String) extends Method[Parameters, Unit]
case class Request[Parameters: ConfigConvert, Result: ConfigConvert](name: String)
extends Method[Parameters, Result]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.virtuslab.ideprobe.jsonrpc

import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import scala.reflect.ClassTag

import org.virtuslab.ideprobe.Close
import org.virtuslab.ideprobe.jsonrpc.JsonRpc._
Expand All @@ -16,7 +15,7 @@ trait JsonRpcEndpoint extends AutoCloseable {

protected def handler: Handler

protected def sendRequest[A: ClassTag, B: ClassTag](method: Method[A, B], parameters: A): Future[B] = {
protected def sendRequest[A, B](method: Method[A, B], parameters: A): Future[B] = {
Future(method.encode(parameters)).flatMap { json =>
method match {
case Method.Notification(name) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import scala.concurrent.Await
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import scala.concurrent.duration._
import scala.reflect.ClassTag
import scala.util.Failure

import com.typesafe.config.ConfigRenderOptions
Expand Down Expand Up @@ -338,7 +337,8 @@ class ProbeDriver(
* Saves the config for the further use
*/
def setConfig(config: Config): Unit = {
val stringFromConfig = config.source.value
val stringFromConfig = config.source
.value()
.fold(e => error(e.prettyPrint()), value => value.render(ConfigRenderOptions.concise()))
send(Endpoints.SetConfig, stringFromConfig)
}
Expand All @@ -359,19 +359,19 @@ class ProbeDriver(
else throw new IllegalStateException(s"Extension plugin $extensionPluginId is not loaded")
}

def send[R: ClassTag](method: Method[Unit, R]): R = {
def send[R](method: Method[Unit, R]): R = {
send(method, ())
}

def send[T: ClassTag, R: ClassTag](method: Method[T, R], parameters: T): R = {
def send[T, R](method: Method[T, R], parameters: T): R = {
Await.result(sendAsync(method, parameters), 2.hours)
}

def sendAsync[R: ClassTag](method: Method[Unit, R]): Future[R] = {
def sendAsync[R](method: Method[Unit, R]): Future[R] = {
sendAsync(method, ())
}

def sendAsync[T: ClassTag, R: ClassTag](method: Method[T, R], parameters: T): Future[R] = {
def sendAsync[T, R](method: Method[T, R], parameters: T): Future[R] = {
sendRequest(method, parameters)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import java.nio.channels.Channels
import java.nio.charset.StandardCharsets
import java.nio.file.Path

import scala.annotation.nowarn
import scala.collection.mutable
import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.Promise
Expand Down Expand Up @@ -74,8 +76,8 @@ class BaseShell {
}

class ProcessOutputCollector extends NuAbstractProcessHandler {
private val outputBuilder = new StringBuilder
private val errorBuilder = new StringBuilder
private val outputBuilder = new mutable.StringBuilder
private val errorBuilder = new mutable.StringBuilder

override def onStdout(buffer: ByteBuffer, closed: Boolean): Unit = {
outputBuilder.append(StandardCharsets.UTF_8.decode(buffer))
Expand Down Expand Up @@ -172,5 +174,6 @@ class BaseShell {
Seq(outputForwarder)
}

@nowarn // `builder` is not used here, but can be used in classes extending `class BaseShell` by extending this method
protected def customizeBuilder(builder: NuProcessBuilder): Unit = ()
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object TestCase {

def matchingMethods(trace: StackTraceElement): Seq[Method] =
try {
Class.forName(trace.getClassName).getMethods.filter(_.getName == trace.getMethodName)
Class.forName(trace.getClassName).getMethods.toIndexedSeq.filter(_.getName == trace.getMethodName)
} catch {
case _: ReflectiveOperationException => Nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object Plugin extends ConfigFormat {

case class FromSources(id: Id, config: Config) extends Plugin {
override def toString: String = {
val conf = config.source.value.fold(_.toString, _.render(ConfigRenderOptions.concise))
val conf = config.source.value().fold(_.toString, _.render(ConfigRenderOptions.concise))
s"Plugin($id, $conf)"
}
}
Expand All @@ -62,7 +62,7 @@ object Plugin extends ConfigFormat {
}

implicit val fromSourcesWriter: ConfigWriter[FromSources] = ConfigWriter.fromFunction { fs =>
fs.config.source.value.getOrElse(error(s"cannot serialize $fs"))
fs.config.source.value().getOrElse(error(s"cannot serialize $fs"))
}

implicit val pluginReader: ConfigReader[Plugin] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.nio.file.Path
import java.nio.file.Paths
import java.util.zip.ZipInputStream

import scala.annotation.nowarn
import scala.util.control.NonFatal

import pureconfig.ConfigReader
Expand All @@ -20,6 +21,7 @@ sealed trait Resource
object Resource extends ConfigFormat {
implicit val resourceConfigReader: ConfigReader[Resource] = ConfigReader[String].map(from)

@nowarn // as match is not exhaustive - case class Jar is not handled
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved
def exists(uri: URI): Boolean = from(uri) match {
case File(path) => Files.exists(path)
case Http(uri) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class FileDownloader(private val baseDirectory: Path) {
override def isOpen: Boolean = rbc.isOpen
override def close(): Unit = rbc.close()
override def read(bb: ByteBuffer): Int = {
var numRead = rbc.read(bb)
val numRead = rbc.read(bb)
if (numRead > 0) {
readSoFar += numRead
readLastSecond += numRead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class RunningIde(val launcher: NuProcess, idePID: Long, val probe: ProbeDr
case OS.Windows => Array("taskkill", "/F", "/pid", idePID.toString)
}

val result = Shell.run(command: _*)
val result = Shell.run(command.toIndexedSeq: _*)
if (result.exitCode == 0) {
println("IDE terminated")
} else if (!result.err.contains("No such process")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object AfterTestChecks {
def apply(config: CheckConfig, probe: ProbeDriver): Unit = {
val e = new Exception("Test failed due to postcondition failures")

ErrorValidator(config, probe.errors).foreach(e.addSuppressed)
ErrorValidator(config, probe.errors()).foreach(e.addSuppressed)
FreezeValidator(config, probe.freezes).foreach(e.addSuppressed)

if (e.getSuppressed.nonEmpty) throw e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class ProbeDriverTest extends IdeProbeFixture with Assertions with RobotPl
def collectErrors(): Unit = fixture.run { intelliJ =>
intelliJ.probe.invokeActionAsync("org.virtuslab.ideprobe.test.ThrowingAction")
intelliJ.probe.await(WaitLogic.constant(5.seconds))
val errors = intelliJ.probe.errors
val errors = intelliJ.probe.errors()
assertExists(errors)(error =>
error.content.contains("ThrowingAction") && error.pluginId.contains(ProbeTestPlugin.id)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package org.virtuslab.ideprobe

import scala.concurrent.ExecutionContext

import org.virtuslab.ideprobe.ProbeHandlers.ProbeHandler
import org.virtuslab.ideprobe.handlers._
import org.virtuslab.ideprobe.protocol.Endpoints

class BaseProbeHandlerContributor extends ProbeHandlerContributor {
private implicit val ec: ExecutionContext = IdeProbeService.executionContext

override def registerHandlers(handler: ProbeHandler): ProbeHandler = {
handler
Expand All @@ -18,7 +15,7 @@ class BaseProbeHandlerContributor extends ProbeHandlerContributor {
.on(Endpoints.Ping)(_ => ())
.on(Endpoints.Plugins)(_ => Plugins.list)
.on(Endpoints.Shutdown)(_ => App.shutdown())
.on(Endpoints.Messages)(_ => IdeMessages.list)
.on(Endpoints.Messages)(_ => IdeMessages.list.toIndexedSeq)
.on(Endpoints.Freezes)(_ => Freezes.list)
.on(Endpoints.InvokeAction)(Actions.invokeSync)
.on(Endpoints.InvokeActionAsync)(Actions.invokeAsync)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.nio.file.Paths
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

import com.intellij.openapi.compiler.CompilationStatusListener
import com.intellij.openapi.compiler.CompileContext
Expand Down Expand Up @@ -109,7 +109,7 @@ object Builds extends IntelliJApi {
compileContext: CompileContext
): Unit = {
def messages(category: CompilerMessageCategory): Seq[BuildMessage] = {
compileContext.getMessages(category).map { msg =>
compileContext.getMessages(category).toIndexedSeq.map { msg =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this toIndexedSeq conversion happens everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it (as we have on master now) - we are having following warnings (which contain answer, why):

[warn] /Users/lkontowski/code/ide-probe/core/probePlugin/src/main/scala/org/virtuslab/ideprobe/handlers/Builds.scala:112:50: method copyArrayToImmutableIndexedSeq in class LowPriorityImplicits2 is deprecated (since 2.13.0): Implicit conversions from Array to immutable.IndexedSeq are implemented by copying; Use the more efficient non-copying ArraySeq.unsafeWrapArray or an explicit toIndexedSeq call
[warn]         compileContext.getMessages(category).map { msg =>
[warn]                                                  ^
[warn] one warning found

BuildMessage(Option(msg.getVirtualFile).map(_.toString), msg.getMessage)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.virtuslab.ideprobe.protocol.ProjectRef
object Editors extends IntelliJApi {

def all(projectRef: ProjectRef): Seq[Path] = runOnUISync {
editorManager(projectRef).getOpenFiles.map(p => Paths.get(p.getPath))
editorManager(projectRef).getOpenFiles.toIndexedSeq.map(p => Paths.get(p.getPath))
}

def open(fileRef: FileRef): Unit =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.PlatformDataKeys
import com.intellij.openapi.actionSystem.impl.SimpleDataContext
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectUtil
import com.intellij.openapi.vfs.VirtualFile
import gnu.trove.THashMap

Expand All @@ -30,7 +31,7 @@ object ExpandMacro {
val data = new THashMap[String, Object]()
data.put(CommonDataKeys.PROJECT.getName, fileRef.project)
data.put(CommonDataKeys.VIRTUAL_FILE.getName, file)
data.put(PlatformDataKeys.PROJECT_FILE_DIRECTORY.getName, project.getBaseDir)
data.put(PlatformDataKeys.PROJECT_FILE_DIRECTORY.getName, ProjectUtil.guessProjectDir(project))
LukaszKontowski marked this conversation as resolved.
Show resolved Hide resolved
SimpleDataContext.getSimpleContext(data, null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ object Inspections extends IntelliJApi {
}

InspectionRunResult(
descriptors.map(desc =>
descriptors.toIndexedSeq.map(desc =>
read {
ProblemDescriptor(
desc.getDescriptionTemplate,
desc.getLineNumber,
desc.getPsiElement.getText,
desc.getFixes.map(_.getName)
desc.getFixes.toIndexedSeq.map(_.getName)
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import scala.annotation.tailrec
import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.duration.Duration
import scala.reflect.ClassTag

import com.intellij.openapi.application.Application
import com.intellij.openapi.application.ApplicationManager
Expand Down Expand Up @@ -70,7 +69,7 @@ trait IntelliJApi {

implicit class ReflectionOps[A](obj: A) {
import java.lang.reflect._
def invoke[B: ClassTag](name: String)(args: Object*): B = {
def invoke[B](name: String)(args: Object*): B = {
val params = args.map(_.getClass)
val method = getMethod(obj.getClass, name, params: _*)

Expand All @@ -81,13 +80,13 @@ trait IntelliJApi {
result.asInstanceOf[B]
}

def field[B: ClassTag](name: String): B = {
def field[B](name: String): B = {
val field = getField(obj.getClass, "my" + name.capitalize)
using(field)(_.get(obj).asInstanceOf[B])
}

private def using[B <: AccessibleObject, C](accessible: B)(f: B => C): C = {
val isAccessible = accessible.isAccessible
val isAccessible = accessible.canAccess(null)
try {
accessible.setAccessible(true)
f(accessible)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ object Projects extends IntelliJApi {
protocol.Module(module.getName, contentRoots, dependencies, Option(module.getModuleTypeName))
}

protocol.Project(project.getName, project.getBasePath, mappedModules)
protocol.Project(project.getName, project.getBasePath, mappedModules.toIndexedSeq)
}

def sdk(ref: ProjectRef): Option[Sdk] = read {
Expand Down
Loading