YAMLKeyValue (@NotNull String keyName, @NotNull String valueText) { final PsiFile tempValueFile = createDummyYamlWithText(valueText); Collection<YAMLValue> values = PsiTreeUtil.collectElementsOfType(tempValueFile, YAMLValue.class); String text; if (!values.isEmpty() && values.iterator().next() instanceof YAMLScalar && !valueText.contains("\n")) { text = keyName + ": " + valueText; } else { text = keyName + ":\n" + YAMLTextUtil.indentText(valueText, 2); } final PsiFile tempFile = createDummyYamlWithText(text); return PsiTreeUtil.collectElementsOfType(tempFile, YAMLKeyValue.class).iterator().next(); }