int (PsiFragment fragment) { final PsiElement parent = fragment.getParent(); if (!(parent instanceof PsiTemplate)) { return -1; } final PsiTemplate template = (PsiTemplate)parent; Integer cache = template.getUserData(FRAGMENT_INDENT_KEY); if (cache != null) { return cache; } final StringBuilder sb = new StringBuilder(); for (PsiFragment templateFragment : template.getFragments()) { sb.append(templateFragment.getText()); } final String[] lines = PsiLiteralUtil.getTextBlockLines(sb.toString()); if (lines == null) { return -1; } int indent = PsiLiteralUtil.getTextBlockIndent(lines); fragment.putUserData(FRAGMENT_INDENT_KEY, indent); return indent; }