|
14 | 14 | #include <string> |
15 | 15 |
|
16 | 16 | #include "absl/container/flat_hash_set.h" |
| 17 | +#include "absl/log/absl_check.h" |
17 | 18 | #include "absl/strings/str_cat.h" |
18 | 19 | #include "absl/strings/string_view.h" |
| 20 | +#include "google/protobuf/compiler/java/java_features.pb.h" |
| 21 | +#include "google/protobuf/compiler/java/generator.h" |
19 | 22 | #include "google/protobuf/compiler/java/helpers.h" |
20 | 23 | #include "google/protobuf/compiler/java/name_resolver.h" |
21 | 24 | #include "google/protobuf/compiler/java/names_internal.h" |
@@ -94,6 +97,21 @@ std::string FieldName(const FieldDescriptor* field) { |
94 | 97 | return field_name; |
95 | 98 | } |
96 | 99 |
|
| 100 | +template <typename Descriptor> |
| 101 | +bool NestedInFileClassImpl(const Descriptor& descriptor) { |
| 102 | + auto nest_in_file_class = |
| 103 | + JavaGenerator::GetResolvedSourceFeatureExtension(descriptor, pb::java) |
| 104 | + .nest_in_file_class(); |
| 105 | + ABSL_CHECK( |
| 106 | + nest_in_file_class != |
| 107 | + pb::JavaFeatures::NestInFileClassFeature::NEST_IN_FILE_CLASS_UNKNOWN); |
| 108 | + |
| 109 | + if (nest_in_file_class == pb::JavaFeatures::NestInFileClassFeature::LEGACY) { |
| 110 | + return !descriptor.file()->options().java_multiple_files(); |
| 111 | + } |
| 112 | + return nest_in_file_class == pb::JavaFeatures::NestInFileClassFeature::YES; |
| 113 | +} |
| 114 | + |
97 | 115 | } // namespace |
98 | 116 |
|
99 | 117 | std::string QualifiedClassName(const Descriptor* descriptor) { |
@@ -161,24 +179,34 @@ std::string UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field) { |
161 | 179 | return name; |
162 | 180 | } |
163 | 181 |
|
164 | | -PROTOC_EXPORT std::string KotlinFactoryName(const Descriptor* descriptor) { |
| 182 | +std::string KotlinFactoryName(const Descriptor* descriptor) { |
165 | 183 | ClassNameResolver name_resolver; |
166 | 184 | return name_resolver.GetKotlinFactoryName(descriptor); |
167 | 185 | } |
168 | 186 |
|
169 | | -PROTOC_EXPORT std::string FullyQualifiedKotlinFactoryName( |
170 | | - const Descriptor* descriptor) { |
| 187 | +std::string FullyQualifiedKotlinFactoryName(const Descriptor* descriptor) { |
171 | 188 | ClassNameResolver name_resolver; |
172 | 189 | return name_resolver.GetFullyQualifiedKotlinFactoryName(descriptor); |
173 | 190 | } |
174 | 191 |
|
175 | | -PROTOC_EXPORT std::string KotlinExtensionsClassName( |
176 | | - const Descriptor* descriptor) { |
| 192 | +std::string KotlinExtensionsClassName(const Descriptor* descriptor) { |
177 | 193 | ClassNameResolver name_resolver; |
178 | 194 | return name_resolver.GetKotlinExtensionsClassName(descriptor); |
179 | 195 | } |
180 | 196 |
|
181 | 197 |
|
| 198 | +bool NestedInFileClass(const Descriptor& message) { |
| 199 | + return NestedInFileClassImpl(message); |
| 200 | +} |
| 201 | + |
| 202 | +bool NestedInFileClass(const EnumDescriptor& enm) { |
| 203 | + return NestedInFileClassImpl(enm); |
| 204 | +} |
| 205 | + |
| 206 | +bool NestedInFileClass(const ServiceDescriptor& service) { |
| 207 | + return NestedInFileClassImpl(service); |
| 208 | +} |
| 209 | + |
182 | 210 | } // namespace java |
183 | 211 | } // namespace compiler |
184 | 212 | } // namespace protobuf |
|
0 commit comments