Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into diregapic_1
Browse files Browse the repository at this point in the history
  • Loading branch information
vam-google committed May 18, 2021
2 parents e81d781 + 83e2e3b commit a537c93
Show file tree
Hide file tree
Showing 21 changed files with 174 additions and 89 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,20 @@
# Changelog

### [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)


### Bug Fixes

* **types:** Use fully-qualified message type names ([#723](https://www.github.com/googleapis/gapic-generator-java/issues/723)) ([8a5c36c](https://www.github.com/googleapis/gapic-generator-java/commit/8a5c36ccce7540940ec7a4bf8751971c3741d89d))
* Use the right composers in deprecation unit tests ([#715](https://www.github.com/googleapis/gapic-generator-java/issues/715)) ([2318136](https://www.github.com/googleapis/gapic-generator-java/commit/2318136e49060c3212abfd6337e2c3ceb2c2fc69))

### [1.0.3](https://www.github.com/googleapis/gapic-generator-java/compare/v1.0.2...v1.0.3) (2021-04-07)


Expand Down
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
Expand Up @@ -106,7 +106,7 @@ public static Expr createBatchingDescriptorFieldDeclExpr(

private static MethodDefinition createGetBatchPartitionKeyMethod(
Method method, GapicBatchingSettings batchingSettings, Map<String, Message> messageTypes) {
String methodInputTypeName = method.inputType().reference().name();
String methodInputTypeName = method.inputType().reference().fullName();
Message inputMessage = messageTypes.get(methodInputTypeName);
Preconditions.checkNotNull(
inputMessage,
Expand Down Expand Up @@ -283,7 +283,7 @@ private static MethodDefinition createSplitResponseMethod(

List<Statement> outerForBody = new ArrayList<>();
if (hasSubresponseField) {
Message outputMessage = messageTypes.get(method.outputType().reference().name());
Message outputMessage = messageTypes.get(method.outputType().reference().fullName());
Preconditions.checkNotNull(
outputMessage, String.format("Output message not found for RPC %s", method.name()));

Expand Down
Expand Up @@ -1041,7 +1041,7 @@ private static List<ClassDefinition> createNestedPagingClasses(
continue;
}
// Find the repeated field.
Message methodOutputMessage = messageTypes.get(method.outputType().reference().simpleName());
Message methodOutputMessage = messageTypes.get(method.outputType().reference().fullName());
Field repeatedPagedResultsField = methodOutputMessage.findAndUnwrapFirstRepeatedField();
Preconditions.checkNotNull(
repeatedPagedResultsField,
Expand Down Expand Up @@ -1657,7 +1657,6 @@ private static TypeStore createTypes(Service service, Map<String, Message> messa
TimeUnit.class,
UnaryCallable.class);
TypeStore typeStore = new TypeStore(concreteClazzes);
typeStore.putMessageTypes(service.pakkage(), messageTypes);
createVaporTypes(service, typeStore);
return typeStore;
}
Expand Down
Expand Up @@ -546,7 +546,7 @@ private static MethodDefinition createRpcTestMethod(
VariableExpr responsesElementVarExpr = null;
String mockServiceVarName = getMockServiceVarName(rpcService);
if (method.isPaged()) {
Message methodOutputMessage = messageTypes.get(method.outputType().reference().simpleName());
Message methodOutputMessage = messageTypes.get(method.outputType().reference().fullName());
Field repeatedPagedResultsField = methodOutputMessage.findAndUnwrapFirstRepeatedField();
Preconditions.checkNotNull(
repeatedPagedResultsField,
Expand Down Expand Up @@ -577,7 +577,7 @@ private static MethodDefinition createRpcTestMethod(
Variable.builder().setType(methodOutputType).setName("expectedResponse").build());
Expr expectedResponseValExpr = null;
if (method.isPaged()) {
Message methodOutputMessage = messageTypes.get(method.outputType().reference().simpleName());
Message methodOutputMessage = messageTypes.get(method.outputType().reference().fullName());
Field firstRepeatedField = methodOutputMessage.findAndUnwrapFirstRepeatedField();
Preconditions.checkNotNull(
firstRepeatedField,
Expand All @@ -589,10 +589,10 @@ private static MethodDefinition createRpcTestMethod(
DefaultValueComposer.createSimplePagedResponse(
method.outputType(), firstRepeatedField.name(), responsesElementVarExpr);
} else {
if (messageTypes.containsKey(methodOutputType.reference().name())) {
if (messageTypes.containsKey(methodOutputType.reference().fullName())) {
expectedResponseValExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
messageTypes.get(methodOutputType.reference().simpleName()),
messageTypes.get(methodOutputType.reference().fullName()),
resourceNames,
messageTypes);
} else {
Expand Down Expand Up @@ -658,7 +658,7 @@ private static MethodDefinition createRpcTestMethod(
VariableExpr.withVariable(
Variable.builder().setType(method.inputType()).setName("request").build());
argExprs.add(requestVarExpr);
requestMessage = messageTypes.get(method.inputType().reference().simpleName());
requestMessage = messageTypes.get(method.inputType().reference().fullName());
Preconditions.checkNotNull(requestMessage);
Expr valExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
Expand Down Expand Up @@ -784,7 +784,7 @@ private static MethodDefinition createRpcTestMethod(
.build());

// Assert the responses are equivalent.
Message methodOutputMessage = messageTypes.get(method.outputType().reference().simpleName());
Message methodOutputMessage = messageTypes.get(method.outputType().reference().fullName());
Field repeatedPagedResultsField = methodOutputMessage.findAndUnwrapFirstRepeatedField();
Preconditions.checkNotNull(
repeatedPagedResultsField,
Expand Down Expand Up @@ -1022,10 +1022,10 @@ private static MethodDefinition createStreamingRpcTestMethod(
VariableExpr.withVariable(
Variable.builder().setType(methodOutputType).setName("expectedResponse").build());
Expr expectedResponseValExpr = null;
if (messageTypes.containsKey(methodOutputType.reference().name())) {
if (messageTypes.containsKey(methodOutputType.reference().fullName())) {
expectedResponseValExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
messageTypes.get(methodOutputType.reference().simpleName()),
messageTypes.get(methodOutputType.reference().fullName()),
resourceNames,
messageTypes);
} else {
Expand Down Expand Up @@ -1080,7 +1080,7 @@ private static MethodDefinition createStreamingRpcTestMethod(
VariableExpr requestVarExpr =
VariableExpr.withVariable(
Variable.builder().setType(method.inputType()).setName("request").build());
Message requestMessage = messageTypes.get(method.inputType().reference().simpleName());
Message requestMessage = messageTypes.get(method.inputType().reference().fullName());
Preconditions.checkNotNull(requestMessage);
Expr valExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
Expand Down Expand Up @@ -1363,7 +1363,7 @@ private static List<Statement> createStreamingRpcExceptionTestStatements(
VariableExpr requestVarExpr =
VariableExpr.withVariable(
Variable.builder().setType(method.inputType()).setName("request").build());
Message requestMessage = messageTypes.get(method.inputType().reference().simpleName());
Message requestMessage = messageTypes.get(method.inputType().reference().fullName());
Preconditions.checkNotNull(requestMessage);
Expr valExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
Expand Down Expand Up @@ -1552,7 +1552,7 @@ private static List<Statement> createRpcExceptionTestStatements(
VariableExpr.withVariable(
Variable.builder().setType(method.inputType()).setName("request").build());
argVarExprs.add(varExpr);
Message requestMessage = messageTypes.get(method.inputType().reference().simpleName());
Message requestMessage = messageTypes.get(method.inputType().reference().fullName());
Preconditions.checkNotNull(requestMessage);
Expr valExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
Expand Down
Expand Up @@ -248,7 +248,6 @@ private static TypeStore createTypes(Service service, Map<String, Message> messa
UnaryCallable.class,
UnsupportedOperationException.class);
TypeStore typeStore = new TypeStore(concreteClazzes);
typeStore.putMessageTypes(service.pakkage(), messageTypes);

typeStore.put("com.google.longrunning.stub", "OperationsStub");

Expand Down
Expand Up @@ -389,11 +389,9 @@ private static List<Expr> createPagingStaticAssignExprs(
}

// Find the repeated type.
String pagedResponseMessageKey =
JavaStyle.toUpperCamelCase(method.outputType().reference().simpleName());
String pagedResponseMessageKey = method.outputType().reference().fullName();
if (method.hasLro()) {
pagedResponseMessageKey =
JavaStyle.toUpperCamelCase(method.lro().responseType().reference().simpleName());
pagedResponseMessageKey = method.lro().responseType().reference().fullName();
}
Message pagedResponseMessage = messageTypes.get(pagedResponseMessageKey);
Preconditions.checkNotNull(
Expand Down
Expand Up @@ -236,7 +236,7 @@ public static Expr createSimpleMessageBuilderExpr(
if (field.isContainedInOneof() // Avoid colliding fields.
|| ((field.isMessage() || field.isEnum()) // Avoid importing unparsed messages.
&& !field.isRepeated()
&& !messageTypes.containsKey(field.type().reference().name()))) {
&& !messageTypes.containsKey(field.type().reference().fullName()))) {
continue;
}
String setterMethodNamePattern = "set%s";
Expand Down
Expand Up @@ -290,11 +290,11 @@ public static String composeRpcDefaultMethodHeaderSampleCode(
VariableExpr.withVariable(
Variable.builder().setName("request").setType(method.inputType()).build());
List<VariableExpr> rpcMethodArgVarExprs = Arrays.asList(requestVarExpr);
Message requestMessage = messageTypes.get(method.inputType().reference().simpleName());
Message requestMessage = messageTypes.get(method.inputType().reference().fullName());
Preconditions.checkNotNull(
requestMessage,
String.format(
"Could not find the message type %s.", method.inputType().reference().simpleName()));
"Could not find the message type %s.", method.inputType().reference().fullName()));
Expr requestBuilderExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
requestMessage, resourceNames, messageTypes);
Expand Down Expand Up @@ -346,11 +346,11 @@ public static String composeLroCallableMethodHeaderSampleCode(
VariableExpr requestVarExpr =
VariableExpr.withVariable(
Variable.builder().setName("request").setType(method.inputType()).build());
Message requestMessage = messageTypes.get(method.inputType().reference().simpleName());
Message requestMessage = messageTypes.get(method.inputType().reference().fullName());
Preconditions.checkNotNull(
requestMessage,
String.format(
"Could not find the message type %s.", method.inputType().reference().simpleName()));
"Could not find the message type %s.", method.inputType().reference().fullName()));
Expr requestBuilderExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
requestMessage, resourceNames, messageTypes);
Expand Down Expand Up @@ -458,11 +458,11 @@ public static String composePagedCallableMethodHeaderSampleCode(
VariableExpr requestVarExpr =
VariableExpr.withVariable(
Variable.builder().setName("request").setType(method.inputType()).build());
Message requestMessage = messageTypes.get(method.inputType().reference().simpleName());
Message requestMessage = messageTypes.get(method.inputType().reference().fullName());
Preconditions.checkNotNull(
requestMessage,
String.format(
"Could not find the message type %s.", method.inputType().reference().simpleName()));
"Could not find the message type %s.", method.inputType().reference().fullName()));
Expr requestBuilderExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
requestMessage, resourceNames, messageTypes);
Expand All @@ -476,7 +476,7 @@ public static String composePagedCallableMethodHeaderSampleCode(
bodyExprs.add(requestAssignmentExpr);

// Find the repeated field.
Message methodOutputMessage = messageTypes.get(method.outputType().reference().simpleName());
Message methodOutputMessage = messageTypes.get(method.outputType().reference().fullName());
Field repeatedPagedResultsField = methodOutputMessage.findAndUnwrapFirstRepeatedField();
Preconditions.checkNotNull(
repeatedPagedResultsField,
Expand Down Expand Up @@ -578,11 +578,11 @@ public static String composeRegularCallableMethodHeaderSampleCode(
VariableExpr requestVarExpr =
VariableExpr.withVariable(
Variable.builder().setName("request").setType(method.inputType()).build());
Message requestMessage = messageTypes.get(method.inputType().reference().simpleName());
Message requestMessage = messageTypes.get(method.inputType().reference().fullName());
Preconditions.checkNotNull(
requestMessage,
String.format(
"Could not find the message type %s.", method.inputType().reference().simpleName()));
"Could not find the message type %s.", method.inputType().reference().fullName()));
Expr requestBuilderExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
requestMessage, resourceNames, messageTypes);
Expand Down Expand Up @@ -626,11 +626,11 @@ public static String composeStreamCallableMethodHeaderSampleCode(
VariableExpr requestVarExpr =
VariableExpr.withVariable(
Variable.builder().setName("request").setType(method.inputType()).build());
Message requestMessage = messageTypes.get(method.inputType().reference().simpleName());
Message requestMessage = messageTypes.get(method.inputType().reference().fullName());
Preconditions.checkNotNull(
requestMessage,
String.format(
"Could not find the message type %s.", method.inputType().reference().simpleName()));
"Could not find the message type %s.", method.inputType().reference().fullName()));
Expr requestBuilderExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
requestMessage, resourceNames, messageTypes);
Expand Down Expand Up @@ -702,7 +702,12 @@ private static List<Statement> composeUnaryPagedRpcMethodBodyStatements(
Map<String, Message> messageTypes) {

// Find the repeated field.
Message methodOutputMessage = messageTypes.get(method.outputType().reference().simpleName());
Message methodOutputMessage = messageTypes.get(method.outputType().reference().fullName());
Preconditions.checkNotNull(
methodOutputMessage,
"Output message %s not found, keys: ",
method.outputType().reference().fullName(),
messageTypes.keySet().toString());
Field repeatedPagedResultsField = methodOutputMessage.findAndUnwrapFirstRepeatedField();
Preconditions.checkNotNull(
repeatedPagedResultsField,
Expand Down Expand Up @@ -1128,7 +1133,7 @@ private static List<Statement> composePagedCallableBodyStatements(
VariableExpr requestVarExpr,
Map<String, Message> messageTypes) {
// Find the repeated field.
Message methodOutputMessage = messageTypes.get(method.outputType().reference().simpleName());
Message methodOutputMessage = messageTypes.get(method.outputType().reference().fullName());
Field repeatedPagedResultsField = methodOutputMessage.findAndUnwrapFirstRepeatedField();
Preconditions.checkNotNull(
repeatedPagedResultsField,
Expand Down
Expand Up @@ -30,6 +30,11 @@
public abstract class Message {
public abstract String name();

// The fully-qualified proto name, which differs from the Java fully-qualified name.
// For example, this would be google.showcase.v1beta1.EchoRequest for echo.proto (see testdata),
// whereas that message's Java fully-qualified name is com.google.showcase.v1beta1.EchoRequest.
public abstract String fullProtoName();

// TODO(unsupported): oneof fields are parsed as separate ones because field flattening refers to
// a specific field.
public abstract ImmutableList<Field> fields();
Expand Down Expand Up @@ -88,6 +93,8 @@ public static Builder builder() {
public abstract static class Builder {
public abstract Builder setName(String name);

public abstract Builder setFullProtoName(String fullProtoName);

public abstract Builder setFields(List<Field> fields);

public Builder setEnumValues(List<String> names, List<Integer> numbers) {
Expand Down
Expand Up @@ -74,7 +74,7 @@ public static Optional<List<String>> parseHttpBindings(
String subField = descendantBindings[i];
if (i < descendantBindings.length - 1) {
Field field = containingMessage.fieldMap().get(subField);
containingMessage = messageTypes.get(field.type().reference().simpleName());
containingMessage = messageTypes.get(field.type().reference().fullName());
Preconditions.checkNotNull(
containingMessage,
String.format(
Expand Down
Expand Up @@ -57,7 +57,7 @@ public static List<List<MethodArgument>> parseMethodSignatures(

Map<String, ResourceName> patternsToResourceNames =
ResourceParserHelpers.createPatternResourceNameMap(resourceNames);
Message inputMessage = messageTypes.get(methodInputType.reference().simpleName());
Message inputMessage = messageTypes.get(methodInputType.reference().fullName());

// Example from Expand in echo.proto:
// stringSigs: ["content,error", "content,error,info"].
Expand Down Expand Up @@ -266,7 +266,7 @@ private static Map<TypeNode, Field> parseTypeFromArgumentName(
TypeNode.isReferenceType(firstFieldType) && !firstFieldType.equals(TypeNode.STRING),
String.format("Field reference on %s cannot be a primitive type", firstFieldName));

String firstFieldTypeName = firstFieldType.reference().name();
String firstFieldTypeName = firstFieldType.reference().fullName();
Message firstFieldMessage = messageTypes.get(firstFieldTypeName);
Preconditions.checkNotNull(
firstFieldMessage,
Expand Down

0 comments on commit a537c93

Please sign in to comment.