Skip to content

Commit

Permalink
Merge branch 'master' into renovate/gradle-7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
gcf-merge-on-green[bot] committed May 31, 2021
2 parents 05c8508 + 8f6f40e commit 4149eb5
Show file tree
Hide file tree
Showing 160 changed files with 20,933 additions and 2,358 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ jobs:
echo "The old one will disappear after 7 days."
- name: Unit Tests
run: bazel --batch test $(bazel query "//src/test/..." | grep "Test$") --noshow_progress
run: bazel --batch test $(bazel query "//src/test/..." | grep "Test$") --noshow_progress --test_output=errors

- name: Integration Tests
run: bazel --batch test //test/integration:asset //test/integration:credentials //test/integration:iam //test/integration:kms //test/integration:logging //test/integration:redis //test/integration:library --noshow_progress
run: bazel --batch test //test/integration:asset //test/integration:credentials //test/integration:iam //test/integration:kms //test/integration:logging //test/integration:pubsub //test/integration:redis //test/integration:library --noshow_progress

- uses: actions/upload-artifact@v2
if: ${{ failure() }}
Expand Down
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
# Changelog

### [1.0.10](https://www.github.com/googleapis/gapic-generator-java/compare/v1.0.9...v1.0.10) (2021-05-26)


### Miscellaneous Chores

* Pre-DIREGAPIC refactoring ([04c2faa](https://github.com/googleapis/gapic-generator-java/commit/04c2faa191a9b5a10b92392fe8482279c4404803))

### [1.0.9](https://www.github.com/googleapis/gapic-generator-java/compare/v1.0.8...v1.0.9) (2021-05-26)


### Features

* add AST support for lambdas ([#736](https://www.github.com/googleapis/gapic-generator-java/issues/736)) ([9ced678](https://www.github.com/googleapis/gapic-generator-java/commit/9ced6780c7a6b9934dd548002602618566a539d6))


### Bug Fixes

* Support enums in proto HTTP annotations ([#733](https://www.github.com/googleapis/gapic-generator-java/issues/733)) ([f5c7b86](https://www.github.com/googleapis/gapic-generator-java/commit/f5c7b86b43ad71ffe47d8ba039155db601638e1f))
* Support PubSub's _deleted-topic_ pattern ([#739](https://www.github.com/googleapis/gapic-generator-java/issues/739)) ([7d8c62d](https://www.github.com/googleapis/gapic-generator-java/commit/7d8c62d8e8922a3589e631299ecb0287bc41ba2d))


### [1.0.8](https://www.github.com/googleapis/gapic-generator-java/compare/v1.0.7...v1.0.8) (2021-05-24)


### Miscellaneous Chores

* DIREGAPIC refactoring ([ae17e7e](https://github.com/googleapis/gapic-generator-java/commit/ae17e7e9a272b422176962d896e387496b1806e8))

### [1.0.7](https://www.github.com/googleapis/gapic-generator-java/compare/v1.0.6...v1.0.7) (2021-05-21)


### Bug Fixes

* Add PubSub to service.yaml / mixin allowlist ([#729](https://www.github.com/googleapis/gapic-generator-java/issues/729)) ([e7f6d33](https://www.github.com/googleapis/gapic-generator-java/commit/e7f6d33051e335504b05c402d3b98c387a9f0daf))


### [1.0.6](https://www.github.com/googleapis/gapic-generator-java/compare/v1.0.5...v1.0.6) (2021-05-19)


### Bug Fixes

* **mixins:** Gate mixin RPC on HTTP rules, add yaml doc/http overrides ([#727](https://www.github.com/googleapis/gapic-generator-java/issues/727)) ([229da5d](https://www.github.com/googleapis/gapic-generator-java/commit/229da5d94cf7db060abf3ea006a20d1ade804597))

### [1.0.5](https://www.github.com/googleapis/gapic-generator-java/compare/v1.0.4...v1.0.5) (2021-05-17)


### Bug Fixes

* **types:** Reorder nested types for legacy protos w/ java_outer_class in one file ([#724](https://www.github.com/googleapis/gapic-generator-java/issues/724)) ([925356d](https://www.github.com/googleapis/gapic-generator-java/commit/925356d659aed4b8550ce526f1772a706661c246))

### [1.0.4](https://www.github.com/googleapis/gapic-generator-java/compare/v1.0.3...v1.0.4) (2021-05-13)


Expand Down
3 changes: 1 addition & 2 deletions dependencies.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ version.com_google_protobuf=3.13.0
# Version of google-java-format is downgraded from 1.8 to 1.7, because 1.8 supports java 11 minimum, while our JRE is java 8.
version.google_java_format=1.7
version.com_google_api_common_java=1.9.3
# TODO(miraleung): Update this.
version.com_google_gax_java=1.62.0
version.io_grpc_java=1.30.2

# Common deps.
maven.com_google_guava_guava=com.google.guava:guava:26.0-jre
maven.com_google_guava_guava=com.google.guava:guava:30.1-android
maven.com_google_code_findbugs_jsr305=com.google.code.findbugs:jsr305:3.0.0
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
Expand Down
2 changes: 1 addition & 1 deletion rules_java_gapic/java_gapic.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

load("@com_google_api_codegen//rules_gapic:gapic.bzl", "proto_custom_library", "unzipped_srcjar")

SERVICE_YAML_ALLOWLIST = ["clouddms", "cloudkms", "datastream"]
SERVICE_YAML_ALLOWLIST = ["clouddms", "cloudkms", "datastream", "pubsub"]
NO_GRPC_CONFIG_ALLOWLIST = ["library"]

def _java_gapic_postprocess_srcjar_impl(ctx):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public interface AstNodeVisitor {

public void visit(AssignmentOperationExpr assignmentOperationExpr);

public void visit(LambdaExpr lambdaExpr);

/** =============================== COMMENT =============================== */
public void visit(LineComment lineComment);

Expand Down
115 changes: 115 additions & 0 deletions src/main/java/com/google/api/generator/engine/ast/LambdaExpr.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.generator.engine.ast;

import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@AutoValue
public abstract class LambdaExpr implements Expr {
@Override
public TypeNode type() {
// TODO(v2): Support set of FunctionalInterface parameterized on the args and return type,
// which would enable assignment to an appropriate variable.
return TypeNode.VOID;
}

public abstract ImmutableList<VariableExpr> arguments();

public abstract ReturnExpr returnExpr();

public abstract ImmutableList<Statement> body();

@Override
public void accept(AstNodeVisitor visitor) {
visitor.visit(this);
}

public static Builder builder() {
return new AutoValue_LambdaExpr.Builder()
.setArguments(Collections.emptyList())
.setBody(Collections.emptyList());
}

@AutoValue.Builder
public abstract static class Builder {
public Builder setArguments(VariableExpr... arguments) {
return setArguments(Arrays.asList(arguments));
}

public abstract Builder setArguments(List<VariableExpr> arguments);

public abstract Builder setBody(List<Statement> body);

public abstract Builder setReturnExpr(ReturnExpr returnExpr);

public Builder setReturnExpr(Expr expr) {
return setReturnExpr(ReturnExpr.builder().setExpr(expr).build());
}

public abstract LambdaExpr autoBuild();

public LambdaExpr build() {
LambdaExpr lambdaExpr = autoBuild();
Preconditions.checkState(
!lambdaExpr.returnExpr().expr().type().equals(TypeNode.VOID),
"Lambdas cannot return void-typed expressions.");
// Must be a declaration.
lambdaExpr.arguments().stream()
.forEach(
varExpr ->
Preconditions.checkState(
varExpr.isDecl(),
String.format(
"Argument %s must be a variable declaration",
varExpr.variable().identifier())));
// No modifiers allowed.
lambdaExpr.arguments().stream()
.forEach(
varExpr ->
Preconditions.checkState(
varExpr.scope().equals(ScopeNode.LOCAL)
&& !varExpr.isStatic()
&& !varExpr.isFinal()
&& !varExpr.isVolatile(),
String.format(
"Argument %s must have local scope, and cannot have static, final, or"
+ " volatile modifiers",
varExpr.variable().identifier())));

// Check that there aren't any arguments with duplicate names.
List<String> allArgNames =
lambdaExpr.arguments().stream()
.map(v -> v.variable().identifier().name())
.collect(Collectors.toList());
Set<String> duplicateArgNames =
allArgNames.stream()
.filter(n -> Collections.frequency(allArgNames, n) > 1)
.collect(Collectors.toSet());
Preconditions.checkState(
duplicateArgNames.isEmpty(),
String.format(
"Lambda arguments cannot have duplicate names: %s", duplicateArgNames.toString()));

return lambdaExpr;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -169,6 +170,8 @@ public Builder setReturnExpr(Expr expr) {
// Private accessors.
abstract String name();

abstract ImmutableList<VariableExpr> arguments();

abstract ImmutableList<CommentStatement> headerCommentStatements();

abstract ImmutableList<AnnotationNode> annotations();
Expand Down Expand Up @@ -314,28 +317,66 @@ public MethodDefinition build() {
}
}

for (VariableExpr varExpr : method.arguments()) {
Preconditions.checkState(
varExpr.isDecl(),
String.format(
"Argument %s must be a variable declaration", varExpr.variable().identifier()));
}

for (TypeNode exceptionType : method.throwsExceptions()) {
Preconditions.checkState(
TypeNode.isExceptionType(exceptionType),
String.format("Type %s is not an exception type", exceptionType.reference()));
Preconditions.checkState(
!RUNTIME_EXCEPTION_REFERENCE.isAssignableFrom(exceptionType.reference()),
String.format(
"RuntimeException type %s does not need to be thrown",
exceptionType.reference().name()));
}
performArgumentChecks();
performThrownExceptionChecks();

return method;
}

void performNullChecks() {
private void performArgumentChecks() {
// Must be a declaration.
arguments().stream()
.forEach(
varExpr ->
Preconditions.checkState(
varExpr.isDecl(),
String.format(
"Argument %s must be a variable declaration",
varExpr.variable().identifier())));
// No modifiers allowed.
arguments().stream()
.forEach(
varExpr ->
Preconditions.checkState(
varExpr.scope().equals(ScopeNode.LOCAL)
&& !varExpr.isStatic()
&& !varExpr.isVolatile(),
String.format(
"Argument %s must have local scope, and cannot have \"static\" or"
+ " \"volatile\" modifiers",
varExpr.variable().identifier())));

// Check that there aren't any arguments with duplicate names.
List<String> allArgNames =
arguments().stream()
.map(v -> v.variable().identifier().name())
.collect(Collectors.toList());
Set<String> duplicateArgNames =
allArgNames.stream()
.filter(n -> Collections.frequency(allArgNames, n) > 1)
.collect(Collectors.toSet());
Preconditions.checkState(
duplicateArgNames.isEmpty(),
String.format(
"Lambda arguments cannot have duplicate names: %s", duplicateArgNames.toString()));
}

private void performThrownExceptionChecks() {
throwsExceptions().stream()
.forEach(
exceptionType -> {
Preconditions.checkState(
TypeNode.isExceptionType(exceptionType),
String.format("Type %s is not an exception type", exceptionType.reference()));
Preconditions.checkState(
!RUNTIME_EXCEPTION_REFERENCE.isAssignableFrom(exceptionType.reference()),
String.format(
"RuntimeException type %s does not need to be thrown",
exceptionType.reference().name()));
});
}

private void performNullChecks() {
String contextInfo = String.format("method definition of %s", name());
NodeValidator.checkNoNullElements(headerCommentStatements(), "header comments", contextInfo);
NodeValidator.checkNoNullElements(annotations(), "annotations", contextInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public interface Reference extends AstNode {

boolean useFullName();

// The nested types in left-to-right order, if any.
// Example: com.google.Foo.Bar.Car.ThisType will have the outer types listed in the order
// [Foo, Bar, Car].
@Nullable
ImmutableList<String> enclosingClassNames();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.api.generator.engine.ast.IfStatement;
import com.google.api.generator.engine.ast.InstanceofExpr;
import com.google.api.generator.engine.ast.JavaDocComment;
import com.google.api.generator.engine.ast.LambdaExpr;
import com.google.api.generator.engine.ast.LineComment;
import com.google.api.generator.engine.ast.LogicalOperationExpr;
import com.google.api.generator.engine.ast.MethodDefinition;
Expand Down Expand Up @@ -292,6 +293,13 @@ public void visit(AssignmentOperationExpr assignmentOperationExpr) {
assignmentOperationExpr.valueExpr().accept(this);
}

@Override
public void visit(LambdaExpr lambdaExpr) {
variableExpressions(lambdaExpr.arguments());
statements(lambdaExpr.body());
lambdaExpr.returnExpr().accept(this);
}

/** =============================== STATEMENTS =============================== */
@Override
public void visit(ExprStatement exprStatement) {
Expand Down
Loading

0 comments on commit 4149eb5

Please sign in to comment.