Skip to content

Commit 1f77302

Browse files
committed
Remove enum from method model
1 parent 27bdc9e commit 1f77302

File tree

10 files changed

+43
-55
lines changed

10 files changed

+43
-55
lines changed

gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.api.generator.gapic.composer.utils.ClassNames;
2323
import com.google.api.generator.gapic.composer.utils.CommentFormatter;
2424
import com.google.api.generator.gapic.model.Method;
25-
import com.google.api.generator.gapic.model.Method.SelectiveGapicType;
2625
import com.google.api.generator.gapic.model.MethodArgument;
2726
import com.google.api.generator.gapic.model.Service;
2827
import com.google.api.generator.gapic.utils.JavaStyle;
@@ -203,7 +202,7 @@ public static List<CommentStatement> createRpcMethodHeaderComment(
203202
methodJavadocBuilder.setDeprecated(CommentComposer.DEPRECATED_METHOD_STRING);
204203
}
205204

206-
if (method.selectiveGapicType() == SelectiveGapicType.INTERNAL) {
205+
if (method.isPublic() == false) {
207206
methodJavadocBuilder.setInternalOnly(CommentComposer.INTERNAL_ONLY_METHOD_STRING);
208207
}
209208

@@ -350,7 +349,7 @@ public static List<CommentStatement> createRpcCallableMethodHeaderComment(
350349
methodJavadocBuilder.setDeprecated(CommentComposer.DEPRECATED_METHOD_STRING);
351350
}
352351

353-
if (method.selectiveGapicType() == SelectiveGapicType.INTERNAL) {
352+
if (method.isPublic() == false) {
354353
methodJavadocBuilder.setInternalOnly(CommentComposer.INTERNAL_ONLY_METHOD_STRING);
355354
}
356355

gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
import com.google.api.generator.gapic.model.LongrunningOperation;
7272
import com.google.api.generator.gapic.model.Message;
7373
import com.google.api.generator.gapic.model.Method;
74-
import com.google.api.generator.gapic.model.Method.SelectiveGapicType;
7574
import com.google.api.generator.gapic.model.Method.Stream;
7675
import com.google.api.generator.gapic.model.MethodArgument;
7776
import com.google.api.generator.gapic.model.ResourceName;
@@ -810,7 +809,7 @@ private static List<MethodDefinition> createMethodVariants(
810809
annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED));
811810
}
812811

813-
if (method.selectiveGapicType() == SelectiveGapicType.INTERNAL) {
812+
if (method.isPublic() == false) {
814813
annotations.add(
815814
AnnotationNode.withTypeAndDescription(
816815
typeStore.get("InternalApi"), INTERNAL_API_WARNING));
@@ -899,7 +898,7 @@ private static MethodDefinition createMethodDefaultMethod(
899898
annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED));
900899
}
901900

902-
if (method.selectiveGapicType() == SelectiveGapicType.INTERNAL) {
901+
if (method.isPublic() == false) {
903902
annotations.add(
904903
AnnotationNode.withTypeAndDescription(
905904
typeStore.get("InternalApi"), INTERNAL_API_WARNING));
@@ -1059,7 +1058,7 @@ private static MethodDefinition createCallableMethod(
10591058
if (method.isDeprecated()) {
10601059
annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED));
10611060
}
1062-
if (method.selectiveGapicType() == SelectiveGapicType.INTERNAL) {
1061+
if (method.isPublic() == false) {
10631062
annotations.add(
10641063
AnnotationNode.withTypeAndDescription(
10651064
typeStore.get("InternalApi"), INTERNAL_API_WARNING));

gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import com.google.api.generator.gapic.model.GapicClass.Kind;
6262
import com.google.api.generator.gapic.model.GapicContext;
6363
import com.google.api.generator.gapic.model.Method;
64-
import com.google.api.generator.gapic.model.Method.SelectiveGapicType;
6564
import com.google.api.generator.gapic.model.Method.Stream;
6665
import com.google.api.generator.gapic.model.Sample;
6766
import com.google.api.generator.gapic.model.Service;
@@ -142,7 +141,7 @@ private static List<CommentStatement> createClassHeaderComments(
142141
// list.
143142
List<Method> publicMethods =
144143
service.methods().stream()
145-
.filter(m -> m.selectiveGapicType() == SelectiveGapicType.PUBLIC)
144+
.filter(m -> m.isPublic() == true)
146145
.collect(Collectors.toList());
147146
Optional<Method> methodOpt =
148147
publicMethods.isEmpty()
@@ -301,7 +300,7 @@ private static MethodDefinition methodBuilderHelper(
301300
annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED));
302301
}
303302

304-
if (protoMethod.selectiveGapicType() == SelectiveGapicType.INTERNAL) {
303+
if (protoMethod.isPublic() == false) {
305304
annotations.add(
306305
AnnotationNode.withTypeAndDescription(
307306
FIXED_TYPESTORE.get("InternalApi"), INTERNAL_API_WARNING));
@@ -312,7 +311,7 @@ private static MethodDefinition methodBuilderHelper(
312311
SettingsCommentComposer.createCallSettingsGetterComment(
313312
getMethodNameFromSettingsVarName(javaMethodName),
314313
protoMethod.isDeprecated(),
315-
protoMethod.selectiveGapicType() == SelectiveGapicType.INTERNAL))
314+
protoMethod.isPublic() == false))
316315
.setAnnotations(annotations)
317316
.build();
318317
}
@@ -786,7 +785,7 @@ private static List<MethodDefinition> createNestedBuilderSettingsGetterMethods(
786785
SettingsCommentComposer.createCallSettingsBuilderGetterComment(
787786
getMethodNameFromSettingsVarName(javaMethodName),
788787
protoMethod.isDeprecated(),
789-
protoMethod.selectiveGapicType() == SelectiveGapicType.INTERNAL))
788+
protoMethod.isPublic() == false))
790789
.setAnnotations(
791790
protoMethod.isDeprecated()
792791
? Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED))
@@ -803,7 +802,7 @@ private static List<MethodDefinition> createNestedBuilderSettingsGetterMethods(
803802
SettingsCommentComposer.createCallSettingsBuilderGetterComment(
804803
getMethodNameFromSettingsVarName(javaMethodName),
805804
protoMethod.isDeprecated(),
806-
protoMethod.selectiveGapicType() == SelectiveGapicType.INTERNAL))
805+
protoMethod.isPublic() == false))
807806
.setAnnotations(
808807
protoMethod.isDeprecated()
809808
? Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED))

gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import com.google.api.generator.gapic.model.GapicContext;
4242
import com.google.api.generator.gapic.model.Message;
4343
import com.google.api.generator.gapic.model.Method;
44-
import com.google.api.generator.gapic.model.Method.SelectiveGapicType;
4544
import com.google.api.generator.gapic.model.Service;
4645
import com.google.api.generator.gapic.utils.JavaStyle;
4746
import com.google.common.collect.ImmutableList;
@@ -203,7 +202,7 @@ private MethodDefinition createCallableGetterHelper(
203202
if (method.isDeprecated()) {
204203
annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED));
205204
}
206-
if (method.selectiveGapicType() == SelectiveGapicType.INTERNAL) {
205+
if (method.isPublic() == false) {
207206
annotations.add(
208207
AnnotationNode.withTypeAndDescription(
209208
typeStore.get("InternalApi"), INTERNAL_API_WARNING));

gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
import com.google.api.generator.gapic.model.GapicServiceConfig;
9393
import com.google.api.generator.gapic.model.Message;
9494
import com.google.api.generator.gapic.model.Method;
95-
import com.google.api.generator.gapic.model.Method.SelectiveGapicType;
9695
import com.google.api.generator.gapic.model.Method.Stream;
9796
import com.google.api.generator.gapic.model.Sample;
9897
import com.google.api.generator.gapic.model.Service;
@@ -425,7 +424,7 @@ private static List<CommentStatement> createClassHeaderComments(
425424
// list.
426425
List<Method> publicMethods =
427426
service.methods().stream()
428-
.filter(m -> m.selectiveGapicType() == SelectiveGapicType.PUBLIC)
427+
.filter(m -> m.isPublic() == true)
429428
.collect(Collectors.toList());
430429
Optional<Method> methodOpt =
431430
publicMethods.isEmpty()
@@ -505,7 +504,7 @@ private static Map<String, VariableExpr> createMethodSettingsClassMemberVarExprs
505504
if (method.isDeprecated()) {
506505
deprecatedSettingVarNames.add(varName);
507506
}
508-
if (method.selectiveGapicType() == SelectiveGapicType.INTERNAL) {
507+
if (method.isPublic() == false) {
509508
internalSettingVarNames.add(varName);
510509
}
511510
varExprs.put(

gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposer.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.google.api.generator.gapic.model.HttpBindings;
3131
import com.google.api.generator.gapic.model.Message;
3232
import com.google.api.generator.gapic.model.Method;
33-
import com.google.api.generator.gapic.model.Method.SelectiveGapicType;
3433
import com.google.api.generator.gapic.model.MethodArgument;
3534
import com.google.api.generator.gapic.model.RegionTag;
3635
import com.google.api.generator.gapic.model.ResourceName;
@@ -53,28 +52,25 @@ public static Sample composeClassHeaderSample(
5352
TypeNode clientType,
5453
Map<String, ResourceName> resourceNames,
5554
Map<String, Message> messageTypes) {
55+
List<Method> publicMethods =
56+
service.methods().stream()
57+
.filter(m -> m.isPublic() == true)
58+
.collect(Collectors.toList());
59+
5660
// If all generated methods are INTERNAL, generate an empty service sample.
57-
if (service.methods().stream()
58-
.filter(m -> m.selectiveGapicType() == SelectiveGapicType.PUBLIC)
59-
.count()
60-
== 0) {
61+
if (publicMethods.isEmpty()) {
6162
return ServiceClientMethodSampleComposer.composeEmptyServiceSample(clientType, service);
6263
}
64+
6365
// Use the first public pure unary RPC method's sample code as showcase, if no such method
64-
// exists, use
65-
// the first public method in the service's methods list.
66-
List<Method> publicMethods =
67-
service.methods().stream()
68-
.filter(m -> m.selectiveGapicType() == SelectiveGapicType.PUBLIC)
69-
.collect(Collectors.toList());
66+
// exists, use the first public method in the service's methods list.
7067
Method method =
7168
publicMethods.stream()
7269
.filter(
7370
m ->
7471
m.stream() == Method.Stream.NONE
7572
&& !m.hasLro()
76-
&& !m.isPaged()
77-
&& m.selectiveGapicType() != SelectiveGapicType.INTERNAL)
73+
&& !m.isPaged())
7874
.findFirst()
7975
.orElse(publicMethods.get(0));
8076

gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/Method.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ public enum Stream {
3030
BIDI
3131
};
3232

33-
public enum SelectiveGapicType {
34-
PUBLIC,
35-
HIDDEN,
36-
INTERNAL
37-
}
38-
3933
public abstract String name();
4034

4135
public abstract Stream stream();
@@ -44,7 +38,7 @@ public enum SelectiveGapicType {
4438

4539
public abstract TypeNode outputType();
4640

47-
public abstract SelectiveGapicType selectiveGapicType();
41+
public abstract boolean isPublic();
4842

4943
public abstract boolean isBatching();
5044

@@ -144,7 +138,7 @@ public static Builder builder() {
144138
.setStream(Stream.NONE)
145139
.setAutoPopulatedFields(new ArrayList<>())
146140
.setMethodSignatures(ImmutableList.of())
147-
.setSelectiveGapicType(SelectiveGapicType.PUBLIC)
141+
.setIsPublic(false)
148142
.setIsBatching(false)
149143
.setIsDeprecated(false)
150144
.setOperationPollingMethod(false);
@@ -170,8 +164,7 @@ public abstract static class Builder {
170164
public abstract Builder setInputType(TypeNode inputType);
171165

172166
public abstract Builder setOutputType(TypeNode outputType);
173-
174-
public abstract Builder setSelectiveGapicType(SelectiveGapicType gapicType);
167+
public abstract Builder setIsPublic(boolean isPublic);
175168

176169
public abstract Builder setStream(Stream stream);
177170

gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import com.google.api.generator.gapic.model.LongrunningOperation;
3939
import com.google.api.generator.gapic.model.Message;
4040
import com.google.api.generator.gapic.model.Method;
41-
import com.google.api.generator.gapic.model.Method.SelectiveGapicType;
4241
import com.google.api.generator.gapic.model.OperationResponse;
4342
import com.google.api.generator.gapic.model.ResourceName;
4443
import com.google.api.generator.gapic.model.ResourceReference;
@@ -93,7 +92,11 @@
9392
import java.util.stream.IntStream;
9493

9594
public class Parser {
96-
95+
enum SelectiveGapicType {
96+
PUBLIC,
97+
HIDDEN,
98+
INTERNAL
99+
}
97100
private static final Logger LOGGER = Logger.getLogger(Parser.class.getName());
98101
private static final String COMMA = ",";
99102
private static final String COLON = ":";
@@ -846,7 +849,7 @@ static List<Method> parseMethods(
846849
.setName(protoMethod.getName())
847850
.setInputType(inputType)
848851
.setOutputType(TypeParser.parseType(protoMethod.getOutputType()))
849-
.setSelectiveGapicType(methodSelectiveGapicType)
852+
.setIsPublic(methodSelectiveGapicType == SelectiveGapicType.PUBLIC)
850853
.setStream(
851854
Method.toStream(protoMethod.isClientStreaming(), protoMethod.isServerStreaming()))
852855
.setLro(parseLro(servicePackage, protoMethod, messageTypes))

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.api.generator.gapic.model.LongrunningOperation;
2323
import com.google.api.generator.gapic.model.Message;
2424
import com.google.api.generator.gapic.model.Method;
25-
import com.google.api.generator.gapic.model.Method.SelectiveGapicType;
2625
import com.google.api.generator.gapic.model.MethodArgument;
2726
import com.google.api.generator.gapic.model.ResourceName;
2827
import com.google.api.generator.gapic.model.Sample;
@@ -217,6 +216,7 @@ void composeClassHeaderSample_firstMethodHasNoSignatures() {
217216
writeStatements(
218217
ServiceClientHeaderSampleComposer.composeClassHeaderSample(
219218
service, clientType, resourceNames, messageTypes));
219+
System.out.println("results: " + results);
220220
String expected =
221221
LineFormatter.lines(
222222
"try (EchoClient echoClient = EchoClient.create()) {\n",
@@ -231,6 +231,7 @@ void composeClassHeaderSample_firstMethodHasNoSignatures() {
231231
" .build();\n",
232232
" EchoResponse response = echoClient.echo(request);\n",
233233
"}");
234+
System.out.println("results: " + expected);
234235
Assert.assertEquals(results, expected);
235236
}
236237

@@ -316,14 +317,14 @@ void composeClassHeaderSample_firstMethodIsInternal() {
316317
.setName("ChatShouldGenerateAsInternal")
317318
.setInputType(inputType)
318319
.setOutputType(outputType)
319-
.setSelectiveGapicType(SelectiveGapicType.INTERNAL)
320+
.setIsPublic(false)
320321
.build();
321322
Method publicMethod =
322323
Method.builder()
323324
.setName("ChatShouldGenerateAsPublic")
324325
.setInputType(inputType)
325326
.setOutputType(outputType)
326-
.setSelectiveGapicType(SelectiveGapicType.PUBLIC)
327+
.setIsPublic(true)
327328
.build();
328329
Service service =
329330
Service.builder()
@@ -386,14 +387,14 @@ void composeClassHeaderSample_allMethodsAreInternal() {
386387
.setName("ChatShouldGenerateAsInternal")
387388
.setInputType(inputType)
388389
.setOutputType(outputType)
389-
.setSelectiveGapicType(SelectiveGapicType.INTERNAL)
390+
.setIsPublic(false)
390391
.build();
391392
Method internalMethod2 =
392393
Method.builder()
393394
.setName("EchoShouldGenerateAsInternal")
394395
.setInputType(inputType)
395396
.setOutputType(outputType)
396-
.setSelectiveGapicType(SelectiveGapicType.INTERNAL)
397+
.setIsPublic(false)
397398
.build();
398399
Service service =
399400
Service.builder()

gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
import com.google.api.generator.gapic.model.GapicContext;
3636
import com.google.api.generator.gapic.model.Message;
3737
import com.google.api.generator.gapic.model.Method;
38-
import com.google.api.generator.gapic.model.Method.SelectiveGapicType;
3938
import com.google.api.generator.gapic.model.MethodArgument;
4039
import com.google.api.generator.gapic.model.ResourceName;
4140
import com.google.api.generator.gapic.model.ResourceReference;
4241
import com.google.api.generator.gapic.model.Transport;
42+
import com.google.api.generator.gapic.protoparser.Parser.SelectiveGapicType;
4343
import com.google.api.version.test.ApiVersionTestingOuterClass;
4444
import com.google.auto.populate.field.AutoPopulateFieldTestingOuterClass;
4545
import com.google.bookshop.v1beta1.BookshopProto;
@@ -761,7 +761,7 @@ void selectiveGenerationTest_shouldGenerateOnlySelectiveMethodsWithGenerateOmitt
761761
assertEquals(3, services.get(0).methods().size());
762762
for (Method method : services.get(0).methods()) {
763763
assertTrue(method.name().contains("ShouldGenerate"));
764-
assertTrue(method.selectiveGapicType().equals(SelectiveGapicType.PUBLIC));
764+
assertTrue(method.isPublic());
765765
}
766766
}
767767

@@ -789,24 +789,24 @@ void selectiveGenerationTest_shouldGenerateOmittedAsInternalWithGenerateOmittedT
789789
assertEquals("EchoServiceShouldGenerateAllPublic", services.get(0).overriddenName());
790790
assertEquals(3, services.get(0).methods().size());
791791
for (Method method : services.get(0).methods()) {
792-
assertTrue(method.selectiveGapicType().equals(SelectiveGapicType.PUBLIC));
792+
assertTrue(method.isPublic());
793793
}
794794

795795
// Tests a service with partial public methods and partial internal methods.
796796
assertEquals("EchoServiceShouldGeneratePartialPublic", services.get(1).overriddenName());
797797
assertEquals(5, services.get(1).methods().size());
798798
for (Method method : services.get(1).methods()) {
799799
if (method.name().contains("ShouldGenerateAsPublic")) {
800-
assertTrue(method.selectiveGapicType().equals(SelectiveGapicType.PUBLIC));
800+
assertTrue(method.isPublic());
801801
} else {
802-
assertTrue(method.selectiveGapicType().equals(SelectiveGapicType.INTERNAL));
802+
assertFalse(method.isPublic());
803803
}
804804
}
805805
// Tests a service with internal methods only.
806806
assertEquals("EchoServiceShouldGenerateAllInternal", services.get(2).overriddenName());
807807
assertEquals(2, services.get(2).methods().size());
808808
for (Method method : services.get(2).methods()) {
809-
assertTrue(method.selectiveGapicType().equals(SelectiveGapicType.INTERNAL));
809+
assertFalse(method.isPublic());
810810
}
811811
}
812812

0 commit comments

Comments
 (0)