@Override
    protected Edge map(final Traverser.Admin<S> traverser) {
        Object literalOrVar = this.parameters.get(traverser, T.label, () -> GValue.of(null, Edge.DEFAULT_LABEL)).get(0);
        final GValue<String> edgeLabel = literalOrVar instanceof String ?
                GValue.ofString(null, (String) literalOrVar) :
                (GValue<String>) literalOrVar;

        final Object theTo;
        try {
            theTo = this.parameters.get(traverser, TO, traverser::get).get(0);
        } catch (IllegalArgumentException e) { // as thrown by TraversalUtil.apply()
            throw new IllegalStateException(String.format(
                    "addE(%s) failed because the to() traversal (which should give a Vertex) failed with: %s",
                    edgeLabel, e.getMessage()));
        }

        if (!GValue.instanceOf(theTo, GType.VERTEX))
            throw new IllegalStateException(String.format(
                    "The value given to addE(%s).to() must resolve to a Vertex but %s was specified instead", edgeLabel,
                    null == theTo ? "null" : theTo.getClass().getSimpleName()));

        final Object theFrom;
        try {
            theFrom  = this.parameters.get(traverser, FROM, traverser::get).get(0);
        } catch (IllegalArgumentException e) { // as thrown by TraversalUtil.apply()
            throw new IllegalStateException(String.format(
                    "addE(%s) failed because the from() traversal (which should give a Vertex) failed with: %s",
                    edgeLabel, e.getMessage()));
        }

        if (!GValue.instanceOf(theFrom, GType.VERTEX))
            throw new IllegalStateException(String.format(
                    "The value given to addE(%s).to() must resolve to a Vertex but %s was specified instead", edgeLabel,
                    null == theFrom ? "null" : theFrom.getClass().getSimpleName()));

        Vertex toVertex = GValue.getFrom(theTo);
        Vertex fromVertex = GValue.getFrom(theFrom);

        if (toVertex instanceof Attachable)
            toVertex = ((Attachable<Vertex>) toVertex)
                    .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance())));
        if (fromVertex instanceof Attachable)
            fromVertex = ((Attachable<Vertex>) fromVertex)
                    .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance())));

        final Edge edge = fromVertex.addEdge(edgeLabel.get(), toVertex, this.parameters.getKeyValues(traverser, TO, FROM, T.label));
        EventUtil.registerEdgeCreation(callbackRegistry, getTraversal(), edge);
        return edge;
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
@author Stephen Mallette (http://stephen.genoprime.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java