Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ggj][codegen][test] fix: ensure all testgen methods throw Exceptions #407

Merged
merged 12 commits into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;

Expand Down Expand Up @@ -45,6 +46,10 @@ public static Builder builder() {
public abstract static class Builder {
public abstract Builder setType(TypeNode type);

public Builder setMethods(MethodDefinition... methods) {
return setMethods(Arrays.asList(methods));
}

public abstract Builder setMethods(List<MethodDefinition> methods);

public abstract Builder setStatements(List<Statement> statements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -210,7 +211,11 @@ public abstract static class Builder {

public abstract Builder setWildcardUpperBound(Reference reference);

public abstract Builder setGenerics(List<Reference> clazzes);
public Builder setGenerics(Reference... references) {
return setGenerics(Arrays.asList(references));
}

public abstract Builder setGenerics(List<Reference> references);

public abstract Builder setIsStaticImport(boolean isStaticImport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ public boolean isPrimitiveType() {
return isPrimitiveType(typeKind());
}

public boolean isProtoPrimitiveType() {
return isPrimitiveType() || this.equals(TypeNode.STRING);
}

public boolean isSupertypeOrEquals(TypeNode other) {
boolean oneTypeIsNull = this.equals(TypeNode.NULL) ^ other.equals(TypeNode.NULL);
return !isPrimitiveType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.auto.value.AutoValue;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -146,6 +147,10 @@ public abstract static class Builder {

public abstract Builder setUseFullName(boolean useFullName);

public Builder setGenerics(Reference... references) {
return setGenerics(Arrays.asList(references));
}

public abstract Builder setGenerics(List<Reference> clazzes);

public abstract Builder setEnclosingClassName(String enclosingClassName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.api.generator.engine.ast.StringObjectValue;
import com.google.api.generator.engine.ast.TypeNode;
import com.google.api.generator.engine.ast.ValueExpr;
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.model.Field;
import com.google.api.generator.gapic.model.Message;
Expand All @@ -32,6 +33,7 @@
import com.google.common.base.Preconditions;
import com.google.longrunning.Operation;
import com.google.protobuf.Any;
import com.google.protobuf.ByteString;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -44,6 +46,8 @@ public class DefaultValueComposer {
private static TypeNode OPERATION_TYPE =
TypeNode.withReference(ConcreteReference.withClazz(Operation.class));
private static TypeNode ANY_TYPE = TypeNode.withReference(ConcreteReference.withClazz(Any.class));
private static TypeNode BYTESTRING_TYPE =
TypeNode.withReference(ConcreteReference.withClazz(ByteString.class));

static Expr createDefaultValue(
MethodArgument methodArg, Map<String, ResourceName> resourceNames) {
Expand Down Expand Up @@ -122,6 +126,13 @@ static Expr createDefaultValue(Field f) {
PrimitiveValue.builder().setType(f.type()).setValue("true").build());
}

if (f.type().equals(BYTESTRING_TYPE)) {
return VariableExpr.builder()
.setStaticReferenceType(BYTESTRING_TYPE)
.setVariable(Variable.builder().setName("EMPTY").setType(BYTESTRING_TYPE).build())
.build();
}

throw new UnsupportedOperationException(
String.format(
"Default value for field %s with type %s not implemented yet.", f.name(), f.type()));
Expand Down Expand Up @@ -283,7 +294,8 @@ static Expr createSimpleOperationBuilderExpr(String name, VariableExpr responseE
.build();
}

static Expr createSimplePagedResponse(TypeNode responseType, Expr responseElementVarExpr) {
static Expr createSimplePagedResponse(
TypeNode responseType, String repeatedFieldName, Expr responseElementVarExpr) {
Expr pagedResponseExpr =
MethodInvocationExpr.builder()
.setStaticReferenceType(responseType)
Expand All @@ -298,7 +310,7 @@ static Expr createSimplePagedResponse(TypeNode responseType, Expr responseElemen
pagedResponseExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(pagedResponseExpr)
.setMethodName("addAllResponses")
.setMethodName(String.format("addAll%s", JavaStyle.toUpperCamelCase(repeatedFieldName)))
.setArguments(
MethodInvocationExpr.builder()
.setStaticReferenceType(
Expand Down
Loading