Skip to content

Commit

Permalink
fix: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
miraleung committed May 13, 2021
1 parent 836a45f commit 13c92e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,24 +643,26 @@ static LongrunningOperation parseLro(
// These can be short names (e.g. FooMessage) or fully-qualified names with the *proto* package.
String responseTypeName = lroInfo.getResponseType();
String metadataTypeName = lroInfo.getMetadataType();
String[] responseTypeNameComponents = responseTypeName.split("\\.");
String[] metadataTypeNameComponents = metadataTypeName.split("\\.");

int lastDotIndex = responseTypeName.lastIndexOf('.');
boolean isResponseTypeNameShortOnly = lastDotIndex < 0;
String responseTypeShortName =
responseTypeNameComponents[responseTypeNameComponents.length - 1];
String metadataTypeShortName =
metadataTypeNameComponents[metadataTypeNameComponents.length - 1];
lastDotIndex >= 0 ? responseTypeName.substring(lastDotIndex + 1) : responseTypeName;

// True if the LRO-specified name is the short name.
boolean isResponseTypeNameShortOnly = responseTypeName.equals(responseTypeShortName);
boolean isMetadataTypeNameShortOnly = metadataTypeName.equals(metadataTypeShortName);
lastDotIndex = metadataTypeName.lastIndexOf('.');
boolean isMetadataTypeNameShortOnly = lastDotIndex < 0;
String metadataTypeShortName =
lastDotIndex >= 0 ? metadataTypeName.substring(lastDotIndex + 1) : metadataTypeName;

Message responseMessage = null;
Message metadataMessage = null;

// The messageTypes map keys to the Java fully-qualified name.
for (Map.Entry<String, Message> messageEntry : messageTypes.entrySet()) {
String[] packageComponents = messageEntry.getKey().split("\\.");
String messageShortName = packageComponents[packageComponents.length - 1];
String messageKey = messageEntry.getKey();
int messageLastDotIndex = messageEntry.getKey().lastIndexOf('.');
String messageShortName =
messageLastDotIndex >= 0 ? messageKey.substring(messageLastDotIndex + 1) : messageKey;
if (responseMessage == null) {
if (isResponseTypeNameShortOnly && responseTypeName.equals(messageShortName)) {
responseMessage = messageEntry.getValue();
Expand Down

0 comments on commit 13c92e1

Please sign in to comment.