Skip to content

Commit 24ce39c

Browse files
committed
Add targetName overloaded methods for Scala 3 inline methods
1 parent 7bf26c8 commit 24ce39c

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

actor/src/main/scala-3/org/apache/pekko/compat/PartialFunction.scala

+7
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,24 @@ package org.apache.pekko.compat
1515

1616
import org.apache.pekko.annotation.InternalApi
1717

18+
import scala.annotation.targetName
19+
1820
/**
1921
* INTERNAL API
2022
*
2123
* Compatibility wrapper for `scala.PartialFunction` to be able to compile the same code
2224
* against Scala 2.12, 2.13, 3.0
2325
*
2426
* Remove these classes as soon as support for Scala 2.12 is dropped!
27+
* Remove the @targetName bytecode forwarded methods for Pekko 2.0.x since we only care about source compatibility
2528
*/
2629
@InternalApi private[pekko] object PartialFunction {
2730

2831
inline def fromFunction[A, B](f: A => B): scala.PartialFunction[A, B] =
2932
scala.PartialFunction.fromFunction(f)
3033

34+
@targetName("fromFunction")
35+
def _pekko10FromFunction[A, B](f: A => B): scala.PartialFunction[A, B] =
36+
scala.PartialFunction.fromFunction(f)
37+
3138
}

actor/src/main/scala-3/org/apache/pekko/dispatch/internal/SameThreadExecutionContext.scala

+6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ import scala.concurrent.ExecutionContext
1818
import org.apache.pekko
1919
import pekko.annotation.InternalApi
2020

21+
import scala.annotation.targetName
22+
2123
/**
2224
* Factory to create same thread ec. Not intended to be called from any other site than to create [[pekko.dispatch.ExecutionContexts#parasitic]]
25+
* Remove the @targetName bytecode forwarded methods for Pekko 2.0.x since we only care about source compatibility
2326
*
2427
* INTERNAL API
2528
*/
2629
@InternalApi
2730
private[dispatch] object SameThreadExecutionContext {
2831
inline def apply(): ExecutionContext = ExecutionContext.parasitic
32+
33+
@targetName("apply")
34+
def _pekko1Apply(): ExecutionContext = ExecutionContext.parasitic
2935
}

actor/src/main/scala-3/org/apache/pekko/util/FutureConverters.scala

+8
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import org.apache.pekko.annotation.InternalStableApi
1313

1414
import java.util.concurrent.CompletionStage
1515
import scala.concurrent.Future
16+
import scala.annotation.targetName
1617

1718
/**
1819
* INTERNAL API
1920
*
2021
* Remove this once Scala 2.12 support is dropped since all methods are in Scala 2.13+ stdlib
22+
* Remove the @targetName bytecode forwarded methods for Pekko 2.0.x since we only care about source compatibility
2123
*/
2224
@InternalStableApi
2325
private[pekko] object FutureConverters {
@@ -29,6 +31,9 @@ private[pekko] object FutureConverters {
2931

3032
implicit final class FutureOps[T](private val f: Future[T]) extends AnyVal {
3133
inline def asJava: CompletionStage[T] = javaapi.FutureConverters.asJava(f)
34+
35+
@targetName("asJava")
36+
def _pekko1AsJava: CompletionStage[T] = javaapi.FutureConverters.asJava(f)
3237
}
3338

3439
// Ideally this should have the Scala 3 inline keyword but then Java sources are
@@ -37,5 +42,8 @@ private[pekko] object FutureConverters {
3742

3843
implicit final class CompletionStageOps[T](private val cs: CompletionStage[T]) extends AnyVal {
3944
inline def asScala: Future[T] = javaapi.FutureConverters.asScala(cs)
45+
46+
@targetName("asScala")
47+
def _pekko1AsScala: Future[T] = javaapi.FutureConverters.asScala(cs)
4048
}
4149
}

actor/src/main/scala-3/org/apache/pekko/util/JavaDurationConverters.scala

+9
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
*/
1313

1414
package org.apache.pekko.util
15+
1516
import java.time.{ Duration => JDuration }
1617

18+
import scala.annotation.targetName
1719
import scala.concurrent.duration.{ Duration, FiniteDuration }
1820

1921
import org.apache.pekko.annotation.InternalStableApi
2022

2123
/**
2224
* INTERNAL API
25+
* Remove the @targetName bytecode forwarded methods for Pekko 2.0.x since we only care about source compatibility
2326
*/
2427
@InternalStableApi
2528
private[pekko] object JavaDurationConverters {
@@ -30,9 +33,15 @@ private[pekko] object JavaDurationConverters {
3033

3134
final implicit class JavaDurationOps(val self: JDuration) extends AnyVal {
3235
inline def asScala: FiniteDuration = Duration.fromNanos(self.toNanos)
36+
37+
@targetName("asScala")
38+
def _pekko1AsScala: FiniteDuration = Duration.fromNanos(self.toNanos)
3339
}
3440

3541
final implicit class ScalaDurationOps(val self: Duration) extends AnyVal {
3642
inline def asJava: JDuration = JDuration.ofNanos(self.toNanos)
43+
44+
@targetName("asJava")
45+
def _pekko1AsJava: JDuration = JDuration.ofNanos(self.toNanos)
3746
}
3847
}

actor/src/main/scala-3/org/apache/pekko/util/OptionConverters.scala

+35-1
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ package org.apache.pekko.util
1212
import org.apache.pekko.annotation.InternalStableApi
1313

1414
import java.util._
15+
import scala.annotation.targetName
1516
import scala.jdk.OptionShape
1617

1718
/**
1819
* INTERNAL API
1920
*
20-
* Remove this once Scala 2.12 support is dropped since all methods are in Scala 2.13+ stdlib
21+
* Remove this once Scala 2.12 support is dropped since all methods are in Scala 2.13+ stdlib.
22+
* Remove the @targetName bytecode forwarded methods for Pekko 2.0.x since we only care about source compatibility
2123
*/
2224
@InternalStableApi
2325
private[pekko] object OptionConverters {
@@ -37,24 +39,44 @@ private[pekko] object OptionConverters {
3739
implicit final class RichOptional[A](private val o: java.util.Optional[A]) extends AnyVal {
3840
inline def toScala: Option[A] = scala.jdk.OptionConverters.RichOptional(o).toScala
3941

42+
@targetName("toScala")
43+
def _pekko1ToScala: Option[A] = scala.jdk.OptionConverters.RichOptional(o).toScala
44+
4045
inline def toJavaPrimitive[O](implicit shape: OptionShape[A, O]): O =
4146
scala.jdk.OptionConverters.RichOptional(o).toJavaPrimitive
47+
48+
@targetName("toJavaPrimitive")
49+
def _pekko1ToJavaPrimitive[O](implicit shape: OptionShape[A, O]): O =
50+
scala.jdk.OptionConverters.RichOptional(o).toJavaPrimitive
4251
}
4352

4453
implicit final class RichOption[A](private val o: Option[A]) extends AnyVal {
4554
inline def toJava: Optional[A] = scala.jdk.OptionConverters.RichOption(o).toJava
4655

56+
@targetName("toJava")
57+
def _pekko1ToJava: Optional[A] = scala.jdk.OptionConverters.RichOption(o).toJava
58+
4759
inline def toJavaPrimitive[O](implicit shape: OptionShape[A, O]): O =
4860
scala.jdk.OptionConverters.RichOption(o).toJavaPrimitive
61+
62+
@targetName("toJavaPrimitive")
63+
def _pekko1ToJavaPrimitive[O](implicit shape: OptionShape[A, O]): O =
64+
scala.jdk.OptionConverters.RichOption(o).toJavaPrimitive
4965
}
5066

5167
implicit class RichOptionalDouble(private val o: OptionalDouble) extends AnyVal {
5268

5369
/** Convert a Java `OptionalDouble` to a Scala `Option` */
5470
inline def toScala: Option[Double] = scala.jdk.OptionConverters.RichOptionalDouble(o).toScala
5571

72+
@targetName("toScala")
73+
def _pekko1ToScala: Option[Double] = scala.jdk.OptionConverters.RichOptionalDouble(o).toScala
74+
5675
/** Convert a Java `OptionalDouble` to a generic Java `Optional` */
5776
inline def toJavaGeneric: Optional[Double] = scala.jdk.OptionConverters.RichOptionalDouble(o).toJavaGeneric
77+
78+
@targetName("toJavaGeneric")
79+
def _pekko1ToJavaGeneric: Optional[Double] = scala.jdk.OptionConverters.RichOptionalDouble(o).toJavaGeneric
5880
}
5981

6082
/** Provides conversions from `OptionalInt` to Scala `Option` and the generic `Optional` */
@@ -63,8 +85,14 @@ private[pekko] object OptionConverters {
6385
/** Convert a Java `OptionalInt` to a Scala `Option` */
6486
inline def toScala: Option[Int] = scala.jdk.OptionConverters.RichOptionalInt(o).toScala
6587

88+
@targetName("toScala")
89+
def _pekko1ToScala: Option[Int] = scala.jdk.OptionConverters.RichOptionalInt(o).toScala
90+
6691
/** Convert a Java `OptionalInt` to a generic Java `Optional` */
6792
inline def toJavaGeneric: Optional[Int] = scala.jdk.OptionConverters.RichOptionalInt(o).toJavaGeneric
93+
94+
@targetName("toJavaGeneric")
95+
def _pekko1ToJavaGeneric: Optional[Int] = scala.jdk.OptionConverters.RichOptionalInt(o).toJavaGeneric
6896
}
6997

7098
/** Provides conversions from `OptionalLong` to Scala `Option` and the generic `Optional` */
@@ -73,7 +101,13 @@ private[pekko] object OptionConverters {
73101
/** Convert a Java `OptionalLong` to a Scala `Option` */
74102
inline def toScala: Option[Long] = scala.jdk.OptionConverters.RichOptionalLong(o).toScala
75103

104+
@targetName("toScala")
105+
def _pekko1ToScala: Option[Long] = scala.jdk.OptionConverters.RichOptionalLong(o).toScala
106+
76107
/** Convert a Java `OptionalLong` to a generic Java `Optional` */
77108
inline def toJavaGeneric: Optional[Long] = scala.jdk.OptionConverters.RichOptionalLong(o).toJavaGeneric
109+
110+
@targetName("toJavaGeneric")
111+
def _pekko1ToJavaGeneric: Optional[Long] = scala.jdk.OptionConverters.RichOptionalLong(o).toJavaGeneric
78112
}
79113
}

0 commit comments

Comments
 (0)