Collection<StructureViewTreeElement> (@Nullable YAMLPsiElement element, @Nullable String path) { if (element == null) { return Collections.emptyList(); } Ref<Collection<StructureViewTreeElement>> result = Ref.create(Collections.emptyList()); element.accept(new YamlPsiElementVisitor() { @Override public void visitSequence(@NotNull YAMLSequence sequence) { result.set(ContainerUtil.map(sequence.getItems(), i -> path == null ? new YAMLStructureViewSequenceItemOriginal(i) : new YAMLStructureViewSequenceItemDuplicated(i, path))); } @Override public void visitMapping(@NotNull YAMLMapping mapping) { result.set(ContainerUtil.map(mapping.getKeyValues(), kv -> path == null ? new YAMLStructureViewKeyValueOriginal(kv) : new YAMLStructureViewKeyValueDuplicated(kv, path))); } }); return result.get(); }