Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c71f061
feat: add factory var decl in ServiceStubSettings codegen
miraleung Aug 25, 2020
4919bba
fix: prevent duplicate MethodDefinition annotations
miraleung Aug 25, 2020
b77848e
feat: add descriptor fields to ServiceStubSettings codegen
miraleung Aug 25, 2020
861f142
feat: add starter Builder to ServiceStubSettings codegen
miraleung Aug 25, 2020
5f285df
feat: add settings.builder decls to ServiceStubSettings codegen
miraleung Aug 25, 2020
dbc5735
feat: add first nested ctors to ServiceStubSettings codegen
miraleung Aug 26, 2020
164c0b3
feat: add GapicServiceConfig DS and processing
miraleung Aug 26, 2020
3783203
feat: integrate GapicServiceConfig into GapicContext, Parser, Composer
miraleung Aug 26, 2020
3984eaa
feat: initial param block, RetrySettingsComposer, test
miraleung Aug 26, 2020
a0ef19e
fix!: refactor GapicRetrySettings
miraleung Aug 27, 2020
74dbcbb
fix: recognize 1. or .1 double patterns
miraleung Aug 27, 2020
34285db
feat: support BlockStatement in ClassDef stmts
miraleung Aug 27, 2020
2fc9d0e
feat: add params block to ServiceStubSettings codegen
miraleung Aug 27, 2020
f6727d8
feat: add codes def to ServiceStubSettings codegen
miraleung Aug 27, 2020
1c54ec1
feat: add initDefaults() to ServiceStubSettings codegen
miraleung Aug 27, 2020
c50a204
feat: add LRO to ServiceStubSettings.Builder.initDefaults
miraleung Aug 27, 2020
106528f
feat: add third ServiceStubSettings.Builder(settings) ctor
miraleung Aug 27, 2020
6858b33
feat: add createDefault() to ServiceStubSettings
miraleung Aug 27, 2020
0df98cb
feat: add ServiceStubSettings.applyToAllUnaryMethods method
miraleung Aug 27, 2020
5919b29
feat: add ServiceStubSettings.unaryMethodSettingsBuilders()
miraleung Aug 27, 2020
0e03f06
feat: add ServiceStubSettings.build()
miraleung Aug 27, 2020
f172ad1
feat: add settingsBuilder getters in ServiceStubSettings
miraleung Aug 27, 2020
de8ab3b
feat: add gapic.yaml batching parsing
miraleung Aug 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dependencies.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ maven.com_google_auto_value_auto_value=com.google.auto.value:auto-value:1.7.2
maven.com_google_auto_value_auto_value_annotations=com.google.auto.value:auto-value-annotations:1.7.2
maven.com_google_protobuf_protobuf_java=com.google.protobuf:protobuf-java:3.12.2

# ServiceStubSettings class.
# Gapic YAML parsing for batching settings.
maven.org_yaml_snakeyaml=org.yaml:snakeyaml:1.26

# ServiceStubSettings class. Used only in generated code.
maven.org_threeten_threetenbp=org.threeten:threetenbp:1.3.3

# Testing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,26 @@ public ClassDefinition build() {
for (Statement statement : classDef.statements()) {
// TODO(xiaozhenliu): Add CommentStatement check here.
Preconditions.checkState(
statement instanceof ExprStatement,
"Class statement type must be either an expression or comment statement");
Expr expr = ((ExprStatement) statement).expression();
if (expr instanceof VariableExpr) {
VariableExpr variableExpr = (VariableExpr) expr;
Preconditions.checkState(
variableExpr.isDecl(), "Class expression variable statements must be declarations");
Preconditions.checkState(
!variableExpr.scope().equals(ScopeNode.LOCAL),
"Class variable statement cannot have a local scope");
} else {
Preconditions.checkState(
expr instanceof AssignmentExpr,
"Class expression statement must be assignment or variable declaration");
VariableExpr variableExpr = ((AssignmentExpr) expr).variableExpr();
Preconditions.checkState(
!variableExpr.scope().equals(ScopeNode.LOCAL),
"Class variable in assignment statement cannot have a local scope");
statement instanceof ExprStatement || statement instanceof BlockStatement,
"Class statement type must be either an expression, block, or comment statement");
if (statement instanceof ExprStatement) {
Expr expr = ((ExprStatement) statement).expression();
if (expr instanceof VariableExpr) {
VariableExpr variableExpr = (VariableExpr) expr;
Preconditions.checkState(
variableExpr.isDecl(), "Class expression variable statements must be declarations");
Preconditions.checkState(
!variableExpr.scope().equals(ScopeNode.LOCAL),
"Class variable statement cannot have a local scope");
} else {
Preconditions.checkState(
expr instanceof AssignmentExpr,
"Class expression statement must be assignment or variable declaration");
VariableExpr variableExpr = ((AssignmentExpr) expr).variableExpr();
Preconditions.checkState(
!variableExpr.scope().equals(ScopeNode.LOCAL),
"Class variable in assignment statement cannot have a local scope");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -122,10 +123,7 @@ public abstract static class Builder {
public abstract Builder setHeaderCommentStatements(
List<CommentStatement> headeCommentStatements);

public Builder setAnnotations(List<AnnotationNode> annotations) {
annotationsBuilder().addAll(annotations);
return this;
}
public abstract Builder setAnnotations(List<AnnotationNode> annotations);

public abstract Builder setIsStatic(boolean isStatic);

Expand Down Expand Up @@ -162,10 +160,10 @@ public Builder setArguments(VariableExpr... arguments) {

// Private accessors.

abstract ImmutableList.Builder<AnnotationNode> annotationsBuilder();

abstract String name();

abstract ImmutableList<AnnotationNode> annotations();

abstract TypeNode returnType();

abstract boolean isOverride();
Expand Down Expand Up @@ -231,9 +229,19 @@ public MethodDefinition build() {
}

// If this method overrides another, ensure that the Override annotaiton is the last one.
ImmutableList<AnnotationNode> processedAnnotations = annotations();
if (isOverride()) {
annotationsBuilder().add(AnnotationNode.OVERRIDE);
processedAnnotations =
annotations()
.<AnnotationNode>builder()
.addAll(annotations())
.add(AnnotationNode.OVERRIDE)
.build();
}
// Remove duplicates while maintaining insertion order.
setAnnotations(
new LinkedHashSet<AnnotationNode>(processedAnnotations)
.stream().collect(Collectors.toList()));

MethodDefinition method = autoBuild();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public class Literal {
private static final Pattern LONG_PATTERN = Pattern.compile("^[0-9]+[Ll]?$");
private static final Pattern FLOAT_PATTERN =
Pattern.compile("^[0-9]+([fF]|(\\.(([0-9]+[fF])|[fF])))?$");
private static final Pattern DOUBLE_PATTERN =
private static final Pattern DOUBLE_PATTERN_ONE =
Pattern.compile("^[0-9]+(\\.[0-9]+)?(\\.?[eE]\\-?[0-9]+)$");
private static final Pattern DOUBLE_PATTERN_TWO = Pattern.compile("^\\d*\\.\\d+$|^\\d+\\.\\d*$");

public static boolean isBooleanLiteral(String str) {
return str.equals(BOOLEAN_TRUE) || str.equals(BOOLEAN_FALSE);
Expand All @@ -46,7 +47,9 @@ public static boolean isFloatLiteral(String str) {
}

public static boolean isDoubleLiteral(String str) {
return isFloatLiteral(str) || DOUBLE_PATTERN.matcher(str).matches();
return isFloatLiteral(str)
|| DOUBLE_PATTERN_ONE.matcher(str).matches()
|| DOUBLE_PATTERN_TWO.matcher(str).matches();
}

public static boolean isNullLiteral(String str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ java_library(
deps = [
"//:longrunning_java_proto",
"//:monitored_resource_java_proto",
"//:rpc_java_proto",
"//:service_config_java_proto",
"//src/main/java/com/google/api/generator/engine/ast",
"//src/main/java/com/google/api/generator/gapic:status_java_proto",
Expand All @@ -23,6 +24,8 @@ java_library(
"@com_google_api_gax_java//jar",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_protobuf//:protobuf_java",
"@com_google_protobuf//:protobuf_java_util",
"@com_google_protobuf//java/core",
"@io_grpc_java//api",
"@io_grpc_java//protobuf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
import com.google.api.generator.gapic.model.GapicContext;
import com.google.api.generator.gapic.model.GapicServiceConfig;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.ResourceName;
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.utils.ApacheLicense;
import com.google.common.annotations.VisibleForTesting;
import io.grpc.serviceconfig.ServiceConfig;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -45,7 +45,7 @@ public static List<GapicClass> composeServiceClasses(GapicContext context) {

public static List<GapicClass> generateServiceClasses(
@Nonnull Service service,
@Nullable ServiceConfig serviceConfig,
@Nullable GapicServiceConfig serviceConfig,
@Nonnull Map<String, Message> messageTypes) {
List<GapicClass> clazzes = new ArrayList<>();
clazzes.addAll(generateStubClasses(service, serviceConfig, messageTypes));
Expand All @@ -64,7 +64,7 @@ public static List<GapicClass> generateResourceNameHelperClasses(
}

public static List<GapicClass> generateStubClasses(
Service service, ServiceConfig serviceConfig, Map<String, Message> messageTypes) {
Service service, GapicServiceConfig serviceConfig, Map<String, Message> messageTypes) {
List<GapicClass> clazzes = new ArrayList<>();
clazzes.add(ServiceStubClassComposer.instance().generate(service, messageTypes));
clazzes.add(
Expand Down
Loading