Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1278 6338c9a23 -> 8d2de3f6a
added support for lambda embedding by using the native lambda functionality of the host language. It supplies a String of the translated language lambda. Removed ScriptXXXTraversal model as after discussion on the ticket, it seems that that model is not as good as the CreationStrategy model. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/8d2de3f6 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/8d2de3f6 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/8d2de3f6 Branch: refs/heads/TINKERPOP-1278 Commit: 8d2de3f6aa6dbf11a715ab79bd53823d04e2849c Parents: 6338c9a Author: Marko A. Rodriguez <okramma...@gmail.com> Authored: Wed Jun 15 16:11:14 2016 -0600 Committer: Marko A. Rodriguez <okramma...@gmail.com> Committed: Wed Jun 15 16:11:14 2016 -0600 ---------------------------------------------------------------------- .../dsl/graph/script/ScriptGraphTraversal.java | 957 ------------------- .../script/ScriptGraphTraversalSource.java | 239 ----- .../process/traversal/util/Translator.java | 9 - .../tinkerpop/gremlin/structure/Graph.java | 3 - .../script/ScriptGraphTraversalSourceTest.java | 60 -- .../graph/script/ScriptGraphTraversalTest.java | 59 -- .../jython/gremlin_python/gremlin_python.py | 2 - .../jython/gremlin_python/groovy_translator.py | 6 + 8 files changed, 6 insertions(+), 1329 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8d2de3f6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversal.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversal.java deleted file mode 100644 index 16bac30..0000000 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversal.java +++ /dev/null @@ -1,957 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.script; - -import org.apache.tinkerpop.gremlin.process.computer.VertexProgram; -import org.apache.tinkerpop.gremlin.process.traversal.Order; -import org.apache.tinkerpop.gremlin.process.traversal.P; -import org.apache.tinkerpop.gremlin.process.traversal.Path; -import org.apache.tinkerpop.gremlin.process.traversal.Pop; -import org.apache.tinkerpop.gremlin.process.traversal.Scope; -import org.apache.tinkerpop.gremlin.process.traversal.Traversal; -import org.apache.tinkerpop.gremlin.process.traversal.Traverser; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; -import org.apache.tinkerpop.gremlin.process.traversal.util.Translator; -import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep; -import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree; -import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet; -import org.apache.tinkerpop.gremlin.structure.Column; -import org.apache.tinkerpop.gremlin.structure.Direction; -import org.apache.tinkerpop.gremlin.structure.Edge; -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.Property; -import org.apache.tinkerpop.gremlin.structure.T; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.apache.tinkerpop.gremlin.structure.VertexProperty; -import org.apache.tinkerpop.gremlin.util.ScriptEngineCache; - -import javax.script.Bindings; -import javax.script.ScriptEngine; -import javax.script.SimpleBindings; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; - -/** - * @author Marko A. Rodriguez (http://markorodriguez.com) - */ -public class ScriptGraphTraversal<S, E> extends DefaultGraphTraversal<S, E> { - - protected Translator translator; - - public ScriptGraphTraversal(final Graph graph, final Translator translator) { - super(graph); - this.translator = translator; - } - - public String getTraversalScript() { - return this.translator.getTraversalScript(); - } - - @Override - public void applyStrategies() { - if (!(this.getParent() instanceof EmptyStep)) { - return; - } - try { - final String traversalScriptString = this.getTraversalScript(); - __.setAnonymousTraversalFunction(null); - ScriptEngine engine = ScriptEngineCache.get(this.translator.getScriptEngine()); - final Bindings bindings = new SimpleBindings(); - bindings.put(this.translator.getAlias(), new GraphTraversalSource(this.getGraph().get(), this.getStrategies())); - Traversal.Admin<S, E> traversal = (Traversal.Admin<S, E>) engine.eval(traversalScriptString, bindings); - assert !traversal.isLocked(); - this.sideEffects = traversal.getSideEffects(); - this.strategies = traversal.getStrategies(); - traversal.getSteps().forEach(step -> this.addStep(step)); - super.applyStrategies(); - } catch (final Exception e) { - throw new IllegalArgumentException(e.getMessage(), e); - } - } - - private static String getMethodName() { - return Thread.currentThread().getStackTrace()[2].getMethodName(); - } - - ////////////////////////// - - public <E2> GraphTraversal<S, E2> map(final Function<Traverser<E>, E2> function) { - this.translator.addStep(getMethodName(), function); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> map(final Traversal<?, E2> mapTraversal) { - this.translator.addStep(getMethodName(), mapTraversal); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> flatMap(final Function<Traverser<E>, Iterator<E2>> function) { - this.translator.addStep(getMethodName(), function); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> flatMap(final Traversal<?, E2> flatMapTraversal) { - this.translator.addStep(getMethodName(), flatMapTraversal); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Object> id() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, String> label() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> identity() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> constant(final E2 e) { - this.translator.addStep(getMethodName(), e); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Vertex> V(final Object... vertexIdsOrElements) { - this.translator.addStep(getMethodName(), vertexIdsOrElements); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Vertex> to(final Direction direction, final String... edgeLabels) { - this.translator.addStep(getMethodName(), direction, edgeLabels); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Vertex> out(final String... edgeLabels) { - this.translator.addStep(getMethodName(), edgeLabels); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Vertex> in(final String... edgeLabels) { - this.translator.addStep(getMethodName(), edgeLabels); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Vertex> both(final String... edgeLabels) { - this.translator.addStep(getMethodName(), edgeLabels); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Edge> toE(final Direction direction, final String... edgeLabels) { - this.translator.addStep(getMethodName(), direction, edgeLabels); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Edge> outE(final String... edgeLabels) { - this.translator.addStep(getMethodName(), edgeLabels); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Edge> inE(final String... edgeLabels) { - this.translator.addStep(getMethodName(), edgeLabels); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Edge> bothE(final String... edgeLabels) { - this.translator.addStep(getMethodName(), edgeLabels); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Vertex> toV(final Direction direction) { - this.translator.addStep(getMethodName(), direction); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Vertex> inV() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Vertex> outV() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Vertex> bothV() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Vertex> otherV() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> order() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> order(final Scope scope) { - this.translator.addStep(getMethodName(), scope); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, ? extends Property<E2>> properties(final String... propertyKeys) { - this.translator.addStep(getMethodName(), propertyKeys); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> values(final String... propertyKeys) { - this.translator.addStep(getMethodName(), propertyKeys); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, Map<String, E2>> propertyMap(final String... propertyKeys) { - this.translator.addStep(getMethodName(), propertyKeys); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, Map<String, E2>> valueMap(final String... propertyKeys) { - this.translator.addStep(getMethodName(), propertyKeys); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, Map<String, E2>> valueMap(final boolean includeTokens, final String... propertyKeys) { - this.translator.addStep(getMethodName(), includeTokens, propertyKeys); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, Collection<E2>> select(final Column column) { - this.translator.addStep(getMethodName(), column); - return (GraphTraversal) this; - } - - @Deprecated - public <E2> GraphTraversal<S, E2> mapValues() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - @Deprecated - public <E2> GraphTraversal<S, E2> mapKeys() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, String> key() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> value() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Path> path() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, Map<String, E2>> match(final Traversal<?, ?>... matchTraversals) { - this.translator.addStep(getMethodName(), matchTraversals); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> sack() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Integer> loops() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, Map<String, E2>> project(final String projectKey, final String... otherProjectKeys) { - this.translator.addStep(getMethodName(), projectKey, otherProjectKeys); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, Map<String, E2>> select(final Pop pop, final String selectKey1, final String selectKey2, String... otherSelectKeys) { - this.translator.addStep(getMethodName(), pop, selectKey1, selectKey2, otherSelectKeys); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, Map<String, E2>> select(final String selectKey1, final String selectKey2, String... otherSelectKeys) { - this.translator.addStep(getMethodName(), selectKey1, selectKey2, otherSelectKeys); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> select(final Pop pop, final String selectKey) { - this.translator.addStep(getMethodName(), pop, selectKey); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> select(final String selectKey) { - this.translator.addStep(getMethodName(), selectKey); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> unfold() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, List<E>> fold() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> fold(final E2 seed, final BiFunction<E2, E, E2> foldFunction) { - this.translator.addStep(getMethodName(), seed, foldFunction); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Long> count() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Long> count(final Scope scope) { - this.translator.addStep(getMethodName(), scope); - return (GraphTraversal) this; - } - - public <E2 extends Number> GraphTraversal<S, E2> sum() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public <E2 extends Number> GraphTraversal<S, E2> sum(final Scope scope) { - this.translator.addStep(getMethodName(), scope); - return (GraphTraversal) this; - } - - public <E2 extends Number> GraphTraversal<S, E2> max() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public <E2 extends Number> GraphTraversal<S, E2> max(final Scope scope) { - this.translator.addStep(getMethodName(), scope); - return (GraphTraversal) this; - } - - public <E2 extends Number> GraphTraversal<S, E2> min() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public <E2 extends Number> GraphTraversal<S, E2> min(final Scope scope) { - this.translator.addStep(getMethodName(), scope); - return (GraphTraversal) this; - } - - public <E2 extends Number> GraphTraversal<S, E2> mean() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public <E2 extends Number> GraphTraversal<S, E2> mean(final Scope scope) { - this.translator.addStep(getMethodName(), scope); - return (GraphTraversal) this; - } - - public <K, V> GraphTraversal<S, Map<K, V>> group() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - @Deprecated - public <K, V> GraphTraversal<S, Map<K, V>> groupV3d0() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public <K> GraphTraversal<S, Map<K, Long>> groupCount() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Tree> tree() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Vertex> addV(final String vertexLabel) { - this.translator.addStep(getMethodName(), vertexLabel); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Vertex> addV() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - @Deprecated - public GraphTraversal<S, Vertex> addV(final Object... propertyKeyValues) { - this.translator.addStep(getMethodName(), propertyKeyValues); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Edge> addE(final String edgeLabel) { - this.translator.addStep(getMethodName(), edgeLabel); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> to(final String toStepLabel) { - this.translator.addStep(getMethodName(), toStepLabel); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> from(final String fromStepLabel) { - this.translator.addStep(getMethodName(), fromStepLabel); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> to(final Traversal<E, Vertex> toVertex) { - this.translator.addStep(getMethodName(), toVertex); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> from(final Traversal<E, Vertex> fromVertex) { - this.translator.addStep(getMethodName(), fromVertex); - return (GraphTraversal) this; - } - - @Deprecated - public GraphTraversal<S, Edge> addE(final Direction direction, final String firstVertexKeyOrEdgeLabel, final String edgeLabelOrSecondVertexKey, final Object... propertyKeyValues) { - this.translator.addStep(getMethodName(), direction, firstVertexKeyOrEdgeLabel, edgeLabelOrSecondVertexKey, propertyKeyValues); - return (GraphTraversal) this; - } - - @Deprecated - public GraphTraversal<S, Edge> addOutE(final String firstVertexKeyOrEdgeLabel, final String edgeLabelOrSecondVertexKey, final Object... propertyKeyValues) { - this.translator.addStep(getMethodName(), firstVertexKeyOrEdgeLabel, edgeLabelOrSecondVertexKey, propertyKeyValues); - return (GraphTraversal) this; - } - - @Deprecated - public GraphTraversal<S, Edge> addInE(final String firstVertexKeyOrEdgeLabel, final String edgeLabelOrSecondVertexKey, final Object... propertyKeyValues) { - this.translator.addStep(getMethodName(), firstVertexKeyOrEdgeLabel, edgeLabelOrSecondVertexKey, propertyKeyValues); - return (GraphTraversal) this; - } - - ///////////////////// FILTER STEPS ///////////////////// - - public GraphTraversal<S, E> filter(final Predicate<Traverser<E>> predicate) { - this.translator.addStep(getMethodName(), predicate); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> filter(final Traversal<?, ?> filterTraversal) { - this.translator.addStep(getMethodName(), filterTraversal); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> or(final Traversal<?, ?>... orTraversals) { - this.translator.addStep(getMethodName(), orTraversals); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> and(final Traversal<?, ?>... andTraversals) { - this.translator.addStep(getMethodName(), andTraversals); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> inject(final E... injections) { - this.translator.addStep(getMethodName(), injections); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> dedup(final Scope scope, final String... dedupLabels) { - this.translator.addStep(getMethodName(), scope, dedupLabels); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> dedup(final String... dedupLabels) { - this.translator.addStep(getMethodName(), dedupLabels); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> where(final String startKey, final P<String> predicate) { - this.translator.addStep(getMethodName(), startKey, predicate); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> where(final P<String> predicate) { - this.translator.addStep(getMethodName(), predicate); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> where(final Traversal<?, ?> whereTraversal) { - this.translator.addStep(getMethodName(), whereTraversal); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> has(final String propertyKey, final P<?> predicate) { - this.translator.addStep(getMethodName(), propertyKey, predicate); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> has(final T accessor, final P<?> predicate) { - this.translator.addStep(getMethodName(), accessor, predicate); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> has(final String propertyKey, final Object value) { - this.translator.addStep(getMethodName(), propertyKey, value); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> has(final T accessor, final Object value) { - this.translator.addStep(getMethodName(), accessor, value); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> has(final String label, final String propertyKey, final P<?> predicate) { - this.translator.addStep(getMethodName(), label, propertyKey, predicate); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> has(final String label, final String propertyKey, final Object value) { - this.translator.addStep(getMethodName(), label, propertyKey, value); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> has(final T accessor, final Traversal<?, ?> propertyTraversal) { - this.translator.addStep(getMethodName(), accessor, propertyTraversal); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> has(final String propertyKey, final Traversal<?, ?> propertyTraversal) { - this.translator.addStep(getMethodName(), propertyKey, propertyTraversal); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> has(final String propertyKey) { - this.translator.addStep(getMethodName(), propertyKey); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> hasNot(final String propertyKey) { - this.translator.addStep(getMethodName(), propertyKey); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> hasLabel(final String... labels) { - this.translator.addStep(getMethodName(), labels); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> hasId(final Object... ids) { - this.translator.addStep(getMethodName(), ids); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> hasKey(final String... keys) { - this.translator.addStep(getMethodName(), keys); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> hasValue(final Object... values) { - this.translator.addStep(getMethodName(), values); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> is(final P<E> predicate) { - this.translator.addStep(getMethodName(), predicate); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> is(final Object value) { - this.translator.addStep(getMethodName(), value); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> not(final Traversal<?, ?> notTraversal) { - this.translator.addStep(getMethodName(), notTraversal); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> coin(final double probability) { - this.translator.addStep(getMethodName(), probability); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> range(final long low, final long high) { - this.translator.addStep(getMethodName(), low, high); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> range(final Scope scope, final long low, final long high) { - this.translator.addStep(getMethodName(), scope, low, high); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> limit(final long limit) { - this.translator.addStep(getMethodName(), limit); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> limit(final Scope scope, final long limit) { - this.translator.addStep(getMethodName(), scope, limit); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> tail() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> tail(final long limit) { - this.translator.addStep(getMethodName(), limit); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> tail(final Scope scope) { - this.translator.addStep(getMethodName(), scope); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> tail(final Scope scope, final long limit) { - this.translator.addStep(getMethodName(), scope, limit); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> timeLimit(final long timeLimit) { - this.translator.addStep(getMethodName(), timeLimit); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> simplePath() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> cyclicPath() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> sample(final int amountToSample) { - this.translator.addStep(getMethodName(), amountToSample); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> sample(final Scope scope, final int amountToSample) { - this.translator.addStep(getMethodName(), scope, amountToSample); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> drop() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - ///////////////////// SIDE-EFFECT STEPS ///////////////////// - - public GraphTraversal<S, E> sideEffect(final Consumer<Traverser<E>> consumer) { - this.translator.addStep(getMethodName(), consumer); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> sideEffect(final Traversal<?, ?> sideEffectTraversal) { - this.translator.addStep(getMethodName(), sideEffectTraversal); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> cap(final String sideEffectKey, final String... sideEffectKeys) { - this.translator.addStep(getMethodName(), sideEffectKey, sideEffectKeys); - return (GraphTraversal) this; - } - - public GraphTraversal<S, Edge> subgraph(final String sideEffectKey) { - this.translator.addStep(getMethodName(), sideEffectKey); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> aggregate(final String sideEffectKey) { - this.translator.addStep(getMethodName(), sideEffectKey); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> group(final String sideEffectKey) { - this.translator.addStep(getMethodName(), sideEffectKey); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> groupV3d0(final String sideEffectKey) { - this.translator.addStep(getMethodName(), sideEffectKey); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> groupCount(final String sideEffectKey) { - this.translator.addStep(getMethodName(), sideEffectKey); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> tree(final String sideEffectKey) { - this.translator.addStep(getMethodName(), sideEffectKey); - return (GraphTraversal) this; - } - - public <V, U> GraphTraversal<S, E> sack(final BiFunction<V, U, V> sackOperator) { - this.translator.addStep(getMethodName(), sackOperator); - return (GraphTraversal) this; - } - - - @Deprecated - public <V, U> GraphTraversal<S, E> sack(final BiFunction<V, U, V> sackOperator, final String elementPropertyKey) { - this.translator.addStep(getMethodName(), sackOperator, elementPropertyKey); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> store(final String sideEffectKey) { - this.translator.addStep(getMethodName(), sideEffectKey); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> profile(final String sideEffectKey) { - this.translator.addStep(getMethodName(), sideEffectKey); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> property(final VertexProperty.Cardinality cardinality, final Object key, final Object value, final Object... keyValues) { - this.translator.addStep(getMethodName(), cardinality, key, value, keyValues); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> property(final Object key, final Object value, final Object... keyValues) { - this.translator.addStep(getMethodName(), key, value, keyValues); - return (GraphTraversal) this; - } - - ///////////////////// BRANCH STEPS ///////////////////// - - public <M, E2> GraphTraversal<S, E2> branch(final Traversal<?, M> branchTraversal) { - this.translator.addStep(getMethodName(), branchTraversal); - return (GraphTraversal) this; - } - - public <M, E2> GraphTraversal<S, E2> branch(final Function<Traverser<E>, M> function) { - this.translator.addStep(getMethodName(), function); - return (GraphTraversal) this; - } - - public <M, E2> GraphTraversal<S, E2> choose(final Traversal<?, M> choiceTraversal) { - this.translator.addStep(getMethodName(), choiceTraversal); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> choose(final Traversal<?, ?> traversalPredicate, - final Traversal<?, E2> trueChoice, final Traversal<?, E2> falseChoice) { - this.translator.addStep(getMethodName(), traversalPredicate, trueChoice, falseChoice); - return (GraphTraversal) this; - } - - public <M, E2> GraphTraversal<S, E2> choose(final Function<E, M> choiceFunction) { - this.translator.addStep(getMethodName(), choiceFunction); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> choose(final Predicate<E> choosePredicate, - final Traversal<?, E2> trueChoice, final Traversal<?, E2> falseChoice) { - this.translator.addStep(getMethodName(), choosePredicate, trueChoice, falseChoice); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> optional(final Traversal<?, E2> optionalTraversal) { - this.translator.addStep(getMethodName(), optionalTraversal); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> union(final Traversal<?, E2>... unionTraversals) { - this.translator.addStep(getMethodName(), unionTraversals); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> coalesce(final Traversal<?, E2>... coalesceTraversals) { - this.translator.addStep(getMethodName(), coalesceTraversals); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> repeat(final Traversal<?, E> repeatTraversal) { - this.translator.addStep(getMethodName(), repeatTraversal); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> emit(final Traversal<?, ?> emitTraversal) { - this.translator.addStep(getMethodName(), emitTraversal); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> emit(final Predicate<Traverser<E>> emitPredicate) { - this.translator.addStep(getMethodName(), emitPredicate); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> emit() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> until(final Traversal<?, ?> untilTraversal) { - this.translator.addStep(getMethodName(), untilTraversal); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> until(final Predicate<Traverser<E>> untilPredicate) { - this.translator.addStep(getMethodName(), untilPredicate); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> times(final int maxLoops) { - this.translator.addStep(getMethodName(), maxLoops); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E2> local(final Traversal<?, E2> localTraversal) { - this.translator.addStep(getMethodName(), localTraversal); - return (GraphTraversal) this; - } - - /////////////////// VERTEX PROGRAM STEPS //////////////// - - public GraphTraversal<S, E> pageRank() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> pageRank(final double alpha) { - this.translator.addStep(getMethodName(), alpha); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> peerPressure() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> program(final VertexProgram<?> vertexProgram) { - this.translator.addStep(getMethodName(), vertexProgram); - return (GraphTraversal) this; - } - - ///////////////////// UTILITY STEPS ///////////////////// - - public GraphTraversal<S, E> as(final String stepLabel, final String... stepLabels) { - this.translator.addStep(getMethodName(), stepLabel, stepLabels); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> barrier() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> barrier(final int maxBarrierSize) { - this.translator.addStep(getMethodName(), maxBarrierSize); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> barrier(final Consumer<TraverserSet<Object>> barrierConsumer) { - this.translator.addStep(getMethodName(), barrierConsumer); - return (GraphTraversal) this; - } - - - //// BY-MODULATORS - - public GraphTraversal<S, E> by() { - this.translator.addStep(getMethodName()); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> by(final Traversal<?, ?> traversal) { - this.translator.addStep(getMethodName(), traversal); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> by(final T token) { - this.translator.addStep(getMethodName(), token); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> by(final String key) { - this.translator.addStep(getMethodName(), key); - return (GraphTraversal) this; - } - - public <V> GraphTraversal<S, E> by(final Function<V, Object> function) { - this.translator.addStep(getMethodName(), function); - return (GraphTraversal) this; - } - - //// COMPARATOR BY-MODULATORS - - public <V> GraphTraversal<S, E> by(final Traversal<?, ?> traversal, final Comparator<V> comparator) { - this.translator.addStep(getMethodName(), traversal, comparator); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> by(final Comparator<E> comparator) { - this.translator.addStep(getMethodName(), comparator); - return (GraphTraversal) this; - } - - public GraphTraversal<S, E> by(final Order order) { - this.translator.addStep(getMethodName(), order); - return (GraphTraversal) this; - } - - public <V> GraphTraversal<S, E> by(final String key, final Comparator<V> comparator) { - this.translator.addStep(getMethodName(), key, comparator); - return (GraphTraversal) this; - } - - public <U> GraphTraversal<S, E> by(final Function<U, Object> function, final Comparator comparator) { - this.translator.addStep(getMethodName(), function, comparator); - return (GraphTraversal) this; - } - - //// - - public <M, E2> GraphTraversal<S, E> option(final M pickToken, final Traversal<E, E2> traversalOption) { - this.translator.addStep(getMethodName(), pickToken, traversalOption); - return (GraphTraversal) this; - } - - public <E2> GraphTraversal<S, E> option(final Traversal<E, E2> traversalOption) { - this.translator.addStep(getMethodName(), traversalOption); - return (GraphTraversal) this; - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8d2de3f6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversalSource.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversalSource.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversalSource.java deleted file mode 100644 index edb1afe..0000000 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversalSource.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.script; - -import org.apache.tinkerpop.gremlin.process.computer.Computer; -import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; -import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies; -import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; -import org.apache.tinkerpop.gremlin.process.traversal.util.Translator; -import org.apache.tinkerpop.gremlin.structure.Edge; -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.Transaction; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.apache.tinkerpop.gremlin.structure.util.StringFactory; - -import java.util.function.BinaryOperator; -import java.util.function.Supplier; -import java.util.function.UnaryOperator; - -/** - * @author Marko A. Rodriguez (http://markorodriguez.com) - */ -public class ScriptGraphTraversalSource extends GraphTraversalSource { - - private final Translator translator; - - public ScriptGraphTraversalSource(final Graph graph, final TraversalStrategies traversalStrategies, final Translator translator) { - super(graph, traversalStrategies); - this.translator = translator; - } - - public ScriptGraphTraversalSource(final Graph graph, final Translator translator) { - super(graph); - this.translator = translator; - } - - @Override - public TraversalStrategies getStrategies() { - return this.strategies; - } - - @Override - public Graph getGraph() { - return this.graph; - } - - @Override - public GraphTraversalSource clone() { - final ScriptGraphTraversalSource clone = (ScriptGraphTraversalSource) super.clone(); - clone.strategies = this.strategies.clone(); - return clone; - } - - - //// CONFIGURATIONS - - @Override - public GraphTraversalSource withComputer(final Computer computer) { - this.translator.addSource("withComputer", computer); - return this; - } - - @Override - public GraphTraversalSource withComputer(final Class<? extends GraphComputer> graphComputerClass) { - this.translator.addSource("withComputer", graphComputerClass); - return this; - } - - @Override - public GraphTraversalSource withComputer() { - this.translator.addSource("withComputer"); - return this; - } - - @Override - public GraphTraversalSource withStrategies(final TraversalStrategy... traversalStrategies) { - return super.withStrategies(traversalStrategies); - //this.translator.addStep("withStrategies", traversalStrategies); - } - - @Override - @SuppressWarnings({"unchecked", "varargs"}) - public GraphTraversalSource withoutStrategies(final Class<? extends TraversalStrategy>... traversalStrategyClasses) { - this.translator.addSource("withoutStrategies", traversalStrategyClasses); - return this; - } - - @Override - public <A> GraphTraversalSource withSideEffect(final String key, final Supplier<A> initialValue, final BinaryOperator<A> reducer) { - this.translator.addSource("withSideEffect", key, initialValue, reducer); - return this; - } - - @Override - public <A> GraphTraversalSource withSideEffect(final String key, final A initialValue, final BinaryOperator<A> reducer) { - this.translator.addSource("withSideEffect", key, initialValue, reducer); - return this; - } - - @Override - public <A> GraphTraversalSource withSideEffect(final String key, final A initialValue) { - this.translator.addSource("withSideEffect", key, initialValue); - return this; - } - - @Override - public <A> GraphTraversalSource withSideEffect(final String key, final Supplier<A> initialValue) { - this.translator.addSource("withSideEffect", key, initialValue); - return this; - } - - @Override - public <A> GraphTraversalSource withSack(final Supplier<A> initialValue, final UnaryOperator<A> splitOperator, final BinaryOperator<A> mergeOperator) { - this.translator.addSource("withSack", initialValue, splitOperator, mergeOperator); - return this; - } - - @Override - public <A> GraphTraversalSource withSack(final A initialValue, final UnaryOperator<A> splitOperator, final BinaryOperator<A> mergeOperator) { - this.translator.addSource("withSack", initialValue, splitOperator, mergeOperator); - return this; - } - - @Override - public <A> GraphTraversalSource withSack(final A initialValue) { - this.translator.addSource("withSack", initialValue); - return this; - } - - @Override - public <A> GraphTraversalSource withSack(final Supplier<A> initialValue) { - this.translator.addSource("withSack", initialValue); - return this; - } - - @Override - public <A> GraphTraversalSource withSack(final Supplier<A> initialValue, final UnaryOperator<A> splitOperator) { - this.translator.addSource("withSack", initialValue, splitOperator); - return this; - } - - @Override - public <A> GraphTraversalSource withSack(final A initialValue, final UnaryOperator<A> splitOperator) { - this.translator.addSource("withSack", initialValue, splitOperator); - return this; - } - - @Override - public <A> GraphTraversalSource withSack(final Supplier<A> initialValue, final BinaryOperator<A> mergeOperator) { - this.translator.addSource("withSack", initialValue, mergeOperator); - return this; - } - - @Override - public <A> GraphTraversalSource withSack(final A initialValue, final BinaryOperator<A> mergeOperator) { - this.translator.addSource("withSack", initialValue, mergeOperator); - return this; - } - - public GraphTraversalSource withBulk(final boolean useBulk) { - this.translator.addSource("withBulk", useBulk); - return this; - } - - public GraphTraversalSource withPath() { - this.translator.addSource("withPath"); - return this; - } - - //// SPAWNS - - /** - * @deprecated As of release 3.1.0, replaced by {@link #addV()} - */ - @Deprecated - public GraphTraversal<Vertex, Vertex> addV(final Object... keyValues) { - return this.generateTraversal("addV", keyValues); - } - - public GraphTraversal<Vertex, Vertex> addV(final String label) { - return this.generateTraversal("addV", label); - } - - public GraphTraversal<Vertex, Vertex> addV() { - return this.generateTraversal("addV"); - } - - public <S> GraphTraversal<S, S> inject(S... starts) { - return this.generateTraversal("inject", starts); - } - - public GraphTraversal<Vertex, Vertex> V(final Object... vertexIds) { - return this.generateTraversal("V", vertexIds); - } - - public GraphTraversal<Edge, Edge> E(final Object... edgesIds) { - return this.generateTraversal("E", edgesIds); - } - - private GraphTraversal generateTraversal(final String stepName, final Object... arguments) { - //this.translator.createAnonymousTraversalSupplier(); - final Translator clone = this.translator.clone(); - clone.addStep(stepName, arguments); - final GraphTraversal traversal = new ScriptGraphTraversal(this.graph, clone); - traversal.asAdmin().setStrategies(this.strategies); - return traversal; - } - - - public Transaction tx() { - return this.graph.tx(); - } - - - @Override - public String toString() { - return StringFactory.traversalSourceString(this); - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8d2de3f6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/Translator.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/Translator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/Translator.java index a8f2169..e9c62af 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/Translator.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/Translator.java @@ -49,13 +49,4 @@ public interface Translator extends Cloneable { public Translator clone(); - /// TODO: Below should be removed when ScriptXXXTraversal model is removed - - public default void addSource(final String sourceName, final Object... arguments) { - - } - - public default void addStep(final String sourceName, final Object... arguments) { - - } } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8d2de3f6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java index 8b97570..455b1a4 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java @@ -23,10 +23,7 @@ import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine; import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.script.ScriptGraphTraversalSource; -import org.apache.tinkerpop.gremlin.process.traversal.util.Translator; import org.apache.tinkerpop.gremlin.structure.io.Io; import org.apache.tinkerpop.gremlin.structure.io.IoRegistry; import org.apache.tinkerpop.gremlin.structure.util.FeatureDescriptor; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8d2de3f6/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversalSourceTest.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversalSourceTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversalSourceTest.java deleted file mode 100644 index 9aa8e50..0000000 --- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversalSourceTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.script; - -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.script.ScriptGraphTraversal; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.script.ScriptGraphTraversalSource; -import org.junit.Ignore; -import org.junit.Test; - -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -/** - * @author Marko A. Rodriguez (http://markorodriguez.com) - */ -public class ScriptGraphTraversalSourceTest { - - private static Set<String> NO_GRAPH = new HashSet<>(Arrays.asList("clone", "iterate")); - - @Test - @Ignore - public void scriptGraphTraversalSourceShouldHaveMethodsOfGraphTraversalSource() { - for (Method methodA : GraphTraversalSource.class.getMethods()) { - if ((GraphTraversal.class.isAssignableFrom(methodA.getReturnType()) || GraphTraversalSource.class.isAssignableFrom(methodA.getReturnType())) && !NO_GRAPH.contains(methodA.getName())) { - boolean found = false; - final String methodAName = methodA.getName(); - final String methodAParameters = Arrays.asList(methodA.getParameterTypes()).toString(); - for (final Method methodB : ScriptGraphTraversalSource.class.getDeclaredMethods()) { - final String methodBName = methodB.getName(); - final String methodBParameters = Arrays.asList(methodB.getParameterTypes()).toString(); - if (methodAName.equals(methodBName) && methodAParameters.equals(methodBParameters)) - found = true; - } - if (!found) - throw new IllegalStateException(ScriptGraphTraversal.class.getSimpleName() + " is missing the following method: " + methodAName + ":" + methodAParameters); - } - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8d2de3f6/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversalTest.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversalTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversalTest.java deleted file mode 100644 index cd074f0..0000000 --- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/script/ScriptGraphTraversalTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.script; - -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.script.ScriptGraphTraversal; -import org.junit.Ignore; -import org.junit.Test; - -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -/** - * @author Marko A. Rodriguez (http://markorodriguez.com) - */ -public class ScriptGraphTraversalTest { - - private static Set<String> NO_GRAPH = new HashSet<>(Arrays.asList("asAdmin","iterate")); - - @Test - @Ignore - public void scriptGraphTraversalShouldHaveMethodsOfGraphTraversal() { - for (Method methodA : GraphTraversal.class.getMethods()) { - if (GraphTraversal.class.isAssignableFrom(methodA.getReturnType()) && !NO_GRAPH.contains(methodA.getName())) { - boolean found = false; - final String methodAName = methodA.getName(); - final String methodAParameters = Arrays.asList(methodA.getParameterTypes()).toString(); - for (final Method methodB : ScriptGraphTraversal.class.getDeclaredMethods()) { - final String methodBName = methodB.getName(); - final String methodBParameters = Arrays.asList(methodB.getParameterTypes()).toString(); - if (methodAName.equals(methodBName) && methodAParameters.equals(methodBParameters)) - found = true; - } - if (!found) - throw new IllegalStateException(ScriptGraphTraversal.class.getSimpleName() + " is missing the following method: " + methodAName + ":" + methodAParameters); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8d2de3f6/gremlin-variant/src/main/jython/gremlin_python/gremlin_python.py ---------------------------------------------------------------------- diff --git a/gremlin-variant/src/main/jython/gremlin_python/gremlin_python.py b/gremlin-variant/src/main/jython/gremlin_python/gremlin_python.py index 4fe18ec..37be00b 100644 --- a/gremlin-variant/src/main/jython/gremlin_python/gremlin_python.py +++ b/gremlin-variant/src/main/jython/gremlin_python/gremlin_python.py @@ -17,8 +17,6 @@ specific language governing permissions and limitations under the License. ''' from collections import OrderedDict -import inspect - statics = OrderedDict() http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8d2de3f6/gremlin-variant/src/main/jython/gremlin_python/groovy_translator.py ---------------------------------------------------------------------- diff --git a/gremlin-variant/src/main/jython/gremlin_python/groovy_translator.py b/gremlin-variant/src/main/jython/gremlin_python/groovy_translator.py index d9f3855..0cb16e2 100644 --- a/gremlin-variant/src/main/jython/gremlin_python/groovy_translator.py +++ b/gremlin-variant/src/main/jython/gremlin_python/groovy_translator.py @@ -79,6 +79,12 @@ class GroovyTranslator(Translator): not (arg.startswith("T.")) and not (len(arg) == 0)): return "\"" + arg + "\"" + elif callable(arg): # closures + lambdaString = arg().strip() + if lambdaString.startswith("{"): + return lambdaString + else: + return "{" + lambdaString + "}" elif isinstance(arg, P): if arg.other is None: return "P." + GroovyTranslator.mapMethod(arg.operator) + "(" + GroovyTranslator.stringOrObject(