@Override public void apply(final Traversal<?, ?> traversal, final TraversalEngine engine) { TraversalHelper.getStepsOfClass(LocalRangeStep.class, traversal) .forEach( localRangeStep -> { Step previousStep = localRangeStep.getPreviousStep(); while (!previousStep.equals(EmptyStep.instance()) && !(previousStep instanceof PropertiesStep) && !(previousStep instanceof VertexStep)) { previousStep = previousStep.getPreviousStep(); // TODO: check for not filtering/sideEffect steps and throw an exception? } if (previousStep instanceof VertexStep) { VertexStep vertexStep = (VertexStep) previousStep; if (vertexStep.getReturnClass().equals(Edge.class)) { localRangeStep.setDirection(vertexStep.getDirection()); } else { throw new IllegalStateException( "LocalRangeStep must follow a VertexStep that produces edges, not vertices"); } } else if (previousStep instanceof PropertiesStep) { // do nothing, all is good } else { throw new IllegalStateException( "LocalRangeStep must follow a VertexStep or PropertiesStep"); } }); }