Created
October 19, 2016 16:18
-
-
Save varnerac/4bac246dc76afd61b08ae6b58dd4d138 to your computer and use it in GitHub Desktop.
Attempt to Instantiate Protobuf Companion Object from Name (String)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getProtoCompanionClass(protoName: String): Option[GeneratedMessageCompanion[_]] = { | |
try { | |
val protoClassSymbol = currentMirror.staticClass(protoName) | |
val protoCompanionObjectSymbol = protoClassSymbol.companion.asModule | |
Some(currentMirror.reflectModule(protoCompanionObjectSymbol).instance.asInstanceOf[GeneratedMessageCompanion[_]]) | |
} catch { | |
case _: ScalaReflectionException => None | |
} | |
} | |
// ProtoReflection.scala:6: type arguments [_$2] do not conform to trait GeneratedMessageCompanion's type parameter bounds [A <: com.trueaccord.scalapb.GeneratedMessage with com.trueaccord.scalapb.Message[A]] | |
// [error] Some(currentMirror.reflectModule(protoCompanionObjectSymbol).instance.asInstanceOf[GeneratedMessageCompanion[_]]) | |
// [error] ^ | |
// [error] one error found | |
// [error] (compile:compileIncremental) Compilation failed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment