From 5226136669c7ac3d82733d6b30abbb622eab835b Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Mon, 20 Sep 2021 11:18:01 -0400 Subject: [PATCH 1/3] Fix collection order --- .../java/com/google/api/generator/gapic/protoparser/Parser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java b/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java index 42e2abaa2f..345fc3384d 100644 --- a/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java +++ b/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java @@ -378,7 +378,7 @@ public static List parseServices( outputMixinServices.addAll( outputMixinServiceSet.stream() .sorted((s1, s2) -> s2.name().compareTo(s1.name())) - .collect(Collectors.toSet())); + .collect(Collectors.toList())); return services; } From 335de9d6a5c47ef3bee11aaa6b71490f08869f07 Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Mon, 20 Sep 2021 11:30:24 -0400 Subject: [PATCH 2/3] minor cleanups --- .../api/generator/gapic/protoparser/Parser.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java b/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java index 345fc3384d..9c4c916033 100644 --- a/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java +++ b/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java @@ -115,8 +115,8 @@ public static GapicContext parse(CodeGeneratorRequest request) { boolean willGenerateMetadata = PluginArgumentParser.hasMetadataFlag(request); Optional serviceConfigPathOpt = PluginArgumentParser.parseJsonConfigPath(request); - String serviceConfigPath = serviceConfigPathOpt.isPresent() ? serviceConfigPathOpt.get() : null; - Optional serviceConfigOpt = ServiceConfigParser.parse(serviceConfigPath); + Optional serviceConfigOpt = + ServiceConfigParser.parse(serviceConfigPathOpt.orElse(null)); if (serviceConfigOpt.isPresent()) { GapicServiceConfig serviceConfig = serviceConfigOpt.get(); serviceConfig.setLroRetrySettings(lroRetrySettingsOpt); @@ -171,7 +171,7 @@ public static GapicContext parse(CodeGeneratorRequest request) { Function typeNameFn = r -> r.resourceTypeString().substring(r.resourceTypeString().indexOf("/") + 1); Function, Set> typeStringSetFn = - sr -> sr.stream().map(r -> typeNameFn.apply(r)).collect(Collectors.toSet()); + sr -> sr.stream().map(typeNameFn).collect(Collectors.toSet()); // Include all resource names present in message types for backwards-compatibility with the // monolith. In the future, this should be removed on a client library major semver update. @@ -202,9 +202,9 @@ public static GapicContext parse(CodeGeneratorRequest request) { .setMessages(messages) .setResourceNames(resourceNames) .setHelperResourceNames(outputArgResourceNames) - .setServiceConfig(serviceConfigOpt.isPresent() ? serviceConfigOpt.get() : null) + .setServiceConfig(serviceConfigOpt.orElse(null)) .setGapicMetadataEnabled(willGenerateMetadata) - .setServiceYamlProto(serviceYamlProtoOpt.isPresent() ? serviceYamlProtoOpt.get() : null) + .setServiceYamlProto(serviceYamlProtoOpt.orElse(null)) .setTransport(transport) .build(); } @@ -533,7 +533,7 @@ public static Map parseMessages( private static Map parseMessages( Descriptor messageDescriptor, Set outputResourceReferencesSeen) { - return parseMessages(messageDescriptor, outputResourceReferencesSeen, new ArrayList()); + return parseMessages(messageDescriptor, outputResourceReferencesSeen, new ArrayList<>()); } private static Map parseMessages( @@ -829,7 +829,7 @@ static String parsePageSizeFieldName( @VisibleForTesting static String sanitizeDefaultHost(String rawDefaultHost) { - if (rawDefaultHost.indexOf(COLON) >= 0) { + if (rawDefaultHost.contains(COLON)) { // A port is already present, just return the existing string. return rawDefaultHost; } From 1000e0bb7f2cb84bcf7e03f95f38444af69e77b4 Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Mon, 20 Sep 2021 11:45:26 -0400 Subject: [PATCH 3/3] minor cleanups --- .../com/google/api/generator/gapic/protoparser/Parser.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java b/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java index 9c4c916033..8fd376b7e0 100644 --- a/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java +++ b/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java @@ -128,9 +128,7 @@ public static GapicContext parse(CodeGeneratorRequest request) { Optional serviceYamlConfigPathOpt = PluginArgumentParser.parseServiceYamlConfigPath(request); Optional serviceYamlProtoOpt = - serviceYamlConfigPathOpt.isPresent() - ? ServiceYamlParser.parse(serviceYamlConfigPathOpt.get()) - : Optional.empty(); + serviceYamlConfigPathOpt.flatMap(ServiceYamlParser::parse); // Collect the resource references seen in messages. Set outputResourceReferencesSeen = new HashSet<>();