List<String> (@NotNull YAMLPsiElement target) { SmartList<String> result = new SmartList<>(); PsiElement element = target; while (element != null) { String elementIndexSuffix = ""; if (element instanceof YAMLSequenceItem) { elementIndexSuffix = "[" + ((YAMLSequenceItem)element).getItemIndex() + "]"; element = PsiTreeUtil.getParentOfType(element, YAMLKeyValue.class); } if (element instanceof YAMLKeyValue) { String keyText = ((YAMLKeyValue)element).getKeyText(); result.add(keyText + elementIndexSuffix); } element = PsiTreeUtil.getParentOfType(element, YAMLKeyValue.class, YAMLSequenceItem.class); } return ContainerUtil.reverse(result); }