Fix remaining missing inline statements/annotations

This commit is contained in:
Matthew de Detrich 2023-12-30 15:45:06 +11:00 committed by Matthew de Detrich
parent 8cb7d256dc
commit 0f1db5301e
9 changed files with 119 additions and 10 deletions

View file

@ -0,0 +1,4 @@
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.JavaDurationConverters#JavaDurationOps.asScala$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.JavaDurationConverters#JavaDurationOps.asScala")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.JavaDurationConverters#ScalaDurationOps.asJava$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.JavaDurationConverters#ScalaDurationOps.asJava")

View file

@ -25,8 +25,7 @@ import org.apache.pekko.annotation.InternalApi
*/
@InternalApi private[pekko] object PartialFunction {
def fromFunction[A, B](f: (A) => B): scala.PartialFunction[A, B] = {
@inline def fromFunction[A, B](f: A => B): scala.PartialFunction[A, B] =
scala.PartialFunction.fromFunction(f)
}
}

View file

@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, which was derived from Akka.
*/
/*
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
*/
package org.apache.pekko.dispatch.internal
import scala.concurrent.ExecutionContext
import org.apache.pekko
import pekko.annotation.InternalApi
/**
* Factory to create same thread ec. Not intended to be called from any other site than to create [[pekko.dispatch.ExecutionContexts#parasitic]]
*
* INTERNAL API
*/
@InternalApi
private[dispatch] object SameThreadExecutionContext {
@inline def apply(): ExecutionContext = ExecutionContext.parasitic
}

View file

@ -23,13 +23,13 @@ import org.apache.pekko.annotation.InternalStableApi
*/
@InternalStableApi
private[pekko] object JavaDurationConverters {
def asFiniteDuration(duration: JDuration): FiniteDuration = duration.asScala
@inline def asFiniteDuration(duration: JDuration): FiniteDuration = duration.asScala
final implicit class JavaDurationOps(val self: JDuration) extends AnyVal {
def asScala: FiniteDuration = Duration.fromNanos(self.toNanos)
@inline def asScala: FiniteDuration = Duration.fromNanos(self.toNanos)
}
final implicit class ScalaDurationOps(val self: Duration) extends AnyVal {
def asJava: JDuration = JDuration.ofNanos(self.toNanos)
@inline def asJava: JDuration = JDuration.ofNanos(self.toNanos)
}
}

View file

@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, which was derived from Akka.
*/
/*
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
*/
package org.apache.pekko.compat
import org.apache.pekko.annotation.InternalApi
/**
* INTERNAL API
*
* Compatibility wrapper for `scala.PartialFunction` to be able to compile the same code
* against Scala 2.12, 2.13, 3.0
*
* Remove these classes as soon as support for Scala 2.12 is dropped!
*/
@InternalApi private[pekko] object PartialFunction {
inline def fromFunction[A, B](f: A => B): scala.PartialFunction[A, B] =
scala.PartialFunction.fromFunction(f)
}

View file

@ -25,5 +25,5 @@ import pekko.annotation.InternalApi
*/
@InternalApi
private[dispatch] object SameThreadExecutionContext {
def apply(): ExecutionContext = ExecutionContext.parasitic
inline def apply(): ExecutionContext = ExecutionContext.parasitic
}

View file

@ -23,15 +23,23 @@ import scala.concurrent.Future
private[pekko] object FutureConverters {
import scala.jdk.javaapi
// Ideally this should have the Scala 3 inline keyword but then Java sources are
// unable to call this method, see https://github.com/lampepfl/dotty/issues/19346
def asJava[T](f: Future[T]): CompletionStage[T] = javaapi.FutureConverters.asJava(f)
implicit final class FutureOps[T](private val f: Future[T]) extends AnyVal {
inline def asJava: CompletionStage[T] = FutureConverters.asJava(f)
// Change to FutureConverters.asJava(f) once https://github.com/lampepfl/dotty/issues/19346
// is resolved and the asJava method is marked as inline
inline def asJava: CompletionStage[T] = javaapi.FutureConverters.asJava(f)
}
// Ideally this should have the Scala 3 inline keyword but then Java sources are
// unable to call this method, see https://github.com/lampepfl/dotty/issues/19346
def asScala[T](cs: CompletionStage[T]): Future[T] = javaapi.FutureConverters.asScala(cs)
implicit final class CompletionStageOps[T](private val cs: CompletionStage[T]) extends AnyVal {
inline def asScala: Future[T] = FutureConverters.asScala(cs)
// Change to FutureConverters.asScala(cs) once https://github.com/lampepfl/dotty/issues/19346
// is resolved and the asScala method is marked as inline
inline def asScala: Future[T] = javaapi.FutureConverters.asScala(cs)
}
}

View file

@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, which was derived from Akka.
*/
/*
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
*/
package org.apache.pekko.util
import java.time.{ Duration => JDuration }
import scala.concurrent.duration.{ Duration, FiniteDuration }
import org.apache.pekko.annotation.InternalStableApi
/**
* INTERNAL API
*/
@InternalStableApi
private[pekko] object JavaDurationConverters {
// Ideally this should have the Scala 3 inline keyword but then Java sources are
// unable to call this method, see https://github.com/lampepfl/dotty/issues/19346
def asFiniteDuration(duration: JDuration): FiniteDuration = duration.asScala
final implicit class JavaDurationOps(val self: JDuration) extends AnyVal {
inline def asScala: FiniteDuration = Duration.fromNanos(self.toNanos)
}
final implicit class ScalaDurationOps(val self: Duration) extends AnyVal {
inline def asJava: JDuration = JDuration.ofNanos(self.toNanos)
}
}

View file

@ -67,10 +67,10 @@ import scala.concurrent.Future
package object scaladsl {
implicit class SourceToCompletionStage[Out, T](val src: Source[Out, Future[T]]) extends AnyVal {
def toCompletionStage(): Source[Out, CompletionStage[T]] =
src.mapMaterializedValue(FutureConverters.asJava)
src.mapMaterializedValue(f => FutureConverters.asJava(f))
}
implicit class SinkToCompletionStage[In, T](val sink: Sink[In, Future[T]]) extends AnyVal {
def toCompletionStage(): Sink[In, CompletionStage[T]] =
sink.mapMaterializedValue(FutureConverters.asJava)
sink.mapMaterializedValue(f => FutureConverters.asJava(f))
}
}