File tree 3 files changed +54
-25
lines changed
protokt-codegen/src/main/kotlin/com/toasttab/protokt/codegen/impl
options/src/main/proto/com/toasttab/protokt/testing/options
runtime-tests/src/main/proto/com/toasttab/protokt/testing/rt/oneof
3 files changed +54
-25
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ private constructor(
91
91
PClass .fromName(fieldType).let {
92
92
// If a wrapper type is specified and it shares a name with the
93
93
// oneof, it must be fully qualified.
94
+ // See testing/options/src/main/proto/com/toasttab/protokt/testing/options/oneof_exercises.proto
94
95
if (unqualifiedType.simpleName == it.simpleName) {
95
96
it.possiblyQualify(ctx.pkg).qualifiedName
96
97
} else {
@@ -109,21 +110,21 @@ private constructor(
109
110
val pClass = f.typePClass
110
111
111
112
// Cannot strip qualifiers for field type in a different package
113
+ // See testing/runtime-tests/src/main/proto/com/toasttab/protokt/testing/rt/oneof/oneof_packages.proto
112
114
val requiresQualifiedTypeName = pClass.ppackage != ctx.pkg
113
115
114
116
return if (requiresQualifiedTypeName) {
115
117
pClass.renderName(ctx.pkg)
116
118
} else {
117
- if (oneofFieldTypeName == pClass.nestedName) {
118
- // Oneof field name shares name of its type
119
- if (oneofFieldTypeName == pClass.simpleName) {
120
- // Oneof field name shares name of its enclosing type
119
+ // See testing/runtime-tests/src/main/proto/com/toasttab/protokt/testing/rt/oneof/oneof_exercises.proto
120
+ if (oneofFieldTypeName == pClass.simpleName) {
121
+ if (oneofFieldTypeName == pClass.nestedName) {
121
122
pClass.qualifiedName
122
123
} else {
123
- pClass.simpleName
124
+ pClass.nestedName
124
125
}
125
126
} else {
126
- pClass.nestedName
127
+ pClass.simpleName
127
128
}
128
129
}
129
130
}
Original file line number Diff line number Diff line change @@ -23,27 +23,9 @@ import "protokt/protokt.proto";
23
23
// generated sealed class type names. If the code generator does
24
24
// not handle them properly then compilation will fail.
25
25
26
- message OneofExerciseModel {
27
- oneof oneof {
28
- // Needs partial qualification: OneofExerciseModel.Model
29
- Model model = 1 ;
30
- }
31
-
32
- message Model {
33
- bytes id = 1 ;
34
- }
35
- }
36
-
37
- message OneofExerciseModel2 {
38
- oneof oneof {
39
- // Needs full qualification: com.toasttab.model.OneofExerciseModel
40
- OneofExerciseModel oneof_exercise_model = 1 ;
41
- }
42
- }
43
-
44
26
message OneofExerciseModelWithWrapper {
45
27
oneof oneof {
46
- // Needs full qualification: com.toasttab.testing.options.CachingId
28
+ // Needs full qualification: com.toasttab.protokt. testing.options.CachingId
47
29
bytes caching_id = 1 [
48
30
(.protokt.property ).wrap = "CachingId"
49
31
];
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2020 Toast Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ syntax = "proto3" ;
17
+
18
+ package com.toasttab.protokt.testing.rt.oneof ;
19
+
20
+ // This file exercises oneofs whose names are the same as their
21
+ // generated sealed class type names. If the code generator does
22
+ // not handle them properly then compilation will fail.
23
+
24
+ message OneofExerciseModel {
25
+ oneof oneof {
26
+ // Needs partial qualification: OneofExerciseModel.Model
27
+ Model model = 1 ;
28
+ }
29
+
30
+ oneof oneof2 {
31
+ // Does not need partial qualification: Model
32
+ // This will still compile if qualified but may show a warning in IDEs
33
+ Model not_named_model = 2 ;
34
+ }
35
+
36
+ message Model {
37
+ bytes id = 1 ;
38
+ }
39
+ }
40
+
41
+ message OneofExerciseModel2 {
42
+ oneof oneof {
43
+ // Needs full qualification: com.toasttab.protokt.testing.rt.oneof.OneofExerciseModel
44
+ OneofExerciseModel oneof_exercise_model = 1 ;
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments