void (@NotNull YAMLKeyValue key) { final int indent = YAMLUtil.getIndentToThisElement(this); ASTNode node = getNode(); ASTNode place = node.getLastChildNode(); ASTNode whereInsert = null; while(place != null) { if(place.getElementType() == YAMLTokenTypes.INDENT && place.getTextLength() == indent) { whereInsert = place; } else if (place.getElementType() == YAMLTokenTypes.EOL) { ASTNode next = place.getTreeNext(); if (next == null || next.getElementType() == YAMLTokenTypes.EOL) { whereInsert = place; } } else { break; } place = place.getTreePrev(); } final YAMLElementGenerator generator = YAMLElementGenerator.getInstance(getProject()); if (whereInsert == null) { add(generator.createEol()); add(generator.createIndent(indent)); add(key); return; } PsiElement anchor = whereInsert.getPsi(); if (indent == 0 || whereInsert.getElementType() == YAMLTokenTypes.INDENT && getLastChild().getTextLength() == indent) { addAfter(key, anchor); return; } if (whereInsert.getElementType() != YAMLTokenTypes.EOL) { anchor = addAfter(generator.createEol(), anchor); } addAfter(generator.createIndent(indent), anchor); addAfter(key, anchor); }