PsiElement (@NotNull YAMLMapping mapping) { final PsiElement parent = mapping.getParent(); if (parent instanceof YAMLDocument) { return parent; } else if (parent instanceof YAMLSequenceItem) { final PsiElement key = parent.getFirstChild(); return key != null ? key : mapping; } else if (parent instanceof YAMLKeyValue) { final PsiElement key = ((YAMLKeyValue)parent).getKey(); return key != null ? key : mapping; } else { return mapping; } }