placeholder.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright 2019 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package filedesc
  5. import (
  6. "google.golang.org/protobuf/internal/descopts"
  7. "google.golang.org/protobuf/internal/pragma"
  8. pref "google.golang.org/protobuf/reflect/protoreflect"
  9. )
  10. var (
  11. emptyNames = new(Names)
  12. emptyEnumRanges = new(EnumRanges)
  13. emptyFieldRanges = new(FieldRanges)
  14. emptyFieldNumbers = new(FieldNumbers)
  15. emptySourceLocations = new(SourceLocations)
  16. emptyFiles = new(FileImports)
  17. emptyMessages = new(Messages)
  18. emptyFields = new(Fields)
  19. emptyOneofs = new(Oneofs)
  20. emptyEnums = new(Enums)
  21. emptyEnumValues = new(EnumValues)
  22. emptyExtensions = new(Extensions)
  23. emptyServices = new(Services)
  24. )
  25. // PlaceholderFile is a placeholder, representing only the file path.
  26. type PlaceholderFile string
  27. func (f PlaceholderFile) ParentFile() pref.FileDescriptor { return f }
  28. func (f PlaceholderFile) Parent() pref.Descriptor { return nil }
  29. func (f PlaceholderFile) Index() int { return 0 }
  30. func (f PlaceholderFile) Syntax() pref.Syntax { return 0 }
  31. func (f PlaceholderFile) Name() pref.Name { return "" }
  32. func (f PlaceholderFile) FullName() pref.FullName { return "" }
  33. func (f PlaceholderFile) IsPlaceholder() bool { return true }
  34. func (f PlaceholderFile) Options() pref.ProtoMessage { return descopts.File }
  35. func (f PlaceholderFile) Path() string { return string(f) }
  36. func (f PlaceholderFile) Package() pref.FullName { return "" }
  37. func (f PlaceholderFile) Imports() pref.FileImports { return emptyFiles }
  38. func (f PlaceholderFile) Messages() pref.MessageDescriptors { return emptyMessages }
  39. func (f PlaceholderFile) Enums() pref.EnumDescriptors { return emptyEnums }
  40. func (f PlaceholderFile) Extensions() pref.ExtensionDescriptors { return emptyExtensions }
  41. func (f PlaceholderFile) Services() pref.ServiceDescriptors { return emptyServices }
  42. func (f PlaceholderFile) SourceLocations() pref.SourceLocations { return emptySourceLocations }
  43. func (f PlaceholderFile) ProtoType(pref.FileDescriptor) { return }
  44. func (f PlaceholderFile) ProtoInternal(pragma.DoNotImplement) { return }
  45. // PlaceholderEnum is a placeholder, representing only the full name.
  46. type PlaceholderEnum pref.FullName
  47. func (e PlaceholderEnum) ParentFile() pref.FileDescriptor { return nil }
  48. func (e PlaceholderEnum) Parent() pref.Descriptor { return nil }
  49. func (e PlaceholderEnum) Index() int { return 0 }
  50. func (e PlaceholderEnum) Syntax() pref.Syntax { return 0 }
  51. func (e PlaceholderEnum) Name() pref.Name { return pref.FullName(e).Name() }
  52. func (e PlaceholderEnum) FullName() pref.FullName { return pref.FullName(e) }
  53. func (e PlaceholderEnum) IsPlaceholder() bool { return true }
  54. func (e PlaceholderEnum) Options() pref.ProtoMessage { return descopts.Enum }
  55. func (e PlaceholderEnum) Values() pref.EnumValueDescriptors { return emptyEnumValues }
  56. func (e PlaceholderEnum) ReservedNames() pref.Names { return emptyNames }
  57. func (e PlaceholderEnum) ReservedRanges() pref.EnumRanges { return emptyEnumRanges }
  58. func (e PlaceholderEnum) ProtoType(pref.EnumDescriptor) { return }
  59. func (e PlaceholderEnum) ProtoInternal(pragma.DoNotImplement) { return }
  60. // PlaceholderEnumValue is a placeholder, representing only the full name.
  61. type PlaceholderEnumValue pref.FullName
  62. func (e PlaceholderEnumValue) ParentFile() pref.FileDescriptor { return nil }
  63. func (e PlaceholderEnumValue) Parent() pref.Descriptor { return nil }
  64. func (e PlaceholderEnumValue) Index() int { return 0 }
  65. func (e PlaceholderEnumValue) Syntax() pref.Syntax { return 0 }
  66. func (e PlaceholderEnumValue) Name() pref.Name { return pref.FullName(e).Name() }
  67. func (e PlaceholderEnumValue) FullName() pref.FullName { return pref.FullName(e) }
  68. func (e PlaceholderEnumValue) IsPlaceholder() bool { return true }
  69. func (e PlaceholderEnumValue) Options() pref.ProtoMessage { return descopts.EnumValue }
  70. func (e PlaceholderEnumValue) Number() pref.EnumNumber { return 0 }
  71. func (e PlaceholderEnumValue) ProtoType(pref.EnumValueDescriptor) { return }
  72. func (e PlaceholderEnumValue) ProtoInternal(pragma.DoNotImplement) { return }
  73. // PlaceholderMessage is a placeholder, representing only the full name.
  74. type PlaceholderMessage pref.FullName
  75. func (m PlaceholderMessage) ParentFile() pref.FileDescriptor { return nil }
  76. func (m PlaceholderMessage) Parent() pref.Descriptor { return nil }
  77. func (m PlaceholderMessage) Index() int { return 0 }
  78. func (m PlaceholderMessage) Syntax() pref.Syntax { return 0 }
  79. func (m PlaceholderMessage) Name() pref.Name { return pref.FullName(m).Name() }
  80. func (m PlaceholderMessage) FullName() pref.FullName { return pref.FullName(m) }
  81. func (m PlaceholderMessage) IsPlaceholder() bool { return true }
  82. func (m PlaceholderMessage) Options() pref.ProtoMessage { return descopts.Message }
  83. func (m PlaceholderMessage) IsMapEntry() bool { return false }
  84. func (m PlaceholderMessage) Fields() pref.FieldDescriptors { return emptyFields }
  85. func (m PlaceholderMessage) Oneofs() pref.OneofDescriptors { return emptyOneofs }
  86. func (m PlaceholderMessage) ReservedNames() pref.Names { return emptyNames }
  87. func (m PlaceholderMessage) ReservedRanges() pref.FieldRanges { return emptyFieldRanges }
  88. func (m PlaceholderMessage) RequiredNumbers() pref.FieldNumbers { return emptyFieldNumbers }
  89. func (m PlaceholderMessage) ExtensionRanges() pref.FieldRanges { return emptyFieldRanges }
  90. func (m PlaceholderMessage) ExtensionRangeOptions(int) pref.ProtoMessage { panic("index out of range") }
  91. func (m PlaceholderMessage) Messages() pref.MessageDescriptors { return emptyMessages }
  92. func (m PlaceholderMessage) Enums() pref.EnumDescriptors { return emptyEnums }
  93. func (m PlaceholderMessage) Extensions() pref.ExtensionDescriptors { return emptyExtensions }
  94. func (m PlaceholderMessage) ProtoType(pref.MessageDescriptor) { return }
  95. func (m PlaceholderMessage) ProtoInternal(pragma.DoNotImplement) { return }