From aa3c348bbb1ef786e2900f5cf0173ff6cd6cead9 Mon Sep 17 00:00:00 2001 From: Mira Leung Date: Fri, 9 Oct 2020 20:22:37 -0700 Subject: [PATCH] [ggj][engx] fix: use StringObjectValue for AnnotationNode's description (#389) * fix: support LRO package.name annotations * feat: add microgenerator rules for cloud/asset * fix: update CircleCI * fix: sort message fields in asc. index order * feat: add cloud/redis microgenerator rules * fix: linter * fix: update parser test method sig order * fix: update circleci config * fix: linter * fix: consoliate findRepeatedField into Message * fix: use StringObjectValue for AnnotationNode's description --- .../api/generator/engine/ast/AnnotationNode.java | 10 ++++++++-- .../api/generator/engine/writer/JavaWriterVisitor.java | 6 ++++-- .../composer/ServiceStubSettingsClassComposer.java | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java b/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java index e7b9e05d2f..a7c69d8729 100644 --- a/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java +++ b/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java @@ -34,7 +34,7 @@ private static TypeNode annotationType(Class clazz) { // TODO(unsupported): Any args that do not consist of a single string. However, this can easily be // extended to enable such support. @Nullable - public abstract String description(); + public abstract Expr descriptionExpr(); @Override public void accept(AstNodeVisitor visitor) { @@ -60,7 +60,13 @@ public static Builder builder() { public abstract static class Builder { public abstract Builder setType(TypeNode type); - public abstract Builder setDescription(String description); + public Builder setDescription(String description) { + return setDescriptionExpr(ValueExpr.withValue(StringObjectValue.withValue(description))); + } + + // This will never be anything other than a ValueExpr-wrapped StringObjectValue because + // this setter is private, and called only by setDescription above. + abstract Builder setDescriptionExpr(Expr descriptionExpr); abstract AnnotationNode autoBuild(); diff --git a/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java b/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java index 37df689d00..c3e238a085 100644 --- a/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java +++ b/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java @@ -170,8 +170,10 @@ public void visit(ScopeNode scope) { public void visit(AnnotationNode annotation) { buffer.append(AT); annotation.type().accept(this); - if (annotation.description() != null && !annotation.description().isEmpty()) { - buffer.append(String.format("(\"%s\")", annotation.description())); + if (annotation.descriptionExpr() != null) { + leftParen(); + annotation.descriptionExpr().accept(this); + rightParen(); } newline(); } diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java index 1eb5c7e714..2b35fcf842 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java @@ -354,6 +354,7 @@ private static List createPagingStaticAssignExprs( String.format( "No method found for message type %s for method %s among %s", pagedResponseMessageKey, method.name(), messageTypes.keySet())); + Field repeatedPagedResultsField = pagedResponseMessage.findAndUnwrapFirstRepeatedField(); Preconditions.checkNotNull( repeatedPagedResultsField,