@Override
  public @Nullable TemplateImpl substituteTemplate(@NotNull TemplateSubstitutionContext substitutionContext,
                                                   @NotNull TemplateImpl template) {
    PsiFile file = substitutionContext.getPsiFile();
    if (file.getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
      PsiElement element = file.findElementAt(substitutionContext.getOffset());
      PsiElement prevLeaf = element == null ? null : PsiTreeUtil.prevCodeLeaf(element);
      if (PsiUtil.isJavaToken(prevLeaf, JavaTokenType.ARROW)) {
        boolean inSwitch = prevLeaf.getParent() instanceof PsiSwitchLabeledRuleStatement;
        String text = template.getString();
        try {
          PsiStatement statement = JavaPsiFacade.getElementFactory(substitutionContext.getProject()).createStatementFromText(text, null);
          String resultText;
          if (inSwitch && (statement instanceof PsiExpressionStatement || statement instanceof PsiThrowStatement)) {
            resultText = text;
          }
          else if (statement instanceof PsiExpressionStatement) {
            resultText = ((PsiExpressionStatement)statement).getExpression().getText();
          }
          else {
            resultText = "{" + text + "}";
          }
          TemplateImpl copy = template.copy();
          copy.setString(resultText);
          return copy;
        }
        catch (IncorrectOperationException ignored) {
        }
      }
    }
    return null;
  }
@Override
  public @Nullable TemplateImpl substituteTemplate(@NotNull TemplateSubstitutionContext substitutionContext,
                                                   @NotNull TemplateImpl template)