Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
kunli2 committed Nov 16, 2023
1 parent ee5d12d commit 6ca9663
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2972,15 +2972,7 @@ public J visitStringTemplateExpression(KtStringTemplateExpression expression, Ex
Arrays.stream(entries).forEach(entry -> valueSb.append(maybeAdjustCRLF(entry))
);

PsiElement openQuote = expression.getFirstChild();
PsiElement closingQuota = expression.getLastChild();
if (openQuote == null || closingQuota == null ||
openQuote.getNode().getElementType() != KtTokens.OPEN_QUOTE ||
closingQuota.getNode().getElementType() != KtTokens.CLOSING_QUOTE) {
throw new UnsupportedOperationException("This should never happen");
}

String valueSource = openQuote.getText() + valueSb + closingQuota.getText();
String valueSource = getString(expression, valueSb);

return new J.Literal(
randomId(),
Expand All @@ -2993,6 +2985,19 @@ public J visitStringTemplateExpression(KtStringTemplateExpression expression, Ex
).withPrefix(deepPrefix(expression));
}

@NotNull
private static String getString(KtStringTemplateExpression expression, StringBuilder valueSb) {
PsiElement openQuote = expression.getFirstChild();
PsiElement closingQuota = expression.getLastChild();
if (openQuote == null || closingQuota == null ||
openQuote.getNode().getElementType() != KtTokens.OPEN_QUOTE ||
closingQuota.getNode().getElementType() != KtTokens.CLOSING_QUOTE) {
throw new UnsupportedOperationException("This should never happen");
}

return openQuote.getText() + valueSb + closingQuota.getText();
}

@Override
public J visitStringTemplateEntry(KtStringTemplateEntry entry, ExecutionContext data) {
PsiElement leaf = entry.getFirstChild();
Expand Down

0 comments on commit 6ca9663

Please sign in to comment.