From c4e70136746a491a69f9d06885bfe651a1abfe03 Mon Sep 17 00:00:00 2001 From: Marissa Date: Mon, 11 Mar 2024 17:18:35 -0400 Subject: [PATCH] Simplify `PropagatorConverters` Define (extension and explicit) conversion methods directly in objects rather than in traits. Make extension methods into value classes. Make explicit conversion methods private/internal. --- .../JavaPropagatorWrappers.scala | 8 +- .../propagation/PropagatorConverters.scala | 139 ++++++++++++++++-- .../convert/AsJavaConverters.scala | 77 ---------- .../convert/AsJavaExtensions.scala | 74 ---------- .../convert/AsScalaConverters.scala | 77 ---------- .../convert/AsScalaExtensions.scala | 74 ---------- .../convert/PropagatorConverters.scala | 55 ------- 7 files changed, 132 insertions(+), 372 deletions(-) rename oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/{convert => }/JavaPropagatorWrappers.scala (93%) delete mode 100644 oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsJavaConverters.scala delete mode 100644 oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsJavaExtensions.scala delete mode 100644 oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsScalaConverters.scala delete mode 100644 oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsScalaExtensions.scala delete mode 100644 oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/PropagatorConverters.scala diff --git a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/JavaPropagatorWrappers.scala b/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/JavaPropagatorWrappers.scala similarity index 93% rename from oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/JavaPropagatorWrappers.scala rename to oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/JavaPropagatorWrappers.scala index cdf20a019..a782e9566 100644 --- a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/JavaPropagatorWrappers.scala +++ b/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/JavaPropagatorWrappers.scala @@ -15,7 +15,7 @@ */ package org.typelevel.otel4s.oteljava.context -package propagation.convert +package propagation import io.opentelemetry.context.{Context => JContext} import io.opentelemetry.context.propagation.{TextMapGetter => JTextMapGetter} @@ -31,7 +31,7 @@ import java.{lang => jl} import java.{util => ju} import scala.jdk.CollectionConverters._ -private[convert] object JavaPropagatorWrappers { +private[propagation] object JavaPropagatorWrappers { class TextMapGetterWrapper[C](val underlying: TextMapGetter[C]) extends JTextMapGetter[C] { def keys(carrier: C): jl.Iterable[String] = @@ -70,7 +70,7 @@ private[convert] object JavaPropagatorWrappers { getter: JTextMapGetter[C] ): JContext = { implicit val tmg: TextMapGetter[C] = - PropagatorConverters.asScala(getter) // don't double-wrap + PropagatorConverters.Explicit.asScala(getter) // don't double-wrap Option(carrier) .fold(context)(underlying.extract(Context.wrap(context), _).underlying) } @@ -87,7 +87,7 @@ private[convert] object JavaPropagatorWrappers { underlying.extract( _, carrier, - PropagatorConverters.asJava(getter) // don't double-wrap + PropagatorConverters.Explicit.asJava(getter) // don't double-wrap ) ) def inject[A](ctx: Context, carrier: A)(implicit diff --git a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/PropagatorConverters.scala b/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/PropagatorConverters.scala index c150c168b..0f0a71d07 100644 --- a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/PropagatorConverters.scala +++ b/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/PropagatorConverters.scala @@ -20,15 +20,25 @@ * in the Scala standard library. */ -package org.typelevel.otel4s.oteljava.context.propagation +package org.typelevel.otel4s.oteljava.context +package propagation -/** This object provides extension methods that convert between Scala and Java - * `TextMapGetter`s, `TextMapPropagator`s, and `ContextPropagators` using - * `asScala` and `asJava` extension methods. - * - * For the rare instances where they are needed, explicit conversion methods - * are defined in - * [[org.typelevel.otel4s.oteljava.context.propagation.convert.PropagatorConverters]]. +import io.opentelemetry.context.propagation.{ + ContextPropagators => JContextPropagators +} +import io.opentelemetry.context.propagation.{TextMapGetter => JTextMapGetter} +import io.opentelemetry.context.propagation.{ + TextMapPropagator => JTextMapPropagator +} +import org.typelevel.otel4s.context.propagation.ContextPropagators +import org.typelevel.otel4s.context.propagation.TextMapGetter +import org.typelevel.otel4s.context.propagation.TextMapPropagator + +import scala.{unchecked => uc} + +/** This object provides `asScala` and `asJava` extension methods that convert + * between Scala and Java `TextMapGetter`s, `TextMapPropagator`s, and + * `ContextPropagators`. * * {{{ * import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator @@ -60,6 +70,113 @@ package org.typelevel.otel4s.oteljava.context.propagation * Consequently, conversions between `ContextPropagators` convert the * `TextMapPropagator` and do not use a custom wrapper. */ -object PropagatorConverters - extends convert.AsJavaExtensions - with convert.AsScalaExtensions +object PropagatorConverters { + + implicit final class TextMapGetterHasAsJava[A]( + private val getter: TextMapGetter[A] + ) extends AnyVal { + + /** Converts a Scala `TextMapGetter` to a Java `TextMapGetter`. + * + * The returned Java `TextMapGetter` is backed by the provided Scala + * `TextMapGetter` unless the Scala `TextMapGetter` was previously obtained + * from an implicit or explicit call of `asScala`, in which case the + * original Java `TextMapGetter` will be returned. + */ + def asJava: JTextMapGetter[A] = Explicit.asJava(getter) + } + + implicit final class TextMapPropagatorHasAsJava( + private val prop: TextMapPropagator[Context] + ) extends AnyVal { + + /** Converts a Scala `TextMapPropagator` to a Java `TextMapPropagator`. + * + * The returned Java `TextMapPropagator` is backed by the provided Scala + * `TextMapPropagator`unless the Scala `TextMapPropagator` was previously + * obtained from an implicit or explicit call of `asScala`, in which case + * the original Java `TextMapPropagator` will be returned. + */ + def asJava: JTextMapPropagator = Explicit.asJava(prop) + } + + implicit final class ContextPropagatorsHasAsJava( + private val cp: ContextPropagators[Context] + ) extends AnyVal { + + /** Converts a Scala `ContextPropagators` to a Java `ContextPropagators`. */ + def asJava: JContextPropagators = Explicit.asJava(cp) + } + + implicit final class TextMapGetterHasAsScala[A]( + private val getter: JTextMapGetter[A] + ) extends AnyVal { + + /** Converts a Java `TextMapGetter` to a Scala `TextMapGetter`. + * + * The returned Scala `TextMapGetter` is backed by the provided Java + * `TextMapGetter` unless the Java `TextMapGetter` was previously obtained + * from an implicit or explicit call of `asJava`, in which case the + * original Scala `TextMapGetter` will be returned. + */ + def asScala: TextMapGetter[A] = Explicit.asScala(getter) + } + + implicit final class TextMapPropagatorHasAsScala( + private val propagator: JTextMapPropagator + ) extends AnyVal { + + /** Converts a Java `TextMapPropagator` to a Scala `TextMapPropagator`. + * + * The returned Scala `TextMapPropagator` is backed by the provided Java + * `TextMapPropagator` unless the Java `TextMapPropagator` was previously + * obtained from an implicit or explicit call of `asJava`, in which case + * the original Scala `TextMapPropagator` will be returned. + */ + def asScala: TextMapPropagator[Context] = Explicit.asScala(propagator) + } + + implicit final class ContextPropagatorsHasAsScala( + private val cp: JContextPropagators + ) extends AnyVal { + + /** Converts a Java `ContextPropagators` to a Scala `ContextPropagators`. */ + def asScala: ContextPropagators[Context] = Explicit.asScala(cp) + } + + private[propagation] object Explicit { + import JavaPropagatorWrappers._ + + def asJava[A](getter: TextMapGetter[A]): JTextMapGetter[A] = getter match { + case null => null + case wrapper: JTextMapGetterWrapper[A @uc] => wrapper.underlying + case _ => new TextMapGetterWrapper(getter) + } + + def asJava(propagator: TextMapPropagator[Context]): JTextMapPropagator = + propagator match { + case null => null + case wrapper: JTextMapPropagatorWrapper => wrapper.underlying + case _ => new TextMapPropagatorWrapper(propagator) + } + + def asJava(propagators: ContextPropagators[Context]): JContextPropagators = + JContextPropagators.create(asJava(propagators.textMapPropagator)) + + def asScala[A](getter: JTextMapGetter[A]): TextMapGetter[A] = getter match { + case null => null + case wrapper: TextMapGetterWrapper[A @uc] => wrapper.underlying + case _ => new JTextMapGetterWrapper(getter) + } + + def asScala(propagator: JTextMapPropagator): TextMapPropagator[Context] = + propagator match { + case null => null + case wrapper: TextMapPropagatorWrapper => wrapper.underlying + case _ => new JTextMapPropagatorWrapper(propagator) + } + + def asScala(propagators: JContextPropagators): ContextPropagators[Context] = + ContextPropagators.of(asScala(propagators.getTextMapPropagator)) + } +} diff --git a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsJavaConverters.scala b/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsJavaConverters.scala deleted file mode 100644 index 59cc66b24..000000000 --- a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsJavaConverters.scala +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2022 Typelevel - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * The scaladocs in this file are adapted from those in the file - * scala/collection/convert/AsJavaConverters.scala - * in the Scala standard library. - */ - -package org.typelevel.otel4s.oteljava.context -package propagation.convert - -import io.opentelemetry.context.propagation.{ - ContextPropagators => JContextPropagators -} -import io.opentelemetry.context.propagation.{TextMapGetter => JTextMapGetter} -import io.opentelemetry.context.propagation.{ - TextMapPropagator => JTextMapPropagator -} -import org.typelevel.otel4s.context.propagation.ContextPropagators -import org.typelevel.otel4s.context.propagation.TextMapGetter -import org.typelevel.otel4s.context.propagation.TextMapPropagator - -import scala.{unchecked => uc} - -/** Defines explicit conversion methods from Scala to Java for `TextMapGetter`s, - * `TextMapPropagator`s, and `ContextPropagators`. These methods are available - * through - * [[org.typelevel.otel4s.oteljava.context.propagation.convert.PropagatorConverters]]. - */ -trait AsJavaConverters { - import JavaPropagatorWrappers._ - - /** Converts a Scala `TextMapGetter` to a Java `TextMapGetter`. - * - * The returned Java `TextMapGetter` is backed by the provided Scala - * `TextMapGetter` unless the Scala `TextMapGetter` was previously obtained - * from an implicit or explicit call of `asScala`, in which case the original - * Java `TextMapGetter` will be returned. - */ - def asJava[A](getter: TextMapGetter[A]): JTextMapGetter[A] = getter match { - case null => null - case wrapper: JTextMapGetterWrapper[A @uc] => wrapper.underlying - case _ => new TextMapGetterWrapper(getter) - } - - /** Converts a Scala `TextMapPropagator` to a Java `TextMapPropagator`. - * - * The returned Java `TextMapPropagator` is backed by the provided Scala - * `TextMapPropagator`unless the Scala `TextMapPropagator` was previously - * obtained from an implicit or explicit call of `asScala`, in which case the - * original Java `TextMapPropagator` will be returned. - */ - def asJava(propagator: TextMapPropagator[Context]): JTextMapPropagator = - propagator match { - case null => null - case wrapper: JTextMapPropagatorWrapper => wrapper.underlying - case _ => new TextMapPropagatorWrapper(propagator) - } - - /** Converts a Scala `ContextPropagators` to a Java `ContextPropagators`. */ - def asJava(propagators: ContextPropagators[Context]): JContextPropagators = - JContextPropagators.create(asJava(propagators.textMapPropagator)) -} diff --git a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsJavaExtensions.scala b/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsJavaExtensions.scala deleted file mode 100644 index 8514b8ecc..000000000 --- a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsJavaExtensions.scala +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2022 Typelevel - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * The scaladocs in this file are adapted from those in the file - * scala/collection/convert/AsJavaExtensions.scala - * in the Scala standard library. - */ - -package org.typelevel.otel4s.oteljava.context -package propagation -package convert - -import io.opentelemetry.context.propagation.{ - ContextPropagators => JContextPropagators -} -import io.opentelemetry.context.propagation.{TextMapGetter => JTextMapGetter} -import io.opentelemetry.context.propagation.{ - TextMapPropagator => JTextMapPropagator -} -import org.typelevel.otel4s.context.propagation.ContextPropagators -import org.typelevel.otel4s.context.propagation.TextMapGetter -import org.typelevel.otel4s.context.propagation.TextMapPropagator - -/** Defines `asJava` extension methods for `TextMapGetter`s and - * `TextMapPropagator`s, and `ContextPropagators`, available through - * [[org.typelevel.otel4s.oteljava.context.propagation.PropagatorConverters]]. - */ -trait AsJavaExtensions { - import convert.{PropagatorConverters => conv} - - implicit class TextMapGetterHasAsJava[A](getter: TextMapGetter[A]) { - - /** Converts a Scala `TextMapGetter` to a Java `TextMapGetter`. - * - * @see - * [[org.typelevel.otel4s.oteljava.context.propagation.convert.AsJavaConverters.asJava[A](getter* `convert.PropagatorConverters.asJava`]]. - */ - def asJava: JTextMapGetter[A] = conv.asJava(getter) - } - - implicit class TextMapPropagatorHasAsJava(prop: TextMapPropagator[Context]) { - - /** Converts a Scala `TextMapPropagator` to a Java `TextMapPropagator`. - * - * @see - * [[org.typelevel.otel4s.oteljava.context.propagation.convert.AsJavaConverters.asJava(propagator:* `convert.PropagatorConverters.asJava`]]. - */ - def asJava: JTextMapPropagator = conv.asJava(prop) - } - - implicit class ContextPropagatorsHasAsJava(cp: ContextPropagators[Context]) { - - /** Converts a Scala `ContextPropagators` to a Java `ContextPropagators`. - * - * @see - * [[org.typelevel.otel4s.oteljava.context.propagation.convert.AsJavaConverters.asJava(propagators* `convert.PropagatorConverters.asJava`]]. - */ - def asJava: JContextPropagators = conv.asJava(cp) - } -} diff --git a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsScalaConverters.scala b/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsScalaConverters.scala deleted file mode 100644 index 1b9018c28..000000000 --- a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsScalaConverters.scala +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2022 Typelevel - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * The scaladocs in this file are adapted from those in the file - * scala/collection/convert/AsScalaConverters.scala - * in the Scala standard library. - */ - -package org.typelevel.otel4s.oteljava.context -package propagation.convert - -import io.opentelemetry.context.propagation.{ - ContextPropagators => JContextPropagators -} -import io.opentelemetry.context.propagation.{TextMapGetter => JTextMapGetter} -import io.opentelemetry.context.propagation.{ - TextMapPropagator => JTextMapPropagator -} -import org.typelevel.otel4s.context.propagation.ContextPropagators -import org.typelevel.otel4s.context.propagation.TextMapGetter -import org.typelevel.otel4s.context.propagation.TextMapPropagator - -import scala.{unchecked => uc} - -/** Defines explicit conversion methods from Java to Scala for `TextMapGetter`s, - * `TextMapPropagator`s, and `ContextPropagators`. These methods are available - * through - * [[org.typelevel.otel4s.oteljava.context.propagation.convert.PropagatorConverters]]. - */ -trait AsScalaConverters { - import JavaPropagatorWrappers._ - - /** Converts a Java `TextMapGetter` to a Scala `TextMapGetter`. - * - * The returned Scala `TextMapGetter` is backed by the provided Java - * `TextMapGetter` unless the Java `TextMapGetter` was previously obtained - * from an implicit or explicit call of `asJava`, in which case the original - * Scala `TextMapGetter` will be returned. - */ - def asScala[A](getter: JTextMapGetter[A]): TextMapGetter[A] = getter match { - case null => null - case wrapper: TextMapGetterWrapper[A @uc] => wrapper.underlying - case _ => new JTextMapGetterWrapper(getter) - } - - /** Converts a Java `TextMapPropagator` to a Scala `TextMapPropagator`. - * - * The returned Scala `TextMapPropagator` is backed by the provided Java - * `TextMapPropagator` unless the Java `TextMapPropagator` was previously - * obtained from an implicit or explicit call of `asJava`, in which case the - * original Scala `TextMapPropagator` will be returned. - */ - def asScala(propagator: JTextMapPropagator): TextMapPropagator[Context] = - propagator match { - case null => null - case wrapper: TextMapPropagatorWrapper => wrapper.underlying - case _ => new JTextMapPropagatorWrapper(propagator) - } - - /** Converts a Java `ContextPropagators` to a Scala `ContextPropagators`. */ - def asScala(propagators: JContextPropagators): ContextPropagators[Context] = - ContextPropagators.of(asScala(propagators.getTextMapPropagator)) -} diff --git a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsScalaExtensions.scala b/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsScalaExtensions.scala deleted file mode 100644 index 19eb58cfc..000000000 --- a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/AsScalaExtensions.scala +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2022 Typelevel - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * The scaladocs in this file are adapted from those in the file - * scala/collection/convert/AsScalaExtensions.scala - * in the Scala standard library. - */ - -package org.typelevel.otel4s.oteljava.context -package propagation -package convert - -import io.opentelemetry.context.propagation.{ - ContextPropagators => JContextPropagators -} -import io.opentelemetry.context.propagation.{TextMapGetter => JTextMapGetter} -import io.opentelemetry.context.propagation.{ - TextMapPropagator => JTextMapPropagator -} -import org.typelevel.otel4s.context.propagation.ContextPropagators -import org.typelevel.otel4s.context.propagation.TextMapGetter -import org.typelevel.otel4s.context.propagation.TextMapPropagator - -/** Defines `asScala` extension methods for `TextMapGetter`s, - * `TextMapPropagator`s, and `ContextPropagators`, available through - * [[org.typelevel.otel4s.oteljava.context.propagation.PropagatorConverters]]. - */ -trait AsScalaExtensions { - import convert.{PropagatorConverters => conv} - - implicit class TextMapGetterHasAsScala[A](getter: JTextMapGetter[A]) { - - /** Converts a Java `TextMapGetter` to a Scala `TextMapGetter`. - * - * @see - * [[org.typelevel.otel4s.oteljava.context.propagation.convert.AsScalaConverters.asScala[A](getter* `convert.PropagatorConverters.asScala`]]. - */ - def asScala: TextMapGetter[A] = conv.asScala(getter) - } - - implicit class TextMapPropagatorHasAsScala(propagator: JTextMapPropagator) { - - /** Converts a Java `TextMapPropagator` to a Scala `TextMapPropagator`. - * - * @see - * [[org.typelevel.otel4s.oteljava.context.propagation.convert.AsScalaConverters.asScala(propagator:* `convert.PropagatorConverters.asScala`]]. - */ - def asScala: TextMapPropagator[Context] = conv.asScala(propagator) - } - - implicit class ContextPropagatorsHasAsScala(cp: JContextPropagators) { - - /** Converts a Java `TextMapPropagator` to a Scala `TextMapPropagator`. - * - * @see - * [[org.typelevel.otel4s.oteljava.context.propagation.convert.AsScalaConverters.asScala(propagators* `convert.PropagatorConverters.asScala`]]. - */ - def asScala: ContextPropagators[Context] = conv.asScala(cp) - } -} diff --git a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/PropagatorConverters.scala b/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/PropagatorConverters.scala deleted file mode 100644 index 41aab749d..000000000 --- a/oteljava/common/src/main/scala/org/typelevel/otel4s/oteljava/context/propagation/convert/PropagatorConverters.scala +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2022 Typelevel - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * The scaladocs in this file are adapted from those in the file - * scala/jdk/javaapi/CollectionConverters.scala - * in the Scala standard library. - */ - -package org.typelevel.otel4s.oteljava.context.propagation.convert - -/** This object contains methods that convert between Scala and Java - * `TextMapGetter`s, `TextMapPropagator`s, and `ContextPropagators` using - * explicit `asScala` and `asJava` methods. - * - * In general, it is preferable to use the extension methods defined in - * [[org.typelevel.otel4s.oteljava.context.propagation.PropagatorConverters]]. - * - * {{{ - * // Java Code - * import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; - * import org.typelevel.otel4s.context.propagation.TextMapPropagator; - * import org.typelevel.otel4s.oteljava.context.Context; - * import org.typelevel.otel4s.oteljava.context.propagation.convert.TextMapOperatorConverters; - * - * public class Example { - * public void foo(W3CTraceContextPropagator jp) { - * TextMapPropagator sp = TextMapOperatorConverters.asScala(jp); - * } - * } - * }}} - * - * The conversions return wrappers for the TextMap operators, and converting - * from a source type to a target type and back again will return the original - * source object. - * - * Currently, `ContextPropagators` for both Java and Scala are simple wrappers - * around a `TextMapPropagator` instance of the corresponding type. - * Consequently, conversions between `ContextPropagators` convert the - * `TextMapPropagator` and do not use a custom wrapper. - */ -object PropagatorConverters extends AsJavaConverters with AsScalaConverters