public static Set<String> getReferencedLabelsAfterStep(Step<?, ?> step) {
        final Set<String> labels = new HashSet<>();
        while (!(step instanceof EmptyStep)) {
            labels.addAll(PathUtil.getReferencedLabels(step));
            step = step.getNextStep();
        }
        return labels;
    }
@author Ted Wilmes (http://twilmes.org)
@author Stephen Mallette (http://stephen.genoprime.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/PathUtil.java