Skip to content

Y_Update PlaceholderParser.java #34021

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

Closed
wants to merge 1 commit into from
Closed
Changes from all 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 @@ -443,34 +443,30 @@ record SimplePlaceholderPart(String text, String key, @Nullable String fallback)

@Override
public String resolve(PartResolutionContext resolutionContext) {
String resolvedValue = resolveToText(resolutionContext, this.key);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert all the formatting change as it makes it harder for us to see what you've changed.

if (resolvedValue != null) {
return resolvedValue;
}
else if (this.fallback != null) {
return this.fallback;
}
return resolutionContext.handleUnresolvablePlaceholder(this.key, this.text);
String resolvedKey = Part.resolveAll(this.keyParts, resolutionContext);
String value = resolveToText(resolutionContext, resolvedKey);
if (value != null) {
return value;
} else if (this.defaultParts != null) {
return Part.resolveAll(this.defaultParts, resolutionContext);
}
return resolutionContext.handleUnresolvablePlaceholder(resolvedKey, this.text);
}

@Nullable

private String resolveToText(PartResolutionContext resolutionContext, String text) {
String resolvedValue = resolutionContext.resolvePlaceholder(text);
if (resolvedValue != null) {
resolutionContext.flagPlaceholderAsVisited(text);
// Let's check if we need to recursively resolve that value
List<Part> nestedParts = resolutionContext.parse(resolvedValue);
String value = toText(nestedParts);
if (!isTextOnly(nestedParts)) {
value = new ParsedValue(resolvedValue, nestedParts).resolve(resolutionContext);
}
resolutionContext.removePlaceholder(text);
return value;
}
// Not found
return null;
String resolvedValue = resolutionContext.resolvePlaceholder(text);
if (resolvedValue != null) {
resolutionContext.flagPlaceholderAsVisited(text);
// Check for nested placeholders
List<Part> nestedParts = resolutionContext.parse(resolvedValue);
String value = Part.resolveAll(nestedParts, resolutionContext);
resolutionContext.removePlaceholder(text);
return value;
}
return null;
}


private boolean isTextOnly(List<Part> parts) {
return parts.stream().allMatch(TextPart.class::isInstance);
}
Expand Down