Skip to content

Commit

Permalink
chore: simplify logic (#870)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Eltsufin <meltsufin@google.com>
  • Loading branch information
chanseokoh and meltsufin authored Nov 11, 2021
1 parent e306027 commit d1bb7bd
Showing 1 changed file with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,20 @@ static Expr createDefaultValueResourceHelper(
resourceName = findParentResource(resourceName, resnames).orElse(resourceName);
}

boolean hasOnePattern = resourceName.patterns().size() == 1;
if (resourceName.isOnlyWildcard()) {
List<ResourceName> unexaminedResnames = new ArrayList<>(resnames);
for (ResourceName resname : resnames) {
if (resname.isOnlyWildcard()) {
unexaminedResnames.remove(resname);
continue;
}
unexaminedResnames.remove(resname);
return createDefaultValue(resname, false, unexaminedResnames, fieldOrMessageName);
if (!resname.isOnlyWildcard()) {
return createDefaultValue(resname, false, unexaminedResnames, fieldOrMessageName);
}
}

if (unexaminedResnames.isEmpty()) {
return allowAnonResourceNameClass
? createAnonymousResourceNameClass(fieldOrMessageName)
: ValueExpr.withValue(
StringObjectValue.withValue(
String.format("%s%s", fieldOrMessageName, fieldOrMessageName.hashCode())));
}
return allowAnonResourceNameClass
? createAnonymousResourceNameClass(fieldOrMessageName)
: ValueExpr.withValue(
StringObjectValue.withValue(
String.format("%s%s", fieldOrMessageName, fieldOrMessageName.hashCode())));
}

// The cost tradeoffs of new ctors versus distinct() don't really matter here, since this list
Expand All @@ -261,6 +256,7 @@ static Expr createDefaultValueResourceHelper(
}
}

boolean hasOnePattern = resourceName.patterns().size() == 1;
if (!hasOnePattern) {
ofMethodName =
String.format(
Expand Down

0 comments on commit d1bb7bd

Please sign in to comment.