Skip to content

Commit

Permalink
add asRecognized method in GeneratedEnum (#1489)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k authored Feb 25, 2023
1 parent 66106e1 commit 8dec8bf
Show file tree
Hide file tree
Showing 23 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ lazy val runtime = (projectMatrix in file("scalapb-runtime"))
else Nil),
mimaPreviousArtifacts := Set("com.thesamet.scalapb" %% "scalapb-runtime" % MimaPreviousVersion),
mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[ReversedMissingMethodProblem]("scalapb.GeneratedEnum.asRecognized"),
ProblemFilters.exclude[InheritedNewAbstractMethodProblem]("*Extension*"),
ProblemFilters.exclude[Problem]("scalapb.options.*"),
ProblemFilters.exclude[FinalMethodProblem]("*.parseFrom")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ProtobufGenerator(
)
.indent
.add(s"type EnumType = $name")
.add(s"type RecognizedType = ${e.recognizedEnum.fullName}")
.print(e.getValues.asScala) { case (p, v) =>
p.add(s"def ${v.isName}: _root_.scala.Boolean = false")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ object Person extends scalapb.GeneratedMessageCompanion[scalapb.docs.person.Pers
)
sealed abstract class AddressType(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = AddressType
type RecognizedType = scalapb.docs.person.Person.AddressType.Recognized
def isHome: _root_.scala.Boolean = false
def isWork: _root_.scala.Boolean = false
def companion: _root_.scalapb.GeneratedEnumCompanion[AddressType] = scalapb.docs.person.Person.AddressType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package scalapb.perf.protos

sealed abstract class Color(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Color
type RecognizedType = scalapb.perf.protos.Color.Recognized
def isUnknown: _root_.scala.Boolean = false
def isRed: _root_.scala.Boolean = false
def isGreen: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ object CodeGeneratorResponse extends scalapb.GeneratedMessageCompanion[com.googl
*/
sealed abstract class Feature(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Feature
type RecognizedType = com.google.protobuf.compiler.plugin.CodeGeneratorResponse.Feature.Recognized
def isFeatureNone: _root_.scala.Boolean = false
def isFeatureProto3Optional: _root_.scala.Boolean = false
def companion: _root_.scalapb.GeneratedEnumCompanion[Feature] = com.google.protobuf.compiler.plugin.CodeGeneratorResponse.Feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ object FieldDescriptorProto extends scalapb.GeneratedMessageCompanion[com.google
)
sealed abstract class Type(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Type
type RecognizedType = com.google.protobuf.descriptor.FieldDescriptorProto.Type.Recognized
def isTypeDouble: _root_.scala.Boolean = false
def isTypeFloat: _root_.scala.Boolean = false
def isTypeInt64: _root_.scala.Boolean = false
Expand Down Expand Up @@ -567,6 +568,7 @@ object FieldDescriptorProto extends scalapb.GeneratedMessageCompanion[com.google
}
sealed abstract class Label(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Label
type RecognizedType = com.google.protobuf.descriptor.FieldDescriptorProto.Label.Recognized
def isLabelOptional: _root_.scala.Boolean = false
def isLabelRequired: _root_.scala.Boolean = false
def isLabelRepeated: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ object FieldOptions extends scalapb.GeneratedMessageCompanion[com.google.protobu
)
sealed abstract class CType(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = CType
type RecognizedType = com.google.protobuf.descriptor.FieldOptions.CType.Recognized
def isString: _root_.scala.Boolean = false
def isCord: _root_.scala.Boolean = false
def isStringPiece: _root_.scala.Boolean = false
Expand Down Expand Up @@ -344,6 +345,7 @@ object FieldOptions extends scalapb.GeneratedMessageCompanion[com.google.protobu
}
sealed abstract class JSType(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = JSType
type RecognizedType = com.google.protobuf.descriptor.FieldOptions.JSType.Recognized
def isJsNormal: _root_.scala.Boolean = false
def isJsString: _root_.scala.Boolean = false
def isJsNumber: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ object FileOptions extends scalapb.GeneratedMessageCompanion[com.google.protobuf
*/
sealed abstract class OptimizeMode(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = OptimizeMode
type RecognizedType = com.google.protobuf.descriptor.FileOptions.OptimizeMode.Recognized
def isSpeed: _root_.scala.Boolean = false
def isCodeSize: _root_.scala.Boolean = false
def isLiteRuntime: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ object MethodOptions extends scalapb.GeneratedMessageCompanion[com.google.protob
*/
sealed abstract class IdempotencyLevel(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = IdempotencyLevel
type RecognizedType = com.google.protobuf.descriptor.MethodOptions.IdempotencyLevel.Recognized
def isIdempotencyUnknown: _root_.scala.Boolean = false
def isNoSideEffects: _root_.scala.Boolean = false
def isIdempotent: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package com.google.protobuf.struct
*/
sealed abstract class NullValue(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = NullValue
type RecognizedType = com.google.protobuf.struct.NullValue.Recognized
def isNullValue: _root_.scala.Boolean = false
def companion: _root_.scalapb.GeneratedEnumCompanion[NullValue] = com.google.protobuf.struct.NullValue
final def asRecognized: _root_.scala.Option[com.google.protobuf.struct.NullValue.Recognized] = if (isUnrecognized) _root_.scala.None else _root_.scala.Some(this.asInstanceOf[com.google.protobuf.struct.NullValue.Recognized])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ object Field extends scalapb.GeneratedMessageCompanion[com.google.protobuf.`type
*/
sealed abstract class Kind(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Kind
type RecognizedType = com.google.protobuf.`type`.Field.Kind.Recognized
def isTypeUnknown: _root_.scala.Boolean = false
def isTypeDouble: _root_.scala.Boolean = false
def isTypeFloat: _root_.scala.Boolean = false
Expand Down Expand Up @@ -605,6 +606,7 @@ object Field extends scalapb.GeneratedMessageCompanion[com.google.protobuf.`type
*/
sealed abstract class Cardinality(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Cardinality
type RecognizedType = com.google.protobuf.`type`.Field.Cardinality.Recognized
def isCardinalityUnknown: _root_.scala.Boolean = false
def isCardinalityOptional: _root_.scala.Boolean = false
def isCardinalityRequired: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package com.google.protobuf.`type`
*/
sealed abstract class Syntax(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Syntax
type RecognizedType = com.google.protobuf.`type`.Syntax.Recognized
def isSyntaxProto2: _root_.scala.Boolean = false
def isSyntaxProto3: _root_.scala.Boolean = false
def companion: _root_.scalapb.GeneratedEnumCompanion[Syntax] = com.google.protobuf.`type`.Syntax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import scala.annotation.nowarn

trait GeneratedEnum extends Any with Product with Serializable {
type EnumType <: GeneratedEnum
type RecognizedType <: EnumType

def value: Int

Expand All @@ -30,6 +31,8 @@ trait GeneratedEnum extends Any with Product with Serializable {

def scalaValueDescriptor: _root_.scalapb.descriptors.EnumValueDescriptor =
companion.scalaDescriptor.values(index)

def asRecognized: Option[RecognizedType]
}

trait UnrecognizedEnum extends GeneratedEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package scalapb.options

sealed abstract class MatchType(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = MatchType
type RecognizedType = scalapb.options.MatchType.Recognized
def isContains: _root_.scala.Boolean = false
def isExact: _root_.scala.Boolean = false
def isPresence: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ object ScalaPbOptions extends scalapb.GeneratedMessageCompanion[scalapb.options.
*/
sealed abstract class OptionsScope(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = OptionsScope
type RecognizedType = scalapb.options.ScalaPbOptions.OptionsScope.Recognized
def isFile: _root_.scala.Boolean = false
def isPackage: _root_.scala.Boolean = false
def companion: _root_.scalapb.GeneratedEnumCompanion[OptionsScope] = scalapb.options.ScalaPbOptions.OptionsScope
Expand Down Expand Up @@ -802,6 +803,7 @@ object ScalaPbOptions extends scalapb.GeneratedMessageCompanion[scalapb.options.
*/
sealed abstract class EnumValueNaming(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = EnumValueNaming
type RecognizedType = scalapb.options.ScalaPbOptions.EnumValueNaming.Recognized
def isAsInProto: _root_.scala.Boolean = false
def isCamelCase: _root_.scala.Boolean = false
def companion: _root_.scalapb.GeneratedEnumCompanion[EnumValueNaming] = scalapb.options.ScalaPbOptions.EnumValueNaming
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ object CodeGeneratorResponse extends scalapb.GeneratedMessageCompanion[com.googl
*/
sealed abstract class Feature(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Feature
type RecognizedType = com.google.protobuf.compiler.plugin.CodeGeneratorResponse.Feature.Recognized
def isFeatureNone: _root_.scala.Boolean = false
def isFeatureProto3Optional: _root_.scala.Boolean = false
def companion: _root_.scalapb.GeneratedEnumCompanion[Feature] = com.google.protobuf.compiler.plugin.CodeGeneratorResponse.Feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ object FieldDescriptorProto extends scalapb.GeneratedMessageCompanion[com.google
)
sealed abstract class Type(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Type
type RecognizedType = com.google.protobuf.descriptor.FieldDescriptorProto.Type.Recognized
def isTypeDouble: _root_.scala.Boolean = false
def isTypeFloat: _root_.scala.Boolean = false
def isTypeInt64: _root_.scala.Boolean = false
Expand Down Expand Up @@ -600,6 +601,7 @@ object FieldDescriptorProto extends scalapb.GeneratedMessageCompanion[com.google
}
sealed abstract class Label(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Label
type RecognizedType = com.google.protobuf.descriptor.FieldDescriptorProto.Label.Recognized
def isLabelOptional: _root_.scala.Boolean = false
def isLabelRequired: _root_.scala.Boolean = false
def isLabelRepeated: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ object FieldOptions extends scalapb.GeneratedMessageCompanion[com.google.protobu
)
sealed abstract class CType(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = CType
type RecognizedType = com.google.protobuf.descriptor.FieldOptions.CType.Recognized
def isString: _root_.scala.Boolean = false
def isCord: _root_.scala.Boolean = false
def isStringPiece: _root_.scala.Boolean = false
Expand Down Expand Up @@ -370,6 +371,7 @@ object FieldOptions extends scalapb.GeneratedMessageCompanion[com.google.protobu
}
sealed abstract class JSType(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = JSType
type RecognizedType = com.google.protobuf.descriptor.FieldOptions.JSType.Recognized
def isJsNormal: _root_.scala.Boolean = false
def isJsString: _root_.scala.Boolean = false
def isJsNumber: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ object FileOptions extends scalapb.GeneratedMessageCompanion[com.google.protobuf
*/
sealed abstract class OptimizeMode(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = OptimizeMode
type RecognizedType = com.google.protobuf.descriptor.FileOptions.OptimizeMode.Recognized
def isSpeed: _root_.scala.Boolean = false
def isCodeSize: _root_.scala.Boolean = false
def isLiteRuntime: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ object MethodOptions extends scalapb.GeneratedMessageCompanion[com.google.protob
*/
sealed abstract class IdempotencyLevel(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = IdempotencyLevel
type RecognizedType = com.google.protobuf.descriptor.MethodOptions.IdempotencyLevel.Recognized
def isIdempotencyUnknown: _root_.scala.Boolean = false
def isNoSideEffects: _root_.scala.Boolean = false
def isIdempotent: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package com.google.protobuf.struct
*/
sealed abstract class NullValue(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = NullValue
type RecognizedType = com.google.protobuf.struct.NullValue.Recognized
def isNullValue: _root_.scala.Boolean = false
def companion: _root_.scalapb.GeneratedEnumCompanion[NullValue] = com.google.protobuf.struct.NullValue
final def asRecognized: _root_.scala.Option[com.google.protobuf.struct.NullValue.Recognized] = if (isUnrecognized) _root_.scala.None else _root_.scala.Some(this.asInstanceOf[com.google.protobuf.struct.NullValue.Recognized])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ object Field extends scalapb.GeneratedMessageCompanion[com.google.protobuf.`type
*/
sealed abstract class Kind(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Kind
type RecognizedType = com.google.protobuf.`type`.Field.Kind.Recognized
def isTypeUnknown: _root_.scala.Boolean = false
def isTypeDouble: _root_.scala.Boolean = false
def isTypeFloat: _root_.scala.Boolean = false
Expand Down Expand Up @@ -637,6 +638,7 @@ object Field extends scalapb.GeneratedMessageCompanion[com.google.protobuf.`type
*/
sealed abstract class Cardinality(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Cardinality
type RecognizedType = com.google.protobuf.`type`.Field.Cardinality.Recognized
def isCardinalityUnknown: _root_.scala.Boolean = false
def isCardinalityOptional: _root_.scala.Boolean = false
def isCardinalityRequired: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package com.google.protobuf.`type`
*/
sealed abstract class Syntax(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {
type EnumType = Syntax
type RecognizedType = com.google.protobuf.`type`.Syntax.Recognized
def isSyntaxProto2: _root_.scala.Boolean = false
def isSyntaxProto3: _root_.scala.Boolean = false
def companion: _root_.scalapb.GeneratedEnumCompanion[Syntax] = com.google.protobuf.`type`.Syntax
Expand Down

0 comments on commit 8dec8bf

Please sign in to comment.