• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc.  All rights reserved.
3//
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file or at
6// https://developers.google.com/open-source/licenses/bsd
7
8// Author: jonp@google.com (Jon Perlow)
9
10// This file tests that various identifiers work as field and type names even
11// though the same identifiers are used internally by the java code generator.
12// LINT: LEGACY_NAMES
13
14edition = "2023";
15
16package io_protocol_tests;
17
18option features.repeated_field_encoding = EXPANDED;
19option features.utf8_validation = NONE;
20option features.enum_type = CLOSED;
21option java_generic_services = true;  // auto-added
22option java_package = "com.google.protobuf";
23option java_outer_classname = "TestBadIdentifiersProto";
24
25// Message with field names using underscores that conflict with accessors in
26// the base message class in java. See kForbiddenWordList in
27// src/google/protobuf/compiler/java/java_helpers.cc
28message ForbiddenWordsUnderscoreMessage {
29  // java.lang.Object
30  bool class = 1;
31  // com.google.protobuf.MessageLiteOrBuilder
32  bool default_instance_for_type = 2;
33  // com.google.protobuf.MessageLite
34  bool parser_for_type = 3;
35  bool serialized_size = 4;
36  // com.google.protobuf.MessageOrBuilder
37  bool all_fields = 5;
38  bool descriptor_for_type = 6;
39  bool initialization_error_string = 7;
40  bool unknown_fields = 8;
41  // obsolete. kept for backwards compatibility of generated code
42  bool cached_size = 9;
43}
44
45// Message with field names using leading underscores that conflict with
46// accessors in the base message class in java. See kForbiddenWordList in
47// src/google/protobuf/compiler/java/java_helpers.cc
48message ForbiddenWordsLeadingUnderscoreMessage {
49  // java.lang.Object
50  bool _class = 1;
51  // com.google.protobuf.MessageLiteOrBuilder
52  bool _default_instance_for_type = 2;
53  // com.google.protobuf.MessageLite
54  bool _parser_for_type = 3;
55  bool _serialized_size = 4;
56  // com.google.protobuf.MessageOrBuilder
57  bool _all_fields = 5;
58  bool _descriptor_for_type = 6;
59  bool _initialization_error_string = 7;
60  // TODO: re-enable
61  // bool _unknown_fields = 8;
62  // obsolete. kept for backwards compatibility of generated code
63  bool _cached_size = 9;
64}
65
66// Message with field names in camel case that conflict with accessors in the
67// base message class in java. See kForbiddenWordList in
68// src/google/protobuf/compiler/java/java_helpers.cc
69message ForbiddenWordsCamelMessage {
70  // java.lang.Object
71  bool class = 1;
72  // com.google.protobuf.MessageLiteOrBuilder
73  bool defaultInstanceForType = 2;
74  // com.google.protobuf.MessageLite
75  bool serializedSize = 3;
76  bool parserForType = 4;
77  // com.google.protobuf.MessageOrBuilder:
78  bool initializationErrorString = 5;
79  bool descriptorForType = 6;
80  bool allFields = 7;
81  // TODO: re-enable
82  // bool unknownFields = 8;
83  // obsolete. kept for backwards compatibility of generated code
84  bool cachedSize = 9;
85}
86
87message Descriptor {
88  option no_standard_descriptor_accessor = true;
89
90  string descriptor = 1;
91  message NestedDescriptor {
92    option no_standard_descriptor_accessor = true;
93
94    string descriptor = 1;
95  }
96  NestedDescriptor nested_descriptor = 2;
97  enum NestedEnum {
98    UNKNOWN = 0;
99    FOO = 1;
100  }
101}
102
103message Parser {
104  enum ParserEnum {
105    UNKNOWN = 0;
106    PARSER = 1;
107  }
108  ParserEnum parser = 1;
109}
110
111message Deprecated {
112  enum TestEnum {
113    UNKNOWN = 0;
114    FOO = 1;
115
116    // Test if @Deprecated annotation conflicts with Deprecated message name.
117    BAR = 2 [deprecated = true];
118  }
119
120  int32 field1 = 1 [deprecated = true];
121  TestEnum field2 = 2 [deprecated = true];
122  ForbiddenWordsUnderscoreMessage field3 = 3 [deprecated = true];
123}
124
125message Override {
126  int32 override = 1;
127}
128
129message Object {
130  int32 object = 1;
131  string string_object = 2;
132}
133
134message String {
135  string string = 1;
136}
137
138message Integer {
139  int32 integer = 1;
140}
141
142message Long {
143  int32 long = 1;
144}
145
146message Float {
147  float float = 1;
148}
149
150message Double {
151  double double = 1;
152}
153
154service TestConflictingMethodNames {
155  rpc Override(ForbiddenWordsUnderscoreMessage)
156      returns (ForbiddenWordsUnderscoreMessage);
157}
158
159message TestConflictingFieldNames {
160  // TODO Remove these tests once this behavior is removed.
161  option deprecated_legacy_json_field_conflicts = true;
162
163  enum TestEnum {
164    UNKNOWN = 0;
165    FOO = 1;
166  }
167  message ForbiddenWordsUnderscoreMessage {}
168  repeated int32 int32_field = 1;
169  repeated TestEnum enum_field = 2;
170  repeated string string_field = 3;
171  repeated bytes bytes_field = 4;
172  repeated ForbiddenWordsUnderscoreMessage message_field = 5;
173
174  int32 int32_field_count = 11;
175  TestEnum enum_field_count = 12;
176  string string_field_count = 13;
177  bytes bytes_field_count = 14;
178  ForbiddenWordsUnderscoreMessage message_field_count = 15;
179
180  repeated int32 Int32Field = 21;                              // NO_PROTO3
181  repeated TestEnum EnumField = 22;                            // NO_PROTO3
182  repeated string StringField = 23;                            // NO_PROTO3
183  repeated bytes BytesField = 24;                              // NO_PROTO3
184  repeated ForbiddenWordsUnderscoreMessage MessageField = 25;  // NO_PROTO3
185
186  // This field conflicts with "int32_field" as they both generate
187  // the method getInt32FieldList().
188  int32 int32_field_list = 31
189      [features.field_presence = LEGACY_REQUIRED];  // NO_PROTO3
190
191  // These field pairs have the same Java converted name
192  string field_name = 32;   // NO_PROTO3
193  string field__name = 33;  // NO_PROTO3
194  int32 _2conflict = 34;    // NO_PROTO3
195  int32 __2conflict = 35;
196
197  extensions 1000 to max;  // NO_PROTO3
198
199  repeated int64 int64_field = 41;
200  extend TestConflictingFieldNames {  // NO_PROTO3
201    // We don't generate accessors for extensions so the following extension
202    // fields don't conflict with the repeated field "int64_field".
203    int64 int64_field_count = 1001;  // NO_PROTO3
204    int64 int64_field_list = 1002;   // NO_PROTO3
205  }  // NO_PROTO3
206}
207
208message TestMapField {
209  message MapField {}
210  message Pair {}
211  message Message {}
212
213  map<int32, int32> map_field = 1;
214}
215
216message TestLeadingNumberFields {
217  int32 _30day_impressions = 1;
218  repeated string _60day_impressions = 2;
219
220  string __2_underscores = 3;
221  repeated string __2repeated_underscores = 4;
222
223  int32 _32 = 32;
224  repeated int64 _64 = 64;
225}
226