You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/05/26 12:57:24 UTC

[01/45] tinkerpop git commit: TINKERPOP-786 Updated javadocs in dsl archetype

Repository: tinkerpop
Updated Branches:
  refs/heads/tp32-glv abe23d4e5 -> 1d97c3de2


TINKERPOP-786 Updated javadocs in dsl archetype


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/94fe5f51
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/94fe5f51
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/94fe5f51

Branch: refs/heads/tp32-glv
Commit: 94fe5f51572c15083609e15fea08540b6740286c
Parents: 7e0d6d4
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 11:16:48 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../src/main/java/SocialTraversalDsl.java       | 22 ++++++++++++++++++++
 .../src/main/java/SocialTraversalSourceDsl.java |  9 ++++++++
 2 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/94fe5f51/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
index e8a2ded..af1f039 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
@@ -23,12 +23,34 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 
+/**
+ * This Social DSL is meant to be used with the TinkerPop "modern" toy graph.
+ * <p/>
+ * All DSLs should extend {@code GraphTraversal.Admin} and be suffixed with "TraversalDsl". Simply add DSL traversal
+ * methods to this interface. Use Gremlin's steps to build the underlying traversal in these methods to ensure
+ * compatibility with the rest of the TinkerPop stack and provider implementations.
+ * <p/>
+ * Arguments provided to the {@code GremlinDsl} annotation are all optional. In this case, a {@code traversalSource} is
+ * specified which points to a specific implementation to use. Had that argument not been specified then a default
+ * {@code TraversalSource} would have been generated.
+ */
 @GremlinDsl(traversalSource = "${package}.SocialTraversalSourceDsl")
 public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+
+    /**
+     * From a {@code Vertex} traverse "knows" edges to adjacent "person" vertices and filter those vertices on the
+     * "name" property.
+     *
+     * @param personName the name of the person to filter on
+     */
     public default GraphTraversal<S, Vertex> knows(String personName) {
         return out("knows").hasLabel("person").has("name", personName);
     }
 
+    /**
+     * From a {@code Vertex} traverse "knows" edges to adjacent "person" vertices and determine the youngest age of
+     * those persons.
+     */
     public default <E2 extends Number> GraphTraversal<S, E2> youngestFriendsAge() {
         return out("knows").hasLabel("person").values("age").min();
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/94fe5f51/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
index 9b5b136..3bd8297 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
@@ -31,6 +31,9 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 
+/**
+ * See {@code SocialTraversalDsl} for more information about this DSL.
+ */
 public class SocialTraversalSourceDsl extends GraphTraversalSource {
 
     public SocialTraversalSourceDsl(final Graph graph, final TraversalStrategies traversalStrategies) {
@@ -41,6 +44,12 @@ public class SocialTraversalSourceDsl extends GraphTraversalSource {
         super(graph);
     }
 
+    /**
+     * Starts a traversal that finds all vertices with a "person" label and optionally allows filtering of those
+     * vertices on the "name" property.
+     *
+     * @param names list of person names to filter on
+     */
     public GraphTraversal<Vertex, Vertex> persons(String... names) {
         GraphTraversalSource clone = this.clone();
         clone.getBytecode().addStep(GraphTraversal.Symbols.V);


[15/45] tinkerpop git commit: TINKERPOP-786 Worked in custom GraphTraversalSource into DSL

Posted by sp...@apache.org.
TINKERPOP-786 Worked in custom GraphTraversalSource into DSL


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/cf53e13d
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/cf53e13d
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/cf53e13d

Branch: refs/heads/tp32-glv
Commit: cf53e13d66dbced6ab0695481473e8a5e8a5d5c0
Parents: fe702fe
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Apr 28 14:58:52 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../src/main/java/SocialTraversalDsl.java       |  2 +-
 .../src/main/java/SocialTraversalSourceDsl.java | 51 ++++++++++++
 .../src/test/java/SocialDslTest.java            |  6 ++
 .../process/traversal/dsl/GremlinDsl.java       |  6 ++
 .../traversal/dsl/GremlinDslProcessor.java      | 87 ++++++++++++++++----
 .../traversal/util/DefaultTraversal.java        |  5 ++
 .../traversal/dsl/GremlinDslProcessorTest.java  |  8 ++
 .../dsl/SocialPackageTraversalSourceDsl.java    | 54 ++++++++++++
 .../traversal/dsl/SocialMoveTraversalDsl.java   |  2 +-
 .../dsl/SocialPackageTraversalDsl.java          | 37 +++++++++
 .../traversal/dsl/SocialTraversalDsl.java       |  2 +-
 11 files changed, 242 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf53e13d/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
index fb2a3f6..add44aa 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
@@ -23,7 +23,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 
-@GremlinDsl
+@GremlinDsl(traversalSource = "${package}.SocialTraversalSourceDsl")
 public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
     public default GraphTraversal<S, Vertex> knows(final String personName) {
         return out("knows").hasLabel("person").has("name", personName);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf53e13d/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
new file mode 100644
index 0000000..0117914
--- /dev/null
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
@@ -0,0 +1,51 @@
+/*
+ * 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 ${package};
+
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDsl;
+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.step.map.GraphStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+public class SocialTraversalSourceDsl extends GraphTraversalSource {
+
+    public SocialTraversalSourceDsl(final Graph graph, final TraversalStrategies traversalStrategies) {
+        super(graph, traversalStrategies);
+    }
+
+    public SocialTraversalSourceDsl(final Graph graph) {
+        super(graph);
+    }
+
+    public GraphTraversal<Vertex, Vertex> persons() {
+        final GraphTraversalSource clone = this.clone();
+        clone.getBytecode().addStep(GraphTraversal.Symbols.V);
+        clone.getBytecode().addStep(GraphTraversal.Symbols.hasLabel, "person");
+        final GraphTraversal.Admin<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
+        return TraversalHelper.addHasContainer(traversal.addStep(new GraphStep<>(traversal, Vertex.class, true)), new HasContainer(T.label.getAccessor(), P.eq("person")));
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf53e13d/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
index ddd584c..be73500 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
@@ -43,4 +43,10 @@ public class SocialDslTest {
         SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
         assertEquals(27, social.V().has("name","marko").youngestFriendsAge().next().intValue());
     }
+
+    @Test
+    public void shouldFindAllPersons() {
+        SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
+        assertEquals(4, social.persons().count().next().intValue());
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf53e13d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
index cbeb5ba..d08736e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
@@ -19,6 +19,7 @@
 package org.apache.tinkerpop.gremlin.process.traversal.dsl;
 
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
 
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
@@ -39,4 +40,9 @@ public @interface GremlinDsl {
      * it will default to the same package as the class or interface the annotation is on.
      */
     public String packageName() default "";
+
+    /**
+     * Defines the optional canonical name of the {@link GraphTraversalSource} that this DSL should extend from.
+     */
+    public String traversalSource() default "org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource";
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf53e13d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index c2c4fc7..6a09ef5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -111,7 +111,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
     }
 
     private void generateTraversalSource(final Context ctx) throws IOException {
-        final TypeElement graphTraversalSourceElement = elementUtils.getTypeElement(GraphTraversalSource.class.getCanonicalName());
+        final TypeElement graphTraversalSourceElement = ctx.traversalSourceDslType;
         final TypeSpec.Builder traversalSourceClass = TypeSpec.classBuilder(ctx.traversalSourceClazz)
                 .addModifiers(Modifier.PUBLIC)
                 .superclass(TypeName.get(graphTraversalSourceElement.asType()));
@@ -129,22 +129,58 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 .addStatement("super($N, $N)", "graph", "strategies")
                 .build());
 
-        // override methods to return a the DSL TraversalSource
-        for (Element elementOfGraphTraversal : graphTraversalSourceElement.getEnclosedElements()) {
+        // override methods to return a the DSL TraversalSource. find GraphTraversalSource class somewhere in the hierarchy
+        final Element tinkerPopsGraphTraversalSource = findTinkerPopsGraphTraversalSource(graphTraversalSourceElement);
+        for (Element elementOfGraphTraversalSource : tinkerPopsGraphTraversalSource.getEnclosedElements()) {
             // first copy/override methods that return a GraphTraversalSource so that we can instead return
             // the DSL TraversalSource class.
-            tryConstructMethod(elementOfGraphTraversal, ctx.traversalSourceClassName, "",
+            tryConstructMethod(elementOfGraphTraversalSource, ctx.traversalSourceClassName, "",
                     e -> !(e.getReturnType().getKind() == TypeKind.DECLARED && ((DeclaredType) e.getReturnType()).asElement().getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())),
                     Modifier.PUBLIC)
                     .ifPresent(traversalSourceClass::addMethod);
         }
 
+        // override methods that return GraphTraversal that come from the user defined extension of GraphTraversal
+        if (!graphTraversalSourceElement.getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())) {
+            for (Element elementOfGraphTraversalSource : graphTraversalSourceElement.getEnclosedElements()) {
+                if (elementOfGraphTraversalSource.getKind() != ElementKind.METHOD) continue;
+
+                final ExecutableElement templateMethod = (ExecutableElement) elementOfGraphTraversalSource;
+                final MethodSpec.Builder methodToAdd = MethodSpec.methodBuilder(elementOfGraphTraversalSource.getSimpleName().toString())
+                        .addModifiers(Modifier.PUBLIC)
+                        .addAnnotation(Override.class);
+
+                boolean added = false;
+                final List<? extends VariableElement> parameters = templateMethod.getParameters();
+                String body = "return new " + ctx.defaultTraversalClassName + "(clone, super." + elementOfGraphTraversalSource.getSimpleName().toString() + "(";
+                for (VariableElement param : parameters) {
+                    methodToAdd.addParameter(ParameterSpec.get(param));
+
+                    body = body + param.getSimpleName() + ",";
+                    added = true;
+                }
+
+                // treat a final array as a varargs param
+                if (!parameters.isEmpty() && parameters.get(parameters.size() - 1).asType().getKind() == TypeKind.ARRAY)
+                    methodToAdd.varargs(true);
+
+                if (added) body = body.substring(0, body.length() - 1);
+
+                body = body + ").asAdmin())";
+                methodToAdd.addStatement("$T clone = this.clone()", ctx.traversalSourceClassName)
+                        .addStatement(body)
+                        .returns(getReturnTypeDefinition(ctx.traversalClassName, templateMethod));
+
+                traversalSourceClass.addMethod(methodToAdd.build());
+            }
+        }
+
         // override methods that return GraphTraversal
         traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
                 .addModifiers(Modifier.PUBLIC)
                 .addAnnotation(Override.class)
                 .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
-                .addStatement("clone.bytecode.addStep($T.addV)", GraphTraversal.Symbols.class)
+                .addStatement("clone.getBytecode().addStep($T.addV)", GraphTraversal.Symbols.class)
                 .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
                 .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, null))", ctx.traversalClassName, AddVertexStartStep.class)
                 .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
@@ -154,7 +190,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 .addAnnotation(Override.class)
                 .addParameter(String.class, "label")
                 .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
-                .addStatement("clone.bytecode.addStep($T.addV, label)", GraphTraversal.Symbols.class)
+                .addStatement("clone.getBytecode().addStep($T.addV, label)", GraphTraversal.Symbols.class)
                 .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
                 .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, label))", ctx.traversalClassName, AddVertexStartStep.class)
                 .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
@@ -165,7 +201,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 .addParameter(Object[].class, "vertexIds")
                 .varargs(true)
                 .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
-                .addStatement("clone.bytecode.addStep($T.V, vertexIds)", GraphTraversal.Symbols.class)
+                .addStatement("clone.getBytecode().addStep($T.V, vertexIds)", GraphTraversal.Symbols.class)
                 .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
                 .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, vertexIds))", ctx.traversalClassName, GraphStep.class, Vertex.class)
                 .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
@@ -176,7 +212,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 .addParameter(Object[].class, "edgeIds")
                 .varargs(true)
                 .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
-                .addStatement("clone.bytecode.addStep($T.E, edgeIds)", GraphTraversal.Symbols.class)
+                .addStatement("clone.getBytecode().addStep($T.E, edgeIds)", GraphTraversal.Symbols.class)
                 .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
                 .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, edgeIds))", ctx.traversalClassName, GraphStep.class, Edge.class)
                 .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Edge.class), ClassName.get(Edge.class)))
@@ -186,6 +222,15 @@ public class GremlinDslProcessor extends AbstractProcessor {
         traversalSourceJavaFile.writeTo(filer);
     }
 
+    private Element findTinkerPopsGraphTraversalSource(final Element element) {
+        if (element.getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())) {
+            return element;
+        }
+
+        final List<? extends TypeMirror> supertypes = typeUtils.directSupertypes(element.asType());
+        return findTinkerPopsGraphTraversalSource(typeUtils.asElement(supertypes.get(0)));
+    }
+
     private void generateDefaultTraversal(final Context ctx) throws IOException {
         final TypeSpec.Builder defaultTraversalClass = TypeSpec.classBuilder(ctx.defaultTraversalClazz)
                 .addModifiers(Modifier.PUBLIC)
@@ -208,6 +253,12 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 .addParameter(ctx.traversalSourceClassName, "traversalSource")
                 .addStatement("super($N)", "traversalSource")
                 .build());
+        defaultTraversalClass.addMethod(MethodSpec.constructorBuilder()
+                .addModifiers(Modifier.PUBLIC)
+                .addParameter(ctx.traversalSourceClassName, "traversalSource")
+                .addParameter(ctx.graphTraversalAdminClassName, "traversal")
+                .addStatement("super($N, $N.asAdmin())", "traversalSource", "traversal")
+                .build());
 
         // add the override
         defaultTraversalClass.addMethod(MethodSpec.methodBuilder("iterate")
@@ -277,13 +328,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
 
         if (ignore != null && ignore.test(templateMethod)) return Optional.empty();
 
-        final DeclaredType returnTypeMirror = (DeclaredType) templateMethod.getReturnType();
-        final List<? extends TypeMirror> returnTypeArguments = returnTypeMirror.getTypeArguments();
-
-        // build a return type with appropriate generic declarations (if such declarations are present)
-        final TypeName returnType = returnTypeArguments.isEmpty() ?
-                returnClazz :
-                ParameterizedTypeName.get(returnClazz, returnTypeArguments.stream().map(TypeName::get).collect(Collectors.toList()).toArray(new TypeName[returnTypeArguments.size()]));
+        final TypeName returnType = getReturnTypeDefinition(returnClazz, templateMethod);
         final MethodSpec.Builder methodToAdd = MethodSpec.methodBuilder(methodName)
                 .addModifiers(modifiers)
                 .addAnnotation(Override.class)
@@ -315,6 +360,16 @@ public class GremlinDslProcessor extends AbstractProcessor {
         return Optional.of(methodToAdd.build());
     }
 
+    private TypeName getReturnTypeDefinition(final ClassName returnClazz, final ExecutableElement templateMethod) {
+        final DeclaredType returnTypeMirror = (DeclaredType) templateMethod.getReturnType();
+        final List<? extends TypeMirror> returnTypeArguments = returnTypeMirror.getTypeArguments();
+
+        // build a return type with appropriate generic declarations (if such declarations are present)
+        return returnTypeArguments.isEmpty() ?
+                returnClazz :
+                ParameterizedTypeName.get(returnClazz, returnTypeArguments.stream().map(TypeName::get).collect(Collectors.toList()).toArray(new TypeName[returnTypeArguments.size()]));
+    }
+
     private void validateDSL(final Element dslElement) throws ProcessorException {
         if (dslElement.getKind() != ElementKind.INTERFACE)
             throw new ProcessorException(dslElement, "Only interfaces can be annotated with @%s", GremlinDsl.class.getSimpleName());
@@ -335,6 +390,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
         private final String defaultTraversalClazz;
         private final ClassName defaultTraversalClassName;
         private final ClassName graphTraversalAdminClassName;
+        private final TypeElement traversalSourceDslType;
 
         public Context(final TypeElement dslElement) {
             annotatedDslType = dslElement;
@@ -342,6 +398,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
             // gets the annotation on the dsl class/interface
             GremlinDsl gremlinDslAnnotation = dslElement.getAnnotation(GremlinDsl.class);
 
+            traversalSourceDslType = elementUtils.getTypeElement(gremlinDslAnnotation.traversalSource());
             packageName = getPackageName(dslElement, gremlinDslAnnotation);
 
             // create the Traversal implementation interface

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf53e13d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
index c8f4b24..5a65006 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
@@ -79,6 +79,11 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S, E> {
         this(traversalSource.getGraph(), traversalSource.getStrategies(), traversalSource.getBytecode());
     }
 
+    public DefaultTraversal(final TraversalSource traversalSource, final DefaultTraversal.Admin<S,E> traversal) {
+        this(traversalSource.getGraph(), traversalSource.getStrategies(), traversal.getBytecode());
+        steps.addAll(traversal.getSteps());
+    }
+
     // TODO: clean up unused or redundant constructors
 
     public DefaultTraversal() {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf53e13d/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
index d1e976d..d0d7d6f 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
@@ -48,4 +48,12 @@ public class GremlinDslProcessorTest {
                 .and()
                 .generatesFileNamed(StandardLocation.SOURCE_OUTPUT, "org.apache.tinkerpop.gremlin.process.traversal.dsl.social", "SocialMoveTraversal.java");
     }
+
+    @Test
+    public void shouldCompileTraversalAndTraversalSourceToDefaultPackage() {
+        ASSERT.about(javaSource())
+                .that(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialPackageTraversalDsl.java")))
+                .processedWith(new GremlinDslProcessor())
+                .compilesWithoutError();
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf53e13d/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java
new file mode 100644
index 0000000..143a5c9
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDsl;
+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.step.map.GraphStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class SocialPackageTraversalSourceDsl extends GraphTraversalSource {
+
+    public SocialPackageTraversalSourceDsl(final Graph graph, final TraversalStrategies traversalStrategies) {
+        super(graph, traversalStrategies);
+    }
+
+    public SocialPackageTraversalSourceDsl(final Graph graph) {
+        super(graph);
+    }
+
+    public GraphTraversal<Vertex, Vertex> persons() {
+        final GraphTraversalSource clone = this.clone();
+        clone.getBytecode().addStep(GraphTraversal.Symbols.V);
+        clone.getBytecode().addStep(GraphTraversal.Symbols.hasLabel, "person");
+        final GraphTraversal.Admin<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
+        return TraversalHelper.addHasContainer(traversal.addStep(new GraphStep<>(traversal, Vertex.class, true)), new HasContainer(T.label.getAccessor(), P.eq("person")));
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf53e13d/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
index 1ef5ca8..bb27a9e 100644
--- a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
+++ b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.tinkerpop.gremlin.util.dsl;
+package org.apache.tinkerpop.gremlin.process.traversal.dsl;
 
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDsl;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf53e13d/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalDsl.java b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalDsl.java
new file mode 100644
index 0000000..f472932
--- /dev/null
+++ b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalDsl.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDsl;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@GremlinDsl(traversalSource = "org.apache.tinkerpop.gremlin.process.traversal.dsl.SocialPackageTraversalSourceDsl")
+public interface SocialPackageTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+    public default GraphTraversal<S, Vertex> knows(final String personName) {
+        return out("knows").hasLabel("person").has("name", personName);
+    }
+
+    public default <E2 extends Number> GraphTraversal<S, E2> meanAgeOfFriends() {
+        return out("knows").hasLabel("person").values("age").mean();
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf53e13d/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
index c3c40a3..4c31330 100644
--- a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
+++ b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.tinkerpop.gremlin.util.dsl;
+package org.apache.tinkerpop.gremlin.process.traversal.dsl;
 
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDsl;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;


[45/45] tinkerpop git commit: TINKERPOP-786 Changed name of DSL archetype

Posted by sp...@apache.org.
TINKERPOP-786 Changed name of DSL archetype


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/1d97c3de
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/1d97c3de
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/1d97c3de

Branch: refs/heads/tp32-glv
Commit: 1d97c3de28ea14b1cda35c4e078b9dd76418120c
Parents: d6b0122
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 26 07:48:00 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri May 26 07:48:00 2017 -0400

----------------------------------------------------------------------
 gremlin-archetype/gremlin-archetype-dsl/pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1d97c3de/gremlin-archetype/gremlin-archetype-dsl/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/pom.xml b/gremlin-archetype/gremlin-archetype-dsl/pom.xml
index d4922f5..cecdc28 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/pom.xml
+++ b/gremlin-archetype/gremlin-archetype-dsl/pom.xml
@@ -10,7 +10,7 @@
     </parent>
 
     <artifactId>gremlin-archetype-dsl</artifactId>
-    <name>Apache TinkerPop :: Archetype - TinkerGraph</name>
+    <name>Apache TinkerPop :: Archetype - DSL</name>
     <packaging>jar</packaging>
 
     <build>


[24/45] tinkerpop git commit: TINKERPOP-786 WIP for anonymous traversals in python DSLs

Posted by sp...@apache.org.
TINKERPOP-786 WIP for anonymous traversals in python DSLs

Not sure if this will be the right way to do this, but it works and tests pass. We'll see what happens once this gets review.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/a3d42d5f
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/a3d42d5f
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/a3d42d5f

Branch: refs/heads/tp32-glv
Commit: a3d42d5f37ff90d758947f19b9568cd2a3d92f1b
Parents: 911d17f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed May 10 16:47:27 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:31 2017 -0400

----------------------------------------------------------------------
 .../src/main/jython/tests/process/test_dsl.py   | 30 ++++++++++++++++----
 1 file changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a3d42d5f/gremlin-python/src/main/jython/tests/process/test_dsl.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/process/test_dsl.py b/gremlin-python/src/main/jython/tests/process/test_dsl.py
index ece81dc..92196fe 100644
--- a/gremlin-python/src/main/jython/tests/process/test_dsl.py
+++ b/gremlin-python/src/main/jython/tests/process/test_dsl.py
@@ -18,14 +18,15 @@ under the License.
 '''
 import pytest
 
+from gremlin_python.process.traversal import (Bytecode, P)
 from gremlin_python.process.graph_traversal import (
-    GraphTraversalSource, GraphTraversal)
+    GraphTraversalSource, GraphTraversal, __)
 from gremlin_python.structure.graph import Graph
 
 __author__ = 'David M. Brown (davebshow@gmail.com)'
 
 
-class SocialTraversalDsl(GraphTraversal):
+class SocialTraversal(GraphTraversal):
 
     def knows(self, person_name):
         return self.out("knows").hasLabel("person").has("name", person_name)
@@ -33,12 +34,28 @@ class SocialTraversalDsl(GraphTraversal):
     def youngestFriendsAge(self):
         return self.out("knows").hasLabel("person").values("age").min()
 
+    def createdAtLeast(self, number):
+        return self.outE("created").count().is_(P.gte(number))
 
-class SocialTraversalSourceDsl(GraphTraversalSource):
+class ___(__):
+    @staticmethod
+    def knows(*args):
+        return SocialTraversal(None, None, Bytecode()).knows(*args)
+
+    @staticmethod
+    def youngestFriendsAge(*args):
+        return SocialTraversal(None, None, Bytecode()).youngestFriendsAge(*args)
+
+    @staticmethod
+    def createdAtLeast(*args):
+        return SocialTraversal(None, None, Bytecode()).createdAtLeast(*args)
+
+
+class SocialTraversalSource(GraphTraversalSource):
 
     def __init__(self, *args, **kwargs):
-        super(SocialTraversalSourceDsl, self).__init__(*args, **kwargs)
-        self.graph_traversal = SocialTraversalDsl
+        super(SocialTraversalSource, self).__init__(*args, **kwargs)
+        self.graph_traversal = SocialTraversal
 
     def persons(self):
         traversal = self.get_graph_traversal()
@@ -48,7 +65,8 @@ class SocialTraversalSourceDsl(GraphTraversalSource):
 
 
 def test_dsl(remote_connection):
-    social = Graph().traversal(SocialTraversalSourceDsl).withRemote(remote_connection)
+    social = Graph().traversal(SocialTraversalSource).withRemote(remote_connection)
     assert social.V().has("name", "marko").knows("josh").next()
     assert social.V().has("name", "marko").youngestFriendsAge().next() == 27
     assert social.persons().count().next() == 4
+    assert social.persons().filter(___.createdAtLeast(2)).count().next() == 1


[06/45] tinkerpop git commit: TINKERPOP-786 Updated docs for intellij setup

Posted by sp...@apache.org.
TINKERPOP-786 Updated docs for intellij setup

Now that we have a annotation processor in gremlin-core there are some additional setup instructions required for Intellij to ensure tests can run through the debugger.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/a98471c4
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/a98471c4
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/a98471c4

Branch: refs/heads/tp32-glv
Commit: a98471c4ee267afb1e362a93c28fb9dea221fb98
Parents: 62cfbc9
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu May 4 10:27:27 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 docs/src/dev/developer/development-environment.asciidoc | 10 ++++++++++
 1 file changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a98471c4/docs/src/dev/developer/development-environment.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/dev/developer/development-environment.asciidoc b/docs/src/dev/developer/development-environment.asciidoc
index 4a7a3f0..98a89f7 100644
--- a/docs/src/dev/developer/development-environment.asciidoc
+++ b/docs/src/dev/developer/development-environment.asciidoc
@@ -223,3 +223,13 @@ This will ensure that tests will properly execute within the IDE.
 
 If Intellij complains about "duplicate sources" for the Groovy files when attempting to compile/run tests, then
 install the link:http://plugins.jetbrains.com/plugin/7442?pr=idea[GMavenPlus Intellij plugin].
+
+The `gremlin-core` module uses a Java annotation processor to help support DSLs. To support this capability be sure
+that:
+
+. `File | Settings | Compiler | Annotation Processors` has the checkbox with the "Enable annotation processing" checked.
+Intellij should be able to detect the processor automatically on build.
+. The `gremlin-core/target` directory should not be hidden and `target/classes`, `target/gneerated-sources` and
+`target/generated-test-sources should be marked as "Generated Sources Root". If they are not setup that way by
+Intellij by default then simply right-click on them use the "Mark Directory with" option to make the appropriate
+selections.


[07/45] tinkerpop git commit: TINKERPOP-786 Refactored code to extract TraversalSource generation in DSLs

Posted by sp...@apache.org.
TINKERPOP-786 Refactored code to extract TraversalSource generation in DSLs


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/be3ed44d
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/be3ed44d
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/be3ed44d

Branch: refs/heads/tp32-glv
Commit: be3ed44daa63121218a8295bef2aab1edcea493e
Parents: 6efaca0
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 27 15:22:32 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../traversal/dsl/GremlinDslProcessor.java      | 156 ++++++++++---------
 1 file changed, 80 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/be3ed44d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index f9d5a40..c2c4fc7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -96,84 +96,12 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 generateTraversalInterface(ctx);
 
                 // create the "DefaultTraversal" class which implements the above generated "Traversal" and can then
-                // be used by the "TraversalSource" generated below to spawn new traversal instances
+                // be used by the "TraversalSource" generated below to spawn new traversal instances.
                 generateDefaultTraversal(ctx);
 
-                // START write "TraversalSource" class
-                final TypeElement graphTraversalSourceElement = elementUtils.getTypeElement(GraphTraversalSource.class.getCanonicalName());
-                final TypeSpec.Builder traversalSourceClass = TypeSpec.classBuilder(ctx.traversalSourceClazz)
-                        .addModifiers(Modifier.PUBLIC)
-                        .superclass(TypeName.get(graphTraversalSourceElement.asType()));
-
-                // add the required constructors for instantiation
-                traversalSourceClass.addMethod(MethodSpec.constructorBuilder()
-                        .addModifiers(Modifier.PUBLIC)
-                        .addParameter(Graph.class, "graph")
-                        .addStatement("super($N)", "graph")
-                        .build());
-                traversalSourceClass.addMethod(MethodSpec.constructorBuilder()
-                        .addModifiers(Modifier.PUBLIC)
-                        .addParameter(Graph.class, "graph")
-                        .addParameter(TraversalStrategies.class, "strategies")
-                        .addStatement("super($N, $N)", "graph", "strategies")
-                        .build());
-
-                // override methods to return a the DSL TraversalSource
-                for (Element elementOfGraphTraversal : graphTraversalSourceElement.getEnclosedElements()) {
-                    // first copy/override methods that return a GraphTraversalSource so that we can instead return
-                    // the DSL TraversalSource class.
-                    tryConstructMethod(elementOfGraphTraversal, ctx.traversalSourceClassName, "",
-                            e -> !(e.getReturnType().getKind() == TypeKind.DECLARED && ((DeclaredType) e.getReturnType()).asElement().getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())),
-                            Modifier.PUBLIC)
-                            .ifPresent(traversalSourceClass::addMethod);
-                }
-
-                // override methods that return GraphTraversal
-                traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
-                        .addModifiers(Modifier.PUBLIC)
-                        .addAnnotation(Override.class)
-                        .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
-                        .addStatement("clone.bytecode.addStep($T.addV)", GraphTraversal.Symbols.class)
-                        .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
-                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, null))", ctx.traversalClassName, AddVertexStartStep.class)
-                        .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
-                        .build());
-                traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
-                        .addModifiers(Modifier.PUBLIC)
-                        .addAnnotation(Override.class)
-                        .addParameter(String.class, "label")
-                        .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
-                        .addStatement("clone.bytecode.addStep($T.addV, label)", GraphTraversal.Symbols.class)
-                        .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
-                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, label))", ctx.traversalClassName, AddVertexStartStep.class)
-                        .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
-                        .build());
-                traversalSourceClass.addMethod(MethodSpec.methodBuilder("V")
-                        .addModifiers(Modifier.PUBLIC)
-                        .addAnnotation(Override.class)
-                        .addParameter(Object[].class, "vertexIds")
-                        .varargs(true)
-                        .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
-                        .addStatement("clone.bytecode.addStep($T.V, vertexIds)", GraphTraversal.Symbols.class)
-                        .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
-                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, vertexIds))", ctx.traversalClassName, GraphStep.class, Vertex.class)
-                        .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
-                        .build());
-                traversalSourceClass.addMethod(MethodSpec.methodBuilder("E")
-                        .addModifiers(Modifier.PUBLIC)
-                        .addAnnotation(Override.class)
-                        .addParameter(Object[].class, "edgeIds")
-                        .varargs(true)
-                        .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
-                        .addStatement("clone.bytecode.addStep($T.E, edgeIds)", GraphTraversal.Symbols.class)
-                        .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
-                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, edgeIds))", ctx.traversalClassName, GraphStep.class, Edge.class)
-                        .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Edge.class), ClassName.get(Edge.class)))
-                        .build());
-
-                final JavaFile traversalSourceJavaFile = JavaFile.builder(ctx.packageName, traversalSourceClass.build()).build();
-                traversalSourceJavaFile.writeTo(filer);
-                // END write "TraversalSource" class
+                // create the "TraversalSource" class which is used to spawn traversals from a Graph instance. It will
+                // spawn instances of the "DefaultTraversal" generated above.
+                generateTraversalSource(ctx);
             }
         } catch (Exception ex) {
             messager.printMessage(Diagnostic.Kind.ERROR, ex.getMessage());
@@ -182,6 +110,82 @@ public class GremlinDslProcessor extends AbstractProcessor {
         return true;
     }
 
+    private void generateTraversalSource(final Context ctx) throws IOException {
+        final TypeElement graphTraversalSourceElement = elementUtils.getTypeElement(GraphTraversalSource.class.getCanonicalName());
+        final TypeSpec.Builder traversalSourceClass = TypeSpec.classBuilder(ctx.traversalSourceClazz)
+                .addModifiers(Modifier.PUBLIC)
+                .superclass(TypeName.get(graphTraversalSourceElement.asType()));
+
+        // add the required constructors for instantiation
+        traversalSourceClass.addMethod(MethodSpec.constructorBuilder()
+                .addModifiers(Modifier.PUBLIC)
+                .addParameter(Graph.class, "graph")
+                .addStatement("super($N)", "graph")
+                .build());
+        traversalSourceClass.addMethod(MethodSpec.constructorBuilder()
+                .addModifiers(Modifier.PUBLIC)
+                .addParameter(Graph.class, "graph")
+                .addParameter(TraversalStrategies.class, "strategies")
+                .addStatement("super($N, $N)", "graph", "strategies")
+                .build());
+
+        // override methods to return a the DSL TraversalSource
+        for (Element elementOfGraphTraversal : graphTraversalSourceElement.getEnclosedElements()) {
+            // first copy/override methods that return a GraphTraversalSource so that we can instead return
+            // the DSL TraversalSource class.
+            tryConstructMethod(elementOfGraphTraversal, ctx.traversalSourceClassName, "",
+                    e -> !(e.getReturnType().getKind() == TypeKind.DECLARED && ((DeclaredType) e.getReturnType()).asElement().getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())),
+                    Modifier.PUBLIC)
+                    .ifPresent(traversalSourceClass::addMethod);
+        }
+
+        // override methods that return GraphTraversal
+        traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
+                .addModifiers(Modifier.PUBLIC)
+                .addAnnotation(Override.class)
+                .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
+                .addStatement("clone.bytecode.addStep($T.addV)", GraphTraversal.Symbols.class)
+                .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
+                .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, null))", ctx.traversalClassName, AddVertexStartStep.class)
+                .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
+                .build());
+        traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
+                .addModifiers(Modifier.PUBLIC)
+                .addAnnotation(Override.class)
+                .addParameter(String.class, "label")
+                .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
+                .addStatement("clone.bytecode.addStep($T.addV, label)", GraphTraversal.Symbols.class)
+                .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
+                .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, label))", ctx.traversalClassName, AddVertexStartStep.class)
+                .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
+                .build());
+        traversalSourceClass.addMethod(MethodSpec.methodBuilder("V")
+                .addModifiers(Modifier.PUBLIC)
+                .addAnnotation(Override.class)
+                .addParameter(Object[].class, "vertexIds")
+                .varargs(true)
+                .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
+                .addStatement("clone.bytecode.addStep($T.V, vertexIds)", GraphTraversal.Symbols.class)
+                .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
+                .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, vertexIds))", ctx.traversalClassName, GraphStep.class, Vertex.class)
+                .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
+                .build());
+        traversalSourceClass.addMethod(MethodSpec.methodBuilder("E")
+                .addModifiers(Modifier.PUBLIC)
+                .addAnnotation(Override.class)
+                .addParameter(Object[].class, "edgeIds")
+                .varargs(true)
+                .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
+                .addStatement("clone.bytecode.addStep($T.E, edgeIds)", GraphTraversal.Symbols.class)
+                .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
+                .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, edgeIds))", ctx.traversalClassName, GraphStep.class, Edge.class)
+                .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Edge.class), ClassName.get(Edge.class)))
+                .build());
+
+        final JavaFile traversalSourceJavaFile = JavaFile.builder(ctx.packageName, traversalSourceClass.build()).build();
+        traversalSourceJavaFile.writeTo(filer);
+    }
+
     private void generateDefaultTraversal(final Context ctx) throws IOException {
         final TypeSpec.Builder defaultTraversalClass = TypeSpec.classBuilder(ctx.defaultTraversalClazz)
                 .addModifiers(Modifier.PUBLIC)


[34/45] tinkerpop git commit: TINKERPOP-786 Added docs for gremlin-python based DSLs

Posted by sp...@apache.org.
TINKERPOP-786 Added docs for gremlin-python based DSLs


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/3142aeee
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/3142aeee
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/3142aeee

Branch: refs/heads/tp32-glv
Commit: 3142aeeeef4a3494b6c698f5e8e57a1205973287
Parents: 628ef6e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu May 11 10:06:33 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:31 2017 -0400

----------------------------------------------------------------------
 docs/src/reference/the-traversal.asciidoc       | 110 +++++++++++++++++--
 .../src/main/java/SocialTraversalDsl.java       |   2 +-
 2 files changed, 102 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3142aeee/docs/src/reference/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/the-traversal.asciidoc b/docs/src/reference/the-traversal.asciidoc
index ec0bed9..443004c 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -2946,17 +2946,17 @@ Domain Specific Languages
 
 Gremlin is a link:http://en.wikipedia.org/wiki/Domain-specific_language[domain specific language] (DSL) for traversing
 graphs. It operates in the language of vertices, edges and properties. Typically, applications built with Gremlin are
-not of the graph domain, but instead model their domain within a graph. For example, the "modern" toy graph models
+not of the graph domain, but instead model their domain within a graph. For example, the
+link:http://tinkerpop.apache.org/docs/current/images/tinkerpop-modern.png["modern" toy graph] models
 software and person domain objects with the relationships between them (i.e. a person "knows" another person and a
 person "created" software).
 
-image::tinkerpop-modern.png[width=350]
-
-An analyst who wanted to find all the people who "marko" knows could write the following Gremlin:
+An analyst who wanted to find out if "marko" knows "josh" could write the following Gremlin:
 
 [source,java]
 ----
-g.V().hasLabel('person').has('name','marko').out('knows')
+g.V().hasLabel('person').has('name','marko').
+  out('knows').hasLabel('person').has('name','josh').hasNext()
 ----
 
 While this method achieves the desired answer, it requires the analyst to traverse the graph in the domain language
@@ -2965,15 +2965,35 @@ traversal might be:
 
 [source,java]
 ----
-g.persons('marko').knows()
+g.persons('marko').knows('josh').hasNext()
 ----
 
 In the statement above, the traversal is written in the language of the domain, abstracting away the underlying
-graph structure from the query. The two traversal results are equivalent and, indeed, the "Social Network DSL" produces
+graph structure from the query. The two traversal results are equivalent and, indeed, the "Social DSL" produces
 the same set of traversal steps as the "Graph DSL" thus producing equivalent strategy application and performance
 runtimes.
 
-The following sections explain how to develop application specific DSLs for different <<gremlin-variants,Gremlin Language Variants>>.
+To further the example of the Social DSL consider the following:
+
+[source,java]
+----
+// Graph DSL - find the number of persons who created at least 2 projects
+g.V().hasLabel('person').
+  where(outE("created").count().is(P.gte(2))).count()
+
+// Social DSL - find the number of persons who created at least 2 projects
+social.persons().where(createdAtLeast(2)).count()
+
+// Graph DSL - determine the age of the youngest friend "marko" has
+g.V().hasLabel('person').has('name','marko').
+  out("knows").hasLabel("person").values("age").min()
+
+// Social DSL - determine the age of the youngest friend "marko" has
+social.persons("marko").youngestFriendsAge()
+----
+
+The following sections explain how to develop application specific DSLs for different <<gremlin-variants,Gremlin Language Variants>>
+using the examples above of the Social DSL as the API for the implementation.
 
 [[gremlin-java-dsl]
 Gremlin-Java
@@ -3005,6 +3025,10 @@ public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
     public default <E2 extends Number> GraphTraversal<S, E2> youngestFriendsAge() {
         return out("knows").hasLabel("person").values("age").min();
     }
+
+    public default GraphTraversal<S, Long> createdAtLeast(int number) {
+        return outE("created").count().is(P.gte(number));
+    }
 }
 ----
 
@@ -3089,7 +3113,7 @@ It is then possible to use the `persons()` method to start traversals:
 [source,java]
 ----
 SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
-social.persons().count();
+social.persons("marko").knows("josh");
 ----
 
 NOTE: Using Maven, as shown in the `gremlin-archetype-dsl` module, makes developing DSLs with the annotation processor
@@ -3097,3 +3121,71 @@ straightforward in that it sets up appropriate paths to the generated code autom
 
 Gremlin-Python
 ~~~~~~~~~~~~~~
+
+Writing a Gremlin DSL in Python simply requires direct extension of several classes:
+
+* `GraphTraversal` - which exposes the various steps used in traversal writing
+* `__` - which spawns anonymous traversals from steps
+* `GraphTraversalSource` - which spawns `GraphTraversal` instances
+
+The Social DSL based on the link:http://tinkerpop.apache.org/docs/current/images/tinkerpop-modern.png["modern" toy graph]
+might look like this:
+
+[source,python]
+----
+class SocialTraversal(GraphTraversal):
+
+    def knows(self, person_name):
+        return self.out("knows").hasLabel("person").has("name", person_name)
+
+    def youngestFriendsAge(self):
+        return self.out("knows").hasLabel("person").values("age").min()
+
+    def createdAtLeast(self, number):
+        return self.outE("created").count().is_(P.gte(number))
+
+class __(AnonymousTraversal):
+    @staticmethod
+    def knows(*args):
+        return SocialTraversal(None, None, Bytecode()).knows(*args)
+
+    @staticmethod
+    def youngestFriendsAge(*args):
+        return SocialTraversal(None, None, Bytecode()).youngestFriendsAge(*args)
+
+    @staticmethod
+    def createdAtLeast(*args):
+        return SocialTraversal(None, None, Bytecode()).createdAtLeast(*args)
+
+
+class SocialTraversalSource(GraphTraversalSource):
+
+    def __init__(self, *args, **kwargs):
+        super(SocialTraversalSource, self).__init__(*args, **kwargs)
+        self.graph_traversal = SocialTraversal
+
+    def persons(self, *args):
+        traversal = self.get_graph_traversal()
+        traversal.bytecode.add_step("V")
+        traversal.bytecode.add_step("hasLabel", "person")
+
+        if len(args) > 0:
+            traversal.bytecode.add_step("has", "name", P.within(args))
+
+        return traversal
+----
+
+NOTE: The `AnonymousTraversal` class above is just an alias for `__` as in
+`from gremlin_python.process.graph_traversal import __ as AnonymousTraversal`
+
+Using the DSL is straightforward and just requires that the graph instance know the `SocialTraversalSource` should
+be used:
+
+[source,python]
+----
+social = Graph().traversal(SocialTraversalSource).withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
+social.persons("marko").knows("josh")
+social.persons("marko").youngestFriendsAge()
+social.persons().filter(__.createdAtLeast(2)).count()
+----
+

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3142aeee/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
index b7e4f07..7f83152 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
@@ -61,7 +61,7 @@ public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
      *
      * @param number the minimum number of projects a person created
      */
-    public default GraphTraversal<S,Long> createdAtLeast(int number) {
+    public default GraphTraversal<S, Long> createdAtLeast(int number) {
         return outE("created").count().is(P.gte(number));
     }
 }


[03/45] tinkerpop git commit: added basic pattern for gremlin-python dsl development

Posted by sp...@apache.org.
added basic pattern for gremlin-python dsl development


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e0dc97d0
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e0dc97d0
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e0dc97d0

Branch: refs/heads/tp32-glv
Commit: e0dc97d0d8337f8808807b1dbf218202e2b0cced
Parents: 2d574fb
Author: davebshow <da...@gmail.com>
Authored: Mon May 8 17:47:37 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../python/GraphTraversalSourceGenerator.groovy | 13 +++--
 .../gremlin_python/process/graph_traversal.py   | 29 ++++++-----
 .../jython/gremlin_python/structure/graph.py    |  6 ++-
 .../src/main/jython/tests/process/test_dsl.py   | 54 ++++++++++++++++++++
 4 files changed, 84 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e0dc97d0/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy b/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
index 1c66c35..c2e733f 100644
--- a/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
+++ b/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
@@ -75,8 +75,13 @@ under the License.
     if bytecode is None:
       bytecode = Bytecode()
     self.bytecode = bytecode
+    self.graph_traversal = GraphTraversal
   def __repr__(self):
     return "graphtraversalsource[" + str(self.graph) + "]"
+  def get_graph_traversal_source(self):
+    return self.__class__(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+  def get_graph_traversal(self):
+    return self.graph_traversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
 """)
         GraphTraversalSource.getMethods(). // SOURCE STEPS
                 findAll { GraphTraversalSource.class.equals(it.returnType) }.
@@ -92,14 +97,14 @@ under the License.
                 forEach { method ->
                     pythonClass.append(
                             """  def ${method}(self, *args):
-    source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+    source = self.get_graph_traversal_source()
     source.bytecode.add_source("${SymbolHelper.toJava(method)}", *args)
     return source
 """)
                 }
         pythonClass.append(
                 """  def withRemote(self, remote_connection):
-    source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+    source = self.get_graph_traversal_source()
     source.traversal_strategies.add_strategies([RemoteStrategy(remote_connection)])
     return source
   def withComputer(self,graph_computer=None, workers=None, result=None, persist=None, vertices=None, edges=None, configuration=None):
@@ -113,7 +118,7 @@ under the License.
                 forEach { method ->
                     pythonClass.append(
                             """  def ${method}(self, *args):
-    traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
+    traversal = self.get_graph_traversal()
     traversal.bytecode.add_step("${SymbolHelper.toJava(method)}", *args)
     return traversal
 """)
@@ -126,7 +131,7 @@ under the License.
         pythonClass.append(
                 """class GraphTraversal(Traversal):
   def __init__(self, graph, traversal_strategies, bytecode):
-    Traversal.__init__(self, graph, traversal_strategies, bytecode)
+    super(GraphTraversal, self).__init__(graph, traversal_strategies, bytecode)
   def __getitem__(self, index):
     if isinstance(index, int):
         return self.range(long(index), long(index + 1))

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e0dc97d0/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
index e722215..ef49443 100644
--- a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
+++ b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
@@ -32,59 +32,64 @@ class GraphTraversalSource(object):
     if bytecode is None:
       bytecode = Bytecode()
     self.bytecode = bytecode
+    self.graph_traversal = GraphTraversal
   def __repr__(self):
     return "graphtraversalsource[" + str(self.graph) + "]"
+  def get_graph_traversal_source(self):
+    return self.__class__(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+  def get_graph_traversal(self):
+    return self.graph_traversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
   def withBulk(self, *args):
-    source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+    source = self.get_graph_traversal_source()
     source.bytecode.add_source("withBulk", *args)
     return source
   def withPath(self, *args):
-    source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+    source = self.get_graph_traversal_source()
     source.bytecode.add_source("withPath", *args)
     return source
   def withSack(self, *args):
-    source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+    source = self.get_graph_traversal_source()
     source.bytecode.add_source("withSack", *args)
     return source
   def withSideEffect(self, *args):
-    source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+    source = self.get_graph_traversal_source()
     source.bytecode.add_source("withSideEffect", *args)
     return source
   def withStrategies(self, *args):
-    source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+    source = self.get_graph_traversal_source()
     source.bytecode.add_source("withStrategies", *args)
     return source
   def withoutStrategies(self, *args):
-    source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+    source = self.get_graph_traversal_source()
     source.bytecode.add_source("withoutStrategies", *args)
     return source
   def withRemote(self, remote_connection):
-    source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+    source = self.get_graph_traversal_source()
     source.traversal_strategies.add_strategies([RemoteStrategy(remote_connection)])
     return source
   def withComputer(self,graph_computer=None, workers=None, result=None, persist=None, vertices=None, edges=None, configuration=None):
     return self.withStrategies(VertexProgramStrategy(graph_computer,workers,result,persist,vertices,edges,configuration))
   def E(self, *args):
-    traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
+    traversal = self.get_graph_traversal()
     traversal.bytecode.add_step("E", *args)
     return traversal
   def V(self, *args):
-    traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
+    traversal = self.get_graph_traversal()
     traversal.bytecode.add_step("V", *args)
     return traversal
   def addV(self, *args):
-    traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
+    traversal = self.get_graph_traversal()
     traversal.bytecode.add_step("addV", *args)
     return traversal
   def inject(self, *args):
-    traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
+    traversal = self.get_graph_traversal()
     traversal.bytecode.add_step("inject", *args)
     return traversal
 
 
 class GraphTraversal(Traversal):
   def __init__(self, graph, traversal_strategies, bytecode):
-    Traversal.__init__(self, graph, traversal_strategies, bytecode)
+    super(GraphTraversal, self).__init__(graph, traversal_strategies, bytecode)
   def __getitem__(self, index):
     if isinstance(index, int):
         return self.range(long(index), long(index + 1))

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e0dc97d0/gremlin-python/src/main/jython/gremlin_python/structure/graph.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/graph.py b/gremlin-python/src/main/jython/gremlin_python/structure/graph.py
index d77cde1..7089dad 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/graph.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/graph.py
@@ -28,8 +28,10 @@ class Graph(object):
         if self.__class__ not in TraversalStrategies.global_cache:
             TraversalStrategies.global_cache[self.__class__] = TraversalStrategies()
 
-    def traversal(self):
-        return GraphTraversalSource(self, TraversalStrategies.global_cache[self.__class__])
+    def traversal(self, traversal_source_class=None):
+        if not traversal_source_class:
+            traversal_source_class = GraphTraversalSource
+        return traversal_source_class(self, TraversalStrategies.global_cache[self.__class__])
 
     def __repr__(self):
         return "graph[empty]"

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e0dc97d0/gremlin-python/src/main/jython/tests/process/test_dsl.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/process/test_dsl.py b/gremlin-python/src/main/jython/tests/process/test_dsl.py
new file mode 100644
index 0000000..ece81dc
--- /dev/null
+++ b/gremlin-python/src/main/jython/tests/process/test_dsl.py
@@ -0,0 +1,54 @@
+'''
+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.
+'''
+import pytest
+
+from gremlin_python.process.graph_traversal import (
+    GraphTraversalSource, GraphTraversal)
+from gremlin_python.structure.graph import Graph
+
+__author__ = 'David M. Brown (davebshow@gmail.com)'
+
+
+class SocialTraversalDsl(GraphTraversal):
+
+    def knows(self, person_name):
+        return self.out("knows").hasLabel("person").has("name", person_name)
+
+    def youngestFriendsAge(self):
+        return self.out("knows").hasLabel("person").values("age").min()
+
+
+class SocialTraversalSourceDsl(GraphTraversalSource):
+
+    def __init__(self, *args, **kwargs):
+        super(SocialTraversalSourceDsl, self).__init__(*args, **kwargs)
+        self.graph_traversal = SocialTraversalDsl
+
+    def persons(self):
+        traversal = self.get_graph_traversal()
+        traversal.bytecode.add_step("V")
+        traversal.bytecode.add_step("hasLabel", "person")
+        return traversal
+
+
+def test_dsl(remote_connection):
+    social = Graph().traversal(SocialTraversalSourceDsl).withRemote(remote_connection)
+    assert social.V().has("name", "marko").knows("josh").next()
+    assert social.V().has("name", "marko").youngestFriendsAge().next() == 27
+    assert social.persons().count().next() == 4


[37/45] tinkerpop git commit: TINKERPOP-1675 Throw underlying unchecked exception in processNextStart

Posted by sp...@apache.org.
TINKERPOP-1675 Throw underlying unchecked exception in processNextStart

For consistency with previous behavior, if an unchecked exception is
set on the returned future throw that instead of the wrapped
CompletionException.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6813e9ef
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6813e9ef
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6813e9ef

Branch: refs/heads/tp32-glv
Commit: 6813e9efd86a4d032d3106000fb5e805deb26454
Parents: afa3432
Author: Andrew Tolbert <an...@datastax.com>
Authored: Mon May 22 12:14:15 2017 -0500
Committer: Andrew Tolbert <an...@datastax.com>
Committed: Mon May 22 12:20:27 2017 -0500

----------------------------------------------------------------------
 .../remote/traversal/step/map/RemoteStep.java    | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6813e9ef/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/step/map/RemoteStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/step/map/RemoteStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/step/map/RemoteStep.java
index 3e19097..8f7d12b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/step/map/RemoteStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/step/map/RemoteStep.java
@@ -30,6 +30,7 @@ import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 
 import java.util.NoSuchElementException;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
@@ -57,7 +58,23 @@ public final class RemoteStep<S, E> extends AbstractStep<S, E> {
 
     @Override
     protected Traverser.Admin<E> processNextStart() throws NoSuchElementException {
-        if (null == this.remoteTraversal) promise().join();
+        if (null == this.remoteTraversal) {
+            try {
+                promise().join();
+            } catch (CompletionException e) {
+                Throwable cause = e.getCause();
+                // If the underlying future failed, join() will throw a CompletionException, for consistency
+                // with previous behavior:
+                // - Throw underlying exception if it was unchecked (RuntimeException or Error).
+                // - Wrap in IllegalStateException otherwise.
+                if (cause instanceof RuntimeException) {
+                    throw (RuntimeException) cause;
+                } else if (cause instanceof Error) {
+                    throw (Error) cause;
+                }
+                throw new IllegalStateException(cause);
+            }
+        }
         return this.remoteTraversal.nextTraverser();
     }
 


[27/45] tinkerpop git commit: TINKERPOP-786 Minor change to imports for python DSL example

Posted by sp...@apache.org.
TINKERPOP-786 Minor change to imports for python DSL example


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/628ef6e0
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/628ef6e0
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/628ef6e0

Branch: refs/heads/tp32-glv
Commit: 628ef6e02c59adc213335083324792ac2d571b0e
Parents: 5e09caf
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu May 11 10:06:17 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:31 2017 -0400

----------------------------------------------------------------------
 gremlin-python/src/main/jython/tests/process/test_dsl.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/628ef6e0/gremlin-python/src/main/jython/tests/process/test_dsl.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/process/test_dsl.py b/gremlin-python/src/main/jython/tests/process/test_dsl.py
index 04313ab..0652cbb 100644
--- a/gremlin-python/src/main/jython/tests/process/test_dsl.py
+++ b/gremlin-python/src/main/jython/tests/process/test_dsl.py
@@ -20,7 +20,8 @@ import pytest
 
 from gremlin_python.process.traversal import (Bytecode, P)
 from gremlin_python.process.graph_traversal import (
-    GraphTraversalSource, GraphTraversal, __)
+    GraphTraversalSource, GraphTraversal)
+from gremlin_python.process.graph_traversal import __ as AnonymousTraversal
 from gremlin_python.structure.graph import Graph
 
 __author__ = 'David M. Brown (davebshow@gmail.com)'
@@ -37,7 +38,7 @@ class SocialTraversal(GraphTraversal):
     def createdAtLeast(self, number):
         return self.outE("created").count().is_(P.gte(number))
 
-class ___(__):
+class __(AnonymousTraversal):
     @staticmethod
     def knows(*args):
         return SocialTraversal(None, None, Bytecode()).knows(*args)
@@ -74,4 +75,4 @@ def test_dsl(remote_connection):
     assert social.persons("marko").youngestFriendsAge().next() == 27
     assert social.persons().count().next() == 4
     assert social.persons("marko", "josh").count().next() == 2
-    assert social.persons().filter(___.createdAtLeast(2)).count().next() == 1
+    assert social.persons().filter(__.createdAtLeast(2)).count().next() == 1


[40/45] tinkerpop git commit: TINKERPOP-1653 Fixed multiple -e script execution in Console

Posted by sp...@apache.org.
TINKERPOP-1653 Fixed multiple -e script execution in Console

Added tests - not sure why these weren't there before.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/7bf68835
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/7bf68835
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/7bf68835

Branch: refs/heads/tp32-glv
Commit: 7bf688350251f64247a71c39900fa015c59eb35b
Parents: 7ea3875
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu May 25 06:45:12 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu May 25 06:45:12 2017 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/console/Console.groovy    |  6 ++---
 .../src/test/python/tests/test_console.py       | 25 ++++++++++++++++----
 .../src/test/python/x-printed.script            | 21 ++++++++++++++++
 gremlin-console/src/test/python/x.groovy        | 20 ----------------
 gremlin-console/src/test/python/x.script        | 20 ++++++++++++++++
 .../src/test/python/y-printed.script            | 21 ++++++++++++++++
 gremlin-console/src/test/python/y.groovy        | 20 ----------------
 gremlin-console/src/test/python/y.script        | 20 ++++++++++++++++
 .../src/test/python/z-printed.script            | 21 ++++++++++++++++
 gremlin-console/src/test/python/z.groovy        | 20 ----------------
 gremlin-console/src/test/python/z.script        | 20 ++++++++++++++++
 11 files changed, 147 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7bf68835/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index 393f1f2..3bdc8a1 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -365,7 +365,7 @@ class Console {
     }
 
     private void executeInShell(final List<List<String>> scriptsAndArgs) {
-        scriptsAndArgs.each { scriptAndArgs ->
+        scriptsAndArgs.eachWithIndex { scriptAndArgs, idx ->
             final String scriptFile = scriptAndArgs[0]
             try {
                 // check if this script comes with arguments. if so then set them up in an "args" bundle
@@ -400,8 +400,6 @@ class Console {
 
                     }
                 }
-
-                if (!interactive) System.exit(0)
             } catch (FileNotFoundException ignored) {
                 io.err.println(Colorizer.render(Preferences.errorColor, "Gremlin file not found at [$scriptFile]."))
                 if (!interactive) System.exit(1)
@@ -410,6 +408,8 @@ class Console {
                 if (!interactive) System.exit(1)
             }
         }
+
+        if (!interactive) System.exit(0)
     }
 
     public static void main(final String[] args) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7bf68835/gremlin-console/src/test/python/tests/test_console.py
----------------------------------------------------------------------
diff --git a/gremlin-console/src/test/python/tests/test_console.py b/gremlin-console/src/test/python/tests/test_console.py
index f079291..407b563 100644
--- a/gremlin-console/src/test/python/tests/test_console.py
+++ b/gremlin-console/src/test/python/tests/test_console.py
@@ -34,7 +34,7 @@ class TestConsole(object):
         TestConsole._close(child)
 
     def test_just_dash_i(self):
-        child = pexpect.spawn(TestConsole.gremlinsh + "-i x.groovy")
+        child = pexpect.spawn(TestConsole.gremlinsh + "-i x.script")
         TestConsole._expect_gremlin_header(child)
         TestConsole._send(child, "x")
         child.expect("==>2\r\n")
@@ -42,7 +42,7 @@ class TestConsole(object):
         TestConsole._close(child)
 
     def test_dash_i_with_args(self):
-        child = pexpect.spawn(TestConsole.gremlinsh + "-i y.groovy 1 2 3")
+        child = pexpect.spawn(TestConsole.gremlinsh + "-i y.script 1 2 3")
         TestConsole._expect_gremlin_header(child)
         TestConsole._send(child, "y")
         child.expect("==>6\r\n")
@@ -50,7 +50,7 @@ class TestConsole(object):
         TestConsole._close(child)
 
     def test_dash_i_multiple_scripts(self):
-        child = pexpect.spawn(TestConsole.gremlinsh + "-i y.groovy 1 2 3 -i x.groovy -i \"z.groovy x -i --color -D\"")
+        child = pexpect.spawn(TestConsole.gremlinsh + "-i y.script 1 2 3 -i x.script -i \"z.script x -i --color -D\"")
         TestConsole._expect_gremlin_header(child)
         TestConsole._send(child, "y")
         child.expect("==>6\r\n")
@@ -63,8 +63,25 @@ class TestConsole(object):
         TestConsole._expect_prompt(child)
         TestConsole._close(child)
 
+    def test_just_dash_e(self):
+        child = pexpect.spawn(TestConsole.gremlinsh + "-e x-printed.script")
+        child.expect("2\r\n")
+        TestConsole._close(child)
+
+    def test_dash_e_with_args(self):
+        child = pexpect.spawn(TestConsole.gremlinsh + "-e y-printed.script 1 2 3")
+        child.expect("6\r\n")
+        TestConsole._close(child)
+
+    def test_dash_e_multiple_scripts(self):
+        child = pexpect.spawn(TestConsole.gremlinsh + "-e y-printed.script 1 2 3 -e x-printed.script -e \"z-printed.script x -e --color -D\"")
+        child.expect("6\r\n")
+        child.expect("2\r\n")
+        child.expect("argument=\[x, -e, --color, -D\]\r\n")
+        TestConsole._close(child)
+
     def test_no_mix_dash_i_and_dash_e(self):
-        child = pexpect.spawn(TestConsole.gremlinsh + "-i y.groovy 1 2 3 -i x.groovy -e \"z.groovy x -i --color -D\"")
+        child = pexpect.spawn(TestConsole.gremlinsh + "-i y.script 1 2 3 -i x.script -e \"z.script x -i --color -D\"")
         child.expect("-i and -e options are mutually exclusive - provide one or the other")
         child.expect(pexpect.EOF)
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7bf68835/gremlin-console/src/test/python/x-printed.script
----------------------------------------------------------------------
diff --git a/gremlin-console/src/test/python/x-printed.script b/gremlin-console/src/test/python/x-printed.script
new file mode 100644
index 0000000..9be57a5
--- /dev/null
+++ b/gremlin-console/src/test/python/x-printed.script
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+x = 1 + 1
+println x
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7bf68835/gremlin-console/src/test/python/x.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/test/python/x.groovy b/gremlin-console/src/test/python/x.groovy
deleted file mode 100644
index 31a9f19..0000000
--- a/gremlin-console/src/test/python/x.groovy
+++ /dev/null
@@ -1,20 +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.
- */
-
-x = 1 + 1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7bf68835/gremlin-console/src/test/python/x.script
----------------------------------------------------------------------
diff --git a/gremlin-console/src/test/python/x.script b/gremlin-console/src/test/python/x.script
new file mode 100644
index 0000000..31a9f19
--- /dev/null
+++ b/gremlin-console/src/test/python/x.script
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+x = 1 + 1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7bf68835/gremlin-console/src/test/python/y-printed.script
----------------------------------------------------------------------
diff --git a/gremlin-console/src/test/python/y-printed.script b/gremlin-console/src/test/python/y-printed.script
new file mode 100644
index 0000000..e297186
--- /dev/null
+++ b/gremlin-console/src/test/python/y-printed.script
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+y = args.collect{Integer.parseInt(it)}.sum()
+println y
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7bf68835/gremlin-console/src/test/python/y.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/test/python/y.groovy b/gremlin-console/src/test/python/y.groovy
deleted file mode 100644
index 8b0adf6..0000000
--- a/gremlin-console/src/test/python/y.groovy
+++ /dev/null
@@ -1,20 +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.
- */
-
-y = args.collect{Integer.parseInt(it)}.sum()
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7bf68835/gremlin-console/src/test/python/y.script
----------------------------------------------------------------------
diff --git a/gremlin-console/src/test/python/y.script b/gremlin-console/src/test/python/y.script
new file mode 100644
index 0000000..8b0adf6
--- /dev/null
+++ b/gremlin-console/src/test/python/y.script
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+y = args.collect{Integer.parseInt(it)}.sum()
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7bf68835/gremlin-console/src/test/python/z-printed.script
----------------------------------------------------------------------
diff --git a/gremlin-console/src/test/python/z-printed.script b/gremlin-console/src/test/python/z-printed.script
new file mode 100644
index 0000000..676542a
--- /dev/null
+++ b/gremlin-console/src/test/python/z-printed.script
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+z = "argument=" + args
+println z
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7bf68835/gremlin-console/src/test/python/z.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/test/python/z.groovy b/gremlin-console/src/test/python/z.groovy
deleted file mode 100644
index 3d7d101..0000000
--- a/gremlin-console/src/test/python/z.groovy
+++ /dev/null
@@ -1,20 +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.
- */
-
-z = "argument=" + args
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7bf68835/gremlin-console/src/test/python/z.script
----------------------------------------------------------------------
diff --git a/gremlin-console/src/test/python/z.script b/gremlin-console/src/test/python/z.script
new file mode 100644
index 0000000..3d7d101
--- /dev/null
+++ b/gremlin-console/src/test/python/z.script
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+z = "argument=" + args
\ No newline at end of file


[05/45] tinkerpop git commit: TINKERPOP-786 Refactored settings extraction for DSL generation

Posted by sp...@apache.org.
TINKERPOP-786 Refactored settings extraction for DSL generation


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/06d6d138
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/06d6d138
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/06d6d138

Branch: refs/heads/tp32-glv
Commit: 06d6d1383cec53e3f16f7c8435607422dcd4d8e7
Parents: 5ae3497
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 27 14:52:07 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../traversal/dsl/GremlinDslProcessor.java      | 125 ++++++++++---------
 1 file changed, 69 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/06d6d138/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index f2c89e7..d96ae01 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -26,7 +26,6 @@ import com.squareup.javapoet.ParameterizedTypeName;
 import com.squareup.javapoet.TypeName;
 import com.squareup.javapoet.TypeSpec;
 import com.squareup.javapoet.TypeVariableName;
-import jdk.nashorn.internal.codegen.types.Type;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
@@ -50,7 +49,6 @@ import javax.lang.model.element.ElementKind;
 import javax.lang.model.element.ExecutableElement;
 import javax.lang.model.element.Modifier;
 import javax.lang.model.element.TypeElement;
-import javax.lang.model.element.TypeParameterElement;
 import javax.lang.model.element.VariableElement;
 import javax.lang.model.type.DeclaredType;
 import javax.lang.model.type.TypeKind;
@@ -90,55 +88,40 @@ public class GremlinDslProcessor extends AbstractProcessor {
         try {
             for (Element dslElement : roundEnv.getElementsAnnotatedWith(GremlinDsl.class)) {
                 validateDSL(dslElement);
-
-                // gets the annotation on the dsl class/interface
-                GremlinDsl gremlinDslAnnotation = dslElement.getAnnotation(GremlinDsl.class);
-
                 final TypeElement annotatedDslType = (TypeElement) dslElement;
-                final String packageName = getPackageName(dslElement, gremlinDslAnnotation);
-
-                // create the Traversal implementation interface
-                final String dslName = dslElement.getSimpleName().toString();
-                final String dslPrefix = dslName.substring(0, dslName.length() - "TraversalDSL".length()); // chop off "TraversalDSL"
-                final String traversalClazz = dslPrefix + "Traversal";
-                final ClassName traversalClassName = ClassName.get(packageName, traversalClazz);
-                final String traversalSourceClazz = dslPrefix + "TraversalSource";
-                final ClassName traversalSourceClassName = ClassName.get(packageName, traversalSourceClazz);
-                final String defaultTraversalClazz = "Default" + traversalClazz;
-                final ClassName defaultTraversalClassName = ClassName.get(packageName, defaultTraversalClazz);
-                final ClassName graphTraversalAdminClassName = ClassName.get(GraphTraversal.Admin.class);
+                final Context ctx = new Context(annotatedDslType);
 
                 // START write "Traversal" class
-                final TypeSpec.Builder traversalInterface = TypeSpec.interfaceBuilder(traversalClazz)
+                final TypeSpec.Builder traversalInterface = TypeSpec.interfaceBuilder(ctx.traversalClazz)
                         .addModifiers(Modifier.PUBLIC)
                         .addTypeVariables(Arrays.asList(TypeVariableName.get("S"), TypeVariableName.get("E")))
                         .addSuperinterface(TypeName.get(dslElement.asType()));
 
                 // process the methods of the GremlinDsl annotated class
                 for (Element elementOfDsl : annotatedDslType.getEnclosedElements()) {
-                    tryConstructMethod(elementOfDsl, traversalClassName, dslName, null,
+                    tryConstructMethod(elementOfDsl, ctx.traversalClassName, ctx.dslName, null,
                             Modifier.PUBLIC, Modifier.DEFAULT).ifPresent(traversalInterface::addMethod);
                 }
 
                 // process the methods of GraphTraversal
                 final TypeElement graphTraversalElement = elementUtils.getTypeElement(GraphTraversal.class.getCanonicalName());
                 for (Element elementOfGraphTraversal : graphTraversalElement.getEnclosedElements()) {
-                    tryConstructMethod(elementOfGraphTraversal, traversalClassName, dslName,
+                    tryConstructMethod(elementOfGraphTraversal, ctx.traversalClassName, ctx.dslName,
                             e -> e.getSimpleName().contentEquals("asAdmin") || e.getSimpleName().contentEquals("iterate"),
                             Modifier.PUBLIC, Modifier.DEFAULT)
                             .ifPresent(traversalInterface::addMethod);
                 }
 
-                final JavaFile traversalJavaFile = JavaFile.builder(packageName, traversalInterface.build()).build();
+                final JavaFile traversalJavaFile = JavaFile.builder(ctx.packageName, traversalInterface.build()).build();
                 traversalJavaFile.writeTo(filer);
                 // END write "Traversal" class
 
                 // START write of the "DefaultTraversal" class
-                final TypeSpec.Builder defaultTraversalClass = TypeSpec.classBuilder(defaultTraversalClazz)
+                final TypeSpec.Builder defaultTraversalClass = TypeSpec.classBuilder(ctx.defaultTraversalClazz)
                         .addModifiers(Modifier.PUBLIC)
                         .addTypeVariables(Arrays.asList(TypeVariableName.get("S"), TypeVariableName.get("E")))
                         .superclass(TypeName.get(elementUtils.getTypeElement(DefaultTraversal.class.getCanonicalName()).asType()))
-                        .addSuperinterface(ParameterizedTypeName.get(traversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")));
+                        .addSuperinterface(ParameterizedTypeName.get(ctx.traversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")));
 
                 // add the required constructors for instantiation
                 defaultTraversalClass.addMethod(MethodSpec.constructorBuilder()
@@ -152,7 +135,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
                         .build());
                 defaultTraversalClass.addMethod(MethodSpec.constructorBuilder()
                         .addModifiers(Modifier.PUBLIC)
-                        .addParameter(traversalSourceClassName, "traversalSource")
+                        .addParameter(ctx.traversalSourceClassName, "traversalSource")
                         .addStatement("super($N)", "traversalSource")
                         .build());
 
@@ -160,29 +143,29 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 defaultTraversalClass.addMethod(MethodSpec.methodBuilder("iterate")
                         .addModifiers(Modifier.PUBLIC)
                         .addAnnotation(Override.class)
-                        .addStatement("return ($T) super.iterate()", traversalClassName)
-                        .returns(ParameterizedTypeName.get(traversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
+                        .addStatement("return ($T) super.iterate()", ctx.traversalClassName)
+                        .returns(ParameterizedTypeName.get(ctx.traversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
                         .build());
                 defaultTraversalClass.addMethod(MethodSpec.methodBuilder("asAdmin")
                         .addModifiers(Modifier.PUBLIC)
                         .addAnnotation(Override.class)
                         .addStatement("return ($T) super.asAdmin()", GraphTraversal.Admin.class)
-                        .returns(ParameterizedTypeName.get(graphTraversalAdminClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
+                        .returns(ParameterizedTypeName.get(ctx.graphTraversalAdminClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
                         .build());
                 defaultTraversalClass.addMethod(MethodSpec.methodBuilder("clone")
                         .addModifiers(Modifier.PUBLIC)
                         .addAnnotation(Override.class)
-                        .addStatement("return ($T) super.clone()", defaultTraversalClassName)
-                        .returns(ParameterizedTypeName.get(defaultTraversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
+                        .addStatement("return ($T) super.clone()", ctx.defaultTraversalClassName)
+                        .returns(ParameterizedTypeName.get(ctx.defaultTraversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
                         .build());
 
-                final JavaFile defaultTraversalJavaFile = JavaFile.builder(packageName, defaultTraversalClass.build()).build();
+                final JavaFile defaultTraversalJavaFile = JavaFile.builder(ctx.packageName, defaultTraversalClass.build()).build();
                 defaultTraversalJavaFile.writeTo(filer);
                 // END write of the "DefaultTraversal" class
 
                 // START write "TraversalSource" class
                 final TypeElement graphTraversalSourceElement = elementUtils.getTypeElement(GraphTraversalSource.class.getCanonicalName());
-                final TypeSpec.Builder traversalSourceClass = TypeSpec.classBuilder(traversalSourceClazz)
+                final TypeSpec.Builder traversalSourceClass = TypeSpec.classBuilder(ctx.traversalSourceClazz)
                         .addModifiers(Modifier.PUBLIC)
                         .superclass(TypeName.get(graphTraversalSourceElement.asType()));
 
@@ -203,7 +186,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 for (Element elementOfGraphTraversal : graphTraversalSourceElement.getEnclosedElements()) {
                     // first copy/override methods that return a GraphTraversalSource so that we can instead return
                     // the DSL TraversalSource class.
-                    tryConstructMethod(elementOfGraphTraversal, traversalSourceClassName, "",
+                    tryConstructMethod(elementOfGraphTraversal, ctx.traversalSourceClassName, "",
                             e -> !(e.getReturnType().getKind() == TypeKind.DECLARED && ((DeclaredType) e.getReturnType()).asElement().getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())),
                             Modifier.PUBLIC)
                             .ifPresent(traversalSourceClass::addMethod);
@@ -213,46 +196,46 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
                         .addModifiers(Modifier.PUBLIC)
                         .addAnnotation(Override.class)
-                        .addStatement("$N clone = this.clone()", traversalSourceClazz)
+                        .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
                         .addStatement("clone.bytecode.addStep($T.addV)", GraphTraversal.Symbols.class)
-                        .addStatement("$N traversal = new $N(clone)", defaultTraversalClazz, defaultTraversalClazz)
-                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, null))", traversalClassName, AddVertexStartStep.class)
-                        .returns(ParameterizedTypeName.get(traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
+                        .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
+                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, null))", ctx.traversalClassName, AddVertexStartStep.class)
+                        .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
                         .build());
                 traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
                         .addModifiers(Modifier.PUBLIC)
                         .addAnnotation(Override.class)
                         .addParameter(String.class, "label")
-                        .addStatement("$N clone = this.clone()", traversalSourceClazz)
+                        .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
                         .addStatement("clone.bytecode.addStep($T.addV, label)", GraphTraversal.Symbols.class)
-                        .addStatement("$N traversal = new $N(clone)", defaultTraversalClazz, defaultTraversalClazz)
-                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, label))", traversalClassName, AddVertexStartStep.class)
-                        .returns(ParameterizedTypeName.get(traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
+                        .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
+                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, label))", ctx.traversalClassName, AddVertexStartStep.class)
+                        .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
                         .build());
                 traversalSourceClass.addMethod(MethodSpec.methodBuilder("V")
                         .addModifiers(Modifier.PUBLIC)
                         .addAnnotation(Override.class)
                         .addParameter(Object[].class, "vertexIds")
                         .varargs(true)
-                        .addStatement("$N clone = this.clone()", traversalSourceClazz)
+                        .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
                         .addStatement("clone.bytecode.addStep($T.V, vertexIds)", GraphTraversal.Symbols.class)
-                        .addStatement("$N traversal = new $N(clone)", defaultTraversalClazz, defaultTraversalClazz)
-                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, vertexIds))", traversalClassName, GraphStep.class, Vertex.class)
-                        .returns(ParameterizedTypeName.get(traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
+                        .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
+                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, vertexIds))", ctx.traversalClassName, GraphStep.class, Vertex.class)
+                        .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
                         .build());
                 traversalSourceClass.addMethod(MethodSpec.methodBuilder("E")
                         .addModifiers(Modifier.PUBLIC)
                         .addAnnotation(Override.class)
                         .addParameter(Object[].class, "edgeIds")
                         .varargs(true)
-                        .addStatement("$N clone = this.clone()", traversalSourceClazz)
+                        .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
                         .addStatement("clone.bytecode.addStep($T.E, edgeIds)", GraphTraversal.Symbols.class)
-                        .addStatement("$N traversal = new $N(clone)", defaultTraversalClazz, defaultTraversalClazz)
-                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, edgeIds))", traversalClassName, GraphStep.class, Edge.class)
-                        .returns(ParameterizedTypeName.get(traversalClassName, ClassName.get(Edge.class), ClassName.get(Edge.class)))
+                        .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
+                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, edgeIds))", ctx.traversalClassName, GraphStep.class, Edge.class)
+                        .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Edge.class), ClassName.get(Edge.class)))
                         .build());
 
-                final JavaFile traversalSourceJavaFile = JavaFile.builder(packageName, traversalSourceClass.build()).build();
+                final JavaFile traversalSourceJavaFile = JavaFile.builder(ctx.packageName, traversalSourceClass.build()).build();
                 traversalSourceJavaFile.writeTo(filer);
                 // END write "TraversalSource" class
             }
@@ -263,12 +246,6 @@ public class GremlinDslProcessor extends AbstractProcessor {
         return true;
     }
 
-    private String getPackageName(final Element dslElement, final GremlinDsl gremlinDslAnnotation) {
-        return gremlinDslAnnotation.packageName().isEmpty() ?
-                elementUtils.getPackageOf(dslElement).getQualifiedName().toString() :
-                gremlinDslAnnotation.packageName();
-    }
-
     private Optional<MethodSpec> tryConstructMethod(final Element element, final ClassName returnClazz, final String parent,
                                                     final Predicate<ExecutableElement> ignore, final Modifier... modifiers) {
         if (element.getKind() != ElementKind.METHOD) return Optional.empty();
@@ -324,4 +301,40 @@ public class GremlinDslProcessor extends AbstractProcessor {
         if (!typeElement.getModifiers().contains(Modifier.PUBLIC))
             throw new ProcessorException(dslElement, "The interface %s is not public.", typeElement.getQualifiedName());
     }
+
+    private class Context {
+        private final String packageName;
+        private final String dslName;
+        private final String traversalClazz;
+        private final ClassName traversalClassName;
+        private final String traversalSourceClazz;
+        private final ClassName traversalSourceClassName;
+        private final String defaultTraversalClazz;
+        private final ClassName defaultTraversalClassName;
+        private final ClassName graphTraversalAdminClassName;
+
+        public Context(final TypeElement dslElement) {
+            // gets the annotation on the dsl class/interface
+            GremlinDsl gremlinDslAnnotation = dslElement.getAnnotation(GremlinDsl.class);
+
+            packageName = getPackageName(dslElement, gremlinDslAnnotation);
+
+            // create the Traversal implementation interface
+            dslName = dslElement.getSimpleName().toString();
+            final String dslPrefix = dslName.substring(0, dslName.length() - "TraversalDSL".length()); // chop off "TraversalDSL"
+            traversalClazz = dslPrefix + "Traversal";
+            traversalClassName = ClassName.get(packageName, traversalClazz);
+            traversalSourceClazz = dslPrefix + "TraversalSource";
+            traversalSourceClassName = ClassName.get(packageName, traversalSourceClazz);
+            defaultTraversalClazz = "Default" + traversalClazz;
+            defaultTraversalClassName = ClassName.get(packageName, defaultTraversalClazz);
+            graphTraversalAdminClassName = ClassName.get(GraphTraversal.Admin.class);
+        }
+
+        private String getPackageName(final Element dslElement, final GremlinDsl gremlinDslAnnotation) {
+            return gremlinDslAnnotation.packageName().isEmpty() ?
+                    elementUtils.getPackageOf(dslElement).getQualifiedName().toString() :
+                    gremlinDslAnnotation.packageName();
+        }
+    }
 }


[43/45] tinkerpop git commit: Merge branch 'TINKERPOP-786' into tp32

Posted by sp...@apache.org.
Merge branch 'TINKERPOP-786' into tp32

Conflicts:
	CHANGELOG.asciidoc


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/651c1c66
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/651c1c66
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/651c1c66

Branch: refs/heads/tp32-glv
Commit: 651c1c66e6e7d919d71519c35be251259ff9a595
Parents: 8812f85 869ba9a
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 26 06:35:42 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri May 26 06:35:42 2017 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |   2 +
 .../developer/development-environment.asciidoc  |  10 +
 .../src/reference/gremlin-applications.asciidoc |   1 +
 docs/src/reference/the-traversal.asciidoc       | 250 ++++++++
 .../upgrade/release-3.2.x-incubating.asciidoc   |  25 +-
 gremlin-archetype/gremlin-archetype-dsl/pom.xml |  44 ++
 .../META-INF/maven/archetype-metadata.xml       |  38 ++
 .../archetype-resources/README.asciidoc         |  35 ++
 .../main/resources/archetype-resources/pom.xml  |  63 ++
 .../src/main/java/SocialTraversalDsl.java       |  67 +++
 .../src/main/java/SocialTraversalSourceDsl.java |  67 +++
 .../src/test/java/SocialDslTest.java            |  60 ++
 .../projects/standard/archetype.properties      |  21 +
 .../test/resources/projects/standard/goal.txt   |   1 +
 gremlin-archetype/pom.xml                       |   1 +
 gremlin-core/pom.xml                            |  24 +
 .../process/traversal/dsl/GremlinDsl.java       |  77 +++
 .../traversal/dsl/GremlinDslProcessor.java      | 496 ++++++++++++++++
 .../traversal/dsl/ProcessorException.java       |  39 ++
 .../traversal/util/DefaultTraversal.java        |   5 +
 .../javax.annotation.processing.Processor       |   1 +
 .../traversal/dsl/GremlinDslProcessorTest.java  |  68 +++
 .../dsl/SocialPackageTraversalSourceDsl.java    |  59 ++
 .../traversal/dsl/SocialMoveTraversalDsl.java   |  37 ++
 .../dsl/SocialNoDefaultMethodsTraversalDsl.java |  37 ++
 .../dsl/SocialPackageTraversalDsl.java          |  37 ++
 .../traversal/dsl/SocialTraversalDsl.java       |  37 ++
 .../python/GraphTraversalSourceGenerator.groovy |  28 +-
 .../gremlin_python/process/graph_traversal.py   | 584 ++++++++++---------
 .../jython/gremlin_python/structure/graph.py    |   6 +-
 .../src/main/jython/tests/process/test_dsl.py   |  81 +++
 31 files changed, 1997 insertions(+), 304 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/651c1c66/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --cc CHANGELOG.asciidoc
index 31a4064,dbfe181..dd7616e
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@@ -26,8 -26,8 +26,10 @@@ image::https://raw.githubusercontent.co
  TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET)
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
 +* Improved error messaging on the `g.addV(Object...)` when passing an invalid arguments.
 +* Reduced memory usage for TinkerGraph deserialization in GraphSON by streaming vertices and edges.
+ * Added the `gremlin-archetype-dsl` to demonstrate how to structure a Maven project for a DSL.
+ * Developed and documented patterns for Domain Specific Language implementations.
  * Now using Groovy `[...]` map notation in `GroovyTranslator` instead of `new LinkedHashMap(){{ }}`.
  * Maintained type information on `Traversal.promise()`.
  * Propagated exception to `Future` instead of calling thread in `RemoteConnection`.


[22/45] tinkerpop git commit: TINKERPOP-786 Updated README for gremlin-archetype-dsl

Posted by sp...@apache.org.
TINKERPOP-786 Updated README for gremlin-archetype-dsl


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/df012d37
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/df012d37
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/df012d37

Branch: refs/heads/tp32-glv
Commit: df012d37ace790a4493831dfca6ffdaf3897b1fc
Parents: 94fe5f5
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 11:21:45 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:51 2017 -0400

----------------------------------------------------------------------
 .../src/main/resources/archetype-resources/README.asciidoc   | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/df012d37/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc
index 1e131b1..b50bdc7 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc
@@ -17,7 +17,10 @@ limitations under the License.
 Gremlin DSL
 ===========
 
-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+This is a starter project that demonstrates how a basic
+link:http://tinkerpop.apache.org/docs/${project.version}/reference/#dsl[Domain Specific Language] (DSL) project is
+structured with Java and Maven. The DSL is built to work with the TinkerPop "modern" toy graph. Please see the unit
+tests in `SocialDslTest` for actual DSL usage.
 
 Prerequisites
 -------------
@@ -29,5 +32,4 @@ Building and Running
 --------------------
 
 [source,text]
-mvn clean package
-mvn exec:java -Dexec.mainClass="${package}.App"
\ No newline at end of file
+mvn clean install
\ No newline at end of file


[29/45] tinkerpop git commit: TINKERPOP-786 Added support for anonymous traversal generation

Posted by sp...@apache.org.
TINKERPOP-786 Added support for anonymous traversal generation


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e0505d12
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e0505d12
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e0505d12

Branch: refs/heads/tp32-glv
Commit: e0505d1243f31789514ebc315ee19ee3568470a8
Parents: 5c7f0cb
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 16:43:00 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:31 2017 -0400

----------------------------------------------------------------------
 docs/src/reference/the-traversal.asciidoc       |   1 +
 .../src/main/java/SocialTraversalDsl.java       |  10 ++
 .../src/test/java/SocialDslTest.java            |   6 +
 .../process/traversal/dsl/GremlinDsl.java       |   1 +
 .../traversal/dsl/GremlinDslProcessor.java      | 133 ++++++++++++++++++-
 5 files changed, 147 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e0505d12/docs/src/reference/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/the-traversal.asciidoc b/docs/src/reference/the-traversal.asciidoc
index 1be365d..7da4015 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -3027,6 +3027,7 @@ The annotation processor will generate several classes for the DSL:
 interfaces (such as `GraphTraversal`) to instead return a `SocialTraversal`
 * `DefaultSocialTraversal` - A default implementation of `SocialTraversal` (typically not used directly by the user)
 * `SocialTraversalSource` - Spawns `DefaultSocialTraversal` instances.
+* `__` - Spawns anonymous `DefaultSocialTraversal` instances.
 
 Using the DSL then just involves telling the `Graph` to use it:
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e0505d12/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
index af1f039..b7e4f07 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
@@ -22,6 +22,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDsl;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
 
 /**
  * This Social DSL is meant to be used with the TinkerPop "modern" toy graph.
@@ -54,4 +55,13 @@ public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
     public default <E2 extends Number> GraphTraversal<S, E2> youngestFriendsAge() {
         return out("knows").hasLabel("person").values("age").min();
     }
+
+    /**
+     * Designed to be used as a filter for "person" vertices based on the number of "created" edges encountered.
+     *
+     * @param number the minimum number of projects a person created
+     */
+    public default GraphTraversal<S,Long> createdAtLeast(int number) {
+        return outE("created").count().is(P.gte(number));
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e0505d12/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
index 5967244..7f76558 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
@@ -51,4 +51,10 @@ public class SocialDslTest {
         SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
         assertEquals(4, social.persons().count().next().intValue());
     }
+
+    @Test
+    public void shouldFindAllPersonsWithTwoOrMoreProjects() {
+        SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
+        assertEquals(1, social.persons().filter(__.createdAtLeast(2)).count().next().intValue());
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e0505d12/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
index df96007..d3a807f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
@@ -38,6 +38,7 @@ import java.lang.annotation.Target;
  *     <li>{@code SocialTraversal} - an interface that is an extension to {@code SocialTraversalDsl}</li>
  *     <li>{@code DefaultSocialTraversal} - an implementation of the {@code SocialTraversal}</li>
  *     <li>{@code SocialTraversalSource} - an extension of {@link GraphTraversalSource} which spawns {@code DefaultSocialTraversal} instances</li>
+ *     <li>{@code __} - which spawns anonymous {@code DefaultSocialTraversal} instances</li>
  * </ul>
  *
  * Together these generated classes provide all the infrastructure required to properly Gremlin traversals enhanced

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e0505d12/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index e246765..04e59b4 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -29,6 +29,7 @@ import com.squareup.javapoet.TypeVariableName;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
 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.step.map.AddVertexStartStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep;
 import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal;
@@ -53,6 +54,7 @@ import javax.lang.model.element.VariableElement;
 import javax.lang.model.type.DeclaredType;
 import javax.lang.model.type.TypeKind;
 import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVariable;
 import javax.lang.model.util.Elements;
 import javax.lang.model.util.Types;
 import javax.tools.Diagnostic;
@@ -104,6 +106,9 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 // create the "TraversalSource" class which is used to spawn traversals from a Graph instance. It will
                 // spawn instances of the "DefaultTraversal" generated above.
                 generateTraversalSource(ctx);
+
+                // create anonymous traversal for DSL
+                generateAnonymousTraversal(ctx);
             }
         } catch (Exception ex) {
             messager.printMessage(Diagnostic.Kind.ERROR, ex.getMessage());
@@ -112,6 +117,126 @@ public class GremlinDslProcessor extends AbstractProcessor {
         return true;
     }
 
+    private void generateAnonymousTraversal(final Context ctx) throws IOException {
+        final TypeSpec.Builder anonymousClass = TypeSpec.classBuilder("__")
+                .addModifiers(Modifier.PUBLIC, Modifier.FINAL);
+
+        // this class is just static methods - it should not be instantiated
+        anonymousClass.addMethod(MethodSpec.constructorBuilder()
+                .addModifiers(Modifier.PRIVATE)
+                .build());
+
+        // add start() method
+        anonymousClass.addMethod(MethodSpec.methodBuilder("start")
+                .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+                .addTypeVariable(TypeVariableName.get("A"))
+                .addStatement("return new $N<>()", ctx.defaultTraversalClazz)
+                .returns(ParameterizedTypeName.get(ctx.traversalClassName, TypeVariableName.get("A"), TypeVariableName.get("A")))
+                .build());
+
+        // process the methods of the GremlinDsl annotated class
+        for (Element element : ctx.annotatedDslType.getEnclosedElements()) {
+            if (element.getKind() != ElementKind.METHOD) continue;
+
+            final ExecutableElement templateMethod = (ExecutableElement) element;
+            final String methodName = templateMethod.getSimpleName().toString();
+
+            final TypeName returnType = getReturnTypeDefinition(ctx.traversalClassName, templateMethod);
+            final MethodSpec.Builder methodToAdd = MethodSpec.methodBuilder(methodName)
+                    .addModifiers(Modifier.STATIC, Modifier.PUBLIC)
+                    .addExceptions(templateMethod.getThrownTypes().stream().map(TypeName::get).collect(Collectors.toList()))
+                    .returns(returnType);
+
+            templateMethod.getTypeParameters().forEach(tp -> methodToAdd.addTypeVariable(TypeVariableName.get(tp)));
+
+            // might have to deal with an "S" (in __ it's usually an "A") - how to make this less bound to that convention?
+            final DeclaredType returnTypeMirror = (DeclaredType) templateMethod.getReturnType();
+            final List<? extends TypeMirror> returnTypeArguments = returnTypeMirror.getTypeArguments();
+            returnTypeArguments.stream().filter(rtm -> rtm instanceof TypeVariable).forEach(rtm -> {
+                if (((TypeVariable) rtm).asElement().getSimpleName().contentEquals("S"))
+                    methodToAdd.addTypeVariable(TypeVariableName.get(((TypeVariable) rtm).asElement().getSimpleName().toString()));
+            });
+
+            boolean added = false;
+            final List<? extends VariableElement> parameters = templateMethod.getParameters();
+            String body = "return __.<S>start().$L(";
+            for (VariableElement param : parameters) {
+                methodToAdd.addParameter(ParameterSpec.get(param));
+
+                body = body + param.getSimpleName() + ",";
+                added = true;
+            }
+
+            // treat a final array as a varargs param
+            if (!parameters.isEmpty() && parameters.get(parameters.size() - 1).asType().getKind() == TypeKind.ARRAY)
+                methodToAdd.varargs(true);
+
+            if (added) body = body.substring(0, body.length() - 1);
+
+            body = body + ")";
+
+            methodToAdd.addStatement(body, methodName);
+
+            anonymousClass.addMethod(methodToAdd.build());
+        }
+
+        // use methods from __ to template them into the DSL __
+        final Element anonymousTraversal = elementUtils.getTypeElement(__.class.getCanonicalName());
+        for (Element element : anonymousTraversal.getEnclosedElements()) {
+            if (element.getKind() != ElementKind.METHOD) continue;
+
+            final ExecutableElement templateMethod = (ExecutableElement) element;
+            final String methodName = templateMethod.getSimpleName().toString();
+
+            // ignore start() from __ - that's not proxied
+            if (methodName.equals("start")) continue;
+
+            final TypeName returnType = getReturnTypeDefinition(ctx.traversalClassName, templateMethod);
+            final MethodSpec.Builder methodToAdd = MethodSpec.methodBuilder(methodName)
+                    .addModifiers(Modifier.STATIC, Modifier.PUBLIC)
+                    .addExceptions(templateMethod.getThrownTypes().stream().map(TypeName::get).collect(Collectors.toList()))
+                    .returns(returnType);
+
+            templateMethod.getTypeParameters().forEach(tp -> methodToAdd.addTypeVariable(TypeVariableName.get(tp)));
+
+            boolean added = false;
+            final List<? extends VariableElement> parameters = templateMethod.getParameters();
+            String body;
+            if (methodName.equals("__")) {
+                for (VariableElement param : parameters) {
+                    methodToAdd.addParameter(ParameterSpec.get(param));
+                }
+
+                methodToAdd.varargs(true);
+
+                body = "return inject(starts)";
+            } else {
+                body = "return __.<A>start().$L(";
+                for (VariableElement param : parameters) {
+                    methodToAdd.addParameter(ParameterSpec.get(param));
+
+                    body = body + param.getSimpleName() + ",";
+                    added = true;
+                }
+
+                // treat a final array as a varargs param
+                if (!parameters.isEmpty() && parameters.get(parameters.size() - 1).asType().getKind() == TypeKind.ARRAY)
+                    methodToAdd.varargs(true);
+
+                if (added) body = body.substring(0, body.length() - 1);
+
+                body = body + ")";
+            }
+
+            methodToAdd.addStatement(body, methodName);
+
+            anonymousClass.addMethod(methodToAdd.build());
+        }
+
+        final JavaFile traversalSourceJavaFile = JavaFile.builder(ctx.packageName, anonymousClass.build()).build();
+        traversalSourceJavaFile.writeTo(filer);
+    }
+
     private void generateTraversalSource(final Context ctx) throws IOException {
         final TypeElement graphTraversalSourceElement = ctx.traversalSourceDslType;
         final TypeSpec.Builder traversalSourceClass = TypeSpec.classBuilder(ctx.traversalSourceClazz)
@@ -132,7 +257,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 .build());
 
         // override methods to return a the DSL TraversalSource. find GraphTraversalSource class somewhere in the hierarchy
-        final Element tinkerPopsGraphTraversalSource = findTinkerPopsGraphTraversalSource(graphTraversalSourceElement);
+        final Element tinkerPopsGraphTraversalSource = findClassAsElement(graphTraversalSourceElement, GraphTraversalSource.class);
         for (Element elementOfGraphTraversalSource : tinkerPopsGraphTraversalSource.getEnclosedElements()) {
             // first copy/override methods that return a GraphTraversalSource so that we can instead return
             // the DSL TraversalSource class.
@@ -226,13 +351,13 @@ public class GremlinDslProcessor extends AbstractProcessor {
         traversalSourceJavaFile.writeTo(filer);
     }
 
-    private Element findTinkerPopsGraphTraversalSource(final Element element) {
-        if (element.getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())) {
+    private Element findClassAsElement(final Element element, final Class<?> clazz) {
+        if (element.getSimpleName().contentEquals(clazz.getSimpleName())) {
             return element;
         }
 
         final List<? extends TypeMirror> supertypes = typeUtils.directSupertypes(element.asType());
-        return findTinkerPopsGraphTraversalSource(typeUtils.asElement(supertypes.get(0)));
+        return findClassAsElement(typeUtils.asElement(supertypes.get(0)), clazz);
     }
 
     private void generateDefaultTraversal(final Context ctx) throws IOException {


[44/45] tinkerpop git commit: TINKERPOP-786 Improved flexbility of handling __ for DSLs in java

Posted by sp...@apache.org.
TINKERPOP-786 Improved flexbility of handling __ for DSLs in java


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/d6b0122b
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/d6b0122b
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/d6b0122b

Branch: refs/heads/tp32-glv
Commit: d6b0122b55ebaf4fc91c3c0a0139ca72984a1834
Parents: 651c1c6
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 26 07:26:30 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri May 26 07:26:30 2017 -0400

----------------------------------------------------------------------
 .../gremlin/process/traversal/dsl/GremlinDslProcessor.java    | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d6b0122b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index 5088d21..470dd4b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -178,7 +178,12 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 methodToAdd.varargs(true);
                 methodToAdd.addStatement("return inject(starts)", methodName);
             } else {
-                addMethodBody(methodToAdd, templateMethod, "return __.<A>start().$L(", ")", methodName);
+                if (templateMethod.getTypeParameters().isEmpty()) {
+                    final List<? extends TypeMirror> types = getTypeArguments(templateMethod);
+                    addMethodBody(methodToAdd, templateMethod, "return __.<$T>start().$L(", ")", types.get(0), methodName);
+                } else {
+                    addMethodBody(methodToAdd, templateMethod, "return __.<A>start().$L(", ")", methodName);
+                }
             }
 
             anonymousClass.addMethod(methodToAdd.build());


[26/45] tinkerpop git commit: TINKERPOP-786 Refactored processor

Posted by sp...@apache.org.
TINKERPOP-786 Refactored processor

Removed some more duplicate code and streamlined a bit further.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/7963dc24
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/7963dc24
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/7963dc24

Branch: refs/heads/tp32-glv
Commit: 7963dc24a0cc87f3c2a68aef9ff887e04b18596d
Parents: fbf8f0d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 12 09:02:08 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:31 2017 -0400

----------------------------------------------------------------------
 .../traversal/dsl/GremlinDslProcessor.java      | 48 +++++++++-----------
 1 file changed, 21 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7963dc24/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index 1717053..3358143 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -61,7 +61,6 @@ import javax.tools.Diagnostic;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Optional;
 import java.util.Set;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
@@ -135,7 +134,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 .build());
 
         // process the methods of the GremlinDsl annotated class
-        for (ExecutableElement templateMethod : findMethodsOfElement(ctx.annotatedDslType)) {
+        for (ExecutableElement templateMethod : findMethodsOfElement(ctx.annotatedDslType, null)) {
             final String methodName = templateMethod.getSimpleName().toString();
 
             final TypeName returnType = getReturnTypeDefinition(ctx.traversalClassName, templateMethod);
@@ -178,12 +177,10 @@ public class GremlinDslProcessor extends AbstractProcessor {
 
         // use methods from __ to template them into the DSL __
         final Element anonymousTraversal = elementUtils.getTypeElement(__.class.getCanonicalName());
-        for (ExecutableElement templateMethod : findMethodsOfElement(anonymousTraversal)) {
+        final Predicate<ExecutableElement> ignore = ee -> ee.getSimpleName().contentEquals("start");
+        for (ExecutableElement templateMethod : findMethodsOfElement(anonymousTraversal, ignore)) {
             final String methodName = templateMethod.getSimpleName().toString();
 
-            // ignore start() from __ - that's not proxied
-            if (methodName.equals("start")) continue;
-
             final TypeName returnType = getReturnTypeDefinition(ctx.traversalClassName, templateMethod);
             final MethodSpec.Builder methodToAdd = MethodSpec.methodBuilder(methodName)
                     .addModifiers(Modifier.STATIC, Modifier.PUBLIC)
@@ -251,18 +248,16 @@ public class GremlinDslProcessor extends AbstractProcessor {
 
         // override methods to return a the DSL TraversalSource. find GraphTraversalSource class somewhere in the hierarchy
         final Element tinkerPopsGraphTraversalSource = findClassAsElement(graphTraversalSourceElement, GraphTraversalSource.class);
-        for (ExecutableElement elementOfGraphTraversalSource : findMethodsOfElement(tinkerPopsGraphTraversalSource)) {
+        final Predicate<ExecutableElement> ignore = e -> !(e.getReturnType().getKind() == TypeKind.DECLARED && ((DeclaredType) e.getReturnType()).asElement().getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName()));
+        for (ExecutableElement elementOfGraphTraversalSource : findMethodsOfElement(tinkerPopsGraphTraversalSource, ignore)) {
             // first copy/override methods that return a GraphTraversalSource so that we can instead return
             // the DSL TraversalSource class.
-            tryConstructMethod(elementOfGraphTraversalSource, ctx.traversalSourceClassName, "",
-                    e -> !(e.getReturnType().getKind() == TypeKind.DECLARED && ((DeclaredType) e.getReturnType()).asElement().getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())),
-                    Modifier.PUBLIC)
-                    .ifPresent(traversalSourceClass::addMethod);
+            traversalSourceClass.addMethod(constructMethod(elementOfGraphTraversalSource, ctx.traversalSourceClassName, "",Modifier.PUBLIC));
         }
 
         // override methods that return GraphTraversal that come from the user defined extension of GraphTraversal
         if (!graphTraversalSourceElement.getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())) {
-            for (ExecutableElement templateMethod : findMethodsOfElement(graphTraversalSourceElement)) {
+            for (ExecutableElement templateMethod : findMethodsOfElement(graphTraversalSourceElement, null)) {
                 final MethodSpec.Builder methodToAdd = MethodSpec.methodBuilder(templateMethod.getSimpleName().toString())
                         .addModifiers(Modifier.PUBLIC)
                         .addAnnotation(Override.class);
@@ -410,18 +405,17 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 .addSuperinterface(TypeName.get(ctx.annotatedDslType.asType()));
 
         // process the methods of the GremlinDsl annotated class
-        for (ExecutableElement templateMethod : findMethodsOfElement(ctx.annotatedDslType)) {
-            tryConstructMethod(templateMethod, ctx.traversalClassName, ctx.dslName, null,
-                    Modifier.PUBLIC, Modifier.DEFAULT).ifPresent(traversalInterface::addMethod);
+        for (ExecutableElement templateMethod : findMethodsOfElement(ctx.annotatedDslType, null)) {
+            traversalInterface.addMethod(constructMethod(templateMethod, ctx.traversalClassName, ctx.dslName,
+                    Modifier.PUBLIC, Modifier.DEFAULT));
         }
 
         // process the methods of GraphTraversal
         final TypeElement graphTraversalElement = elementUtils.getTypeElement(GraphTraversal.class.getCanonicalName());
-        for (ExecutableElement templateMethod : findMethodsOfElement(graphTraversalElement)) {
-            tryConstructMethod(templateMethod, ctx.traversalClassName, ctx.dslName,
-                    e -> e.getSimpleName().contentEquals("asAdmin") || e.getSimpleName().contentEquals("iterate"),
-                    Modifier.PUBLIC, Modifier.DEFAULT)
-                    .ifPresent(traversalInterface::addMethod);
+        final Predicate<ExecutableElement> ignore = e -> e.getSimpleName().contentEquals("asAdmin") || e.getSimpleName().contentEquals("iterate");
+        for (ExecutableElement templateMethod : findMethodsOfElement(graphTraversalElement, ignore)) {
+            traversalInterface.addMethod(constructMethod(templateMethod, ctx.traversalClassName, ctx.dslName,
+                    Modifier.PUBLIC, Modifier.DEFAULT));
         }
 
         // there are weird things with generics that require this method to be implemented if it isn't already present
@@ -438,13 +432,11 @@ public class GremlinDslProcessor extends AbstractProcessor {
         traversalJavaFile.writeTo(filer);
     }
 
-    private Optional<MethodSpec> tryConstructMethod(final Element element, final ClassName returnClazz, final String parent,
-                                                    final Predicate<ExecutableElement> ignore, final Modifier... modifiers) {
+    private MethodSpec constructMethod(final Element element, final ClassName returnClazz, final String parent,
+                                       final Modifier... modifiers) {
         final ExecutableElement templateMethod = (ExecutableElement) element;
         final String methodName = templateMethod.getSimpleName().toString();
 
-        if (ignore != null && ignore.test(templateMethod)) return Optional.empty();
-
         final TypeName returnType = getReturnTypeDefinition(returnClazz, templateMethod);
         final MethodSpec.Builder methodToAdd = MethodSpec.methodBuilder(methodName)
                 .addModifiers(modifiers)
@@ -474,7 +466,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
         body = body + ")";
         methodToAdd.addStatement(body, returnClazz, methodName);
 
-        return Optional.of(methodToAdd.build());
+        return methodToAdd.build();
     }
 
     private TypeName getReturnTypeDefinition(final ClassName returnClazz, final ExecutableElement templateMethod) {
@@ -495,10 +487,12 @@ public class GremlinDslProcessor extends AbstractProcessor {
             throw new ProcessorException(dslElement, "The interface %s is not public.", typeElement.getQualifiedName());
     }
 
-    private List<ExecutableElement> findMethodsOfElement(final Element element) {
+    private List<ExecutableElement> findMethodsOfElement(final Element element, final Predicate<ExecutableElement> ignore) {
+        final Predicate<ExecutableElement> test = null == ignore ? ee -> false : ignore;
         return element.getEnclosedElements().stream()
                 .filter(ee -> ee.getKind() == ElementKind.METHOD)
-                .map(ee -> (ExecutableElement) ee).collect(Collectors.toList());
+                .map(ee -> (ExecutableElement) ee)
+                .filter(ee -> !test.test(ee)).collect(Collectors.toList());
     }
 
     private List<? extends TypeMirror> getTypeArguments(final ExecutableElement templateMethod) {


[08/45] tinkerpop git commit: TINKERPOP-786 Allow the package name of the dsl to change

Posted by sp...@apache.org.
TINKERPOP-786 Allow the package name of the dsl to change


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/5ae34971
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/5ae34971
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/5ae34971

Branch: refs/heads/tp32-glv
Commit: 5ae3497111a5e7dcbdaa5266e09a48b50842c2c1
Parents: 844393d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 27 14:02:32 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../process/traversal/dsl/GremlinDsl.java       |  6 +++
 .../traversal/dsl/GremlinDslProcessor.java      | 11 ++++-
 .../traversal/dsl/GremlinDslProcessorTest.java  | 14 ++++++-
 .../traversal/dsl/SocialMoveTraversalDsl.java   | 43 ++++++++++++++++++++
 4 files changed, 72 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5ae34971/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
index 370ad9b..cbeb5ba 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
@@ -33,4 +33,10 @@ import java.lang.annotation.Target;
 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.CLASS)
 public @interface GremlinDsl {
+
+    /**
+     * The default package name in which to generate the DSL. If this value is left unset or set to an empty string,
+     * it will default to the same package as the class or interface the annotation is on.
+     */
+    public String packageName() default "";
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5ae34971/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index d2bcc65..f2c89e7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -91,8 +91,11 @@ public class GremlinDslProcessor extends AbstractProcessor {
             for (Element dslElement : roundEnv.getElementsAnnotatedWith(GremlinDsl.class)) {
                 validateDSL(dslElement);
 
+                // gets the annotation on the dsl class/interface
+                GremlinDsl gremlinDslAnnotation = dslElement.getAnnotation(GremlinDsl.class);
+
                 final TypeElement annotatedDslType = (TypeElement) dslElement;
-                final String packageName = elementUtils.getPackageOf(dslElement).getQualifiedName().toString();
+                final String packageName = getPackageName(dslElement, gremlinDslAnnotation);
 
                 // create the Traversal implementation interface
                 final String dslName = dslElement.getSimpleName().toString();
@@ -260,6 +263,12 @@ public class GremlinDslProcessor extends AbstractProcessor {
         return true;
     }
 
+    private String getPackageName(final Element dslElement, final GremlinDsl gremlinDslAnnotation) {
+        return gremlinDslAnnotation.packageName().isEmpty() ?
+                elementUtils.getPackageOf(dslElement).getQualifiedName().toString() :
+                gremlinDslAnnotation.packageName();
+    }
+
     private Optional<MethodSpec> tryConstructMethod(final Element element, final ClassName returnClazz, final String parent,
                                                     final Predicate<ExecutableElement> ignore, final Modifier... modifiers) {
         if (element.getKind() != ElementKind.METHOD) return Optional.empty();

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5ae34971/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
index c3c62cd..d1e976d 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
@@ -21,6 +21,8 @@ package org.apache.tinkerpop.gremlin.process.traversal.dsl;
 import com.google.testing.compile.JavaFileObjects;
 import org.junit.Test;
 
+import javax.tools.StandardLocation;
+
 import static com.google.common.truth.Truth.ASSERT;
 import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource;
 
@@ -30,10 +32,20 @@ import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource;
 public class GremlinDslProcessorTest {
 
     @Test
-    public void shouldCompile() {
+    public void shouldCompileToDefaultPackage() {
         ASSERT.about(javaSource())
                 .that(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialTraversalDsl.java")))
                 .processedWith(new GremlinDslProcessor())
                 .compilesWithoutError();
     }
+
+    @Test
+    public void shouldCompileAndMovePackage() {
+        ASSERT.about(javaSource())
+                .that(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialMoveTraversalDsl.java")))
+                .processedWith(new GremlinDslProcessor())
+                .compilesWithoutError()
+                .and()
+                .generatesFileNamed(StandardLocation.SOURCE_OUTPUT, "org.apache.tinkerpop.gremlin.process.traversal.dsl.social", "SocialMoveTraversal.java");
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5ae34971/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
new file mode 100644
index 0000000..1392e30
--- /dev/null
+++ b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
@@ -0,0 +1,43 @@
+/*
+ * 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.util.dsl;
+
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDsl;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@GremlinDsl(packageName = "org.apache.tinkerpop.gremlin.process.traversal.dsl.social")
+public interface SocialMoveTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+    public default GraphTraversal<S, Vertex> knows(final String personName) {
+        return out("knows").hasLabel("person").has("name", personName);
+    }
+
+    public default <E2 extends Number> GraphTraversal<S, E2> meanAgeOfFriends() {
+        return out("knows").hasLabel("person").properties("age").mean();
+    }
+
+    @Override
+    public default GraphTraversal<S, E> iterate() {
+        GraphTraversal.Admin.super.iterate();
+        return this;
+    }
+}


[10/45] tinkerpop git commit: TINKERPOP-786 Extracted logic for DefaultTraversal generation for DSLs

Posted by sp...@apache.org.
TINKERPOP-786 Extracted logic for DefaultTraversal generation for DSLs


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6efaca00
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6efaca00
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6efaca00

Branch: refs/heads/tp32-glv
Commit: 6efaca0017e64d0c108ccae9065458b94b3d2dea
Parents: 21b92b8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 27 15:19:46 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../traversal/dsl/GremlinDslProcessor.java      | 96 ++++++++++----------
 1 file changed, 50 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6efaca00/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index 5a1a6bd..f9d5a40 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -95,52 +95,9 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 // GremlinDsl annotation on it
                 generateTraversalInterface(ctx);
 
-                // START write of the "DefaultTraversal" class
-                final TypeSpec.Builder defaultTraversalClass = TypeSpec.classBuilder(ctx.defaultTraversalClazz)
-                        .addModifiers(Modifier.PUBLIC)
-                        .addTypeVariables(Arrays.asList(TypeVariableName.get("S"), TypeVariableName.get("E")))
-                        .superclass(TypeName.get(elementUtils.getTypeElement(DefaultTraversal.class.getCanonicalName()).asType()))
-                        .addSuperinterface(ParameterizedTypeName.get(ctx.traversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")));
-
-                // add the required constructors for instantiation
-                defaultTraversalClass.addMethod(MethodSpec.constructorBuilder()
-                        .addModifiers(Modifier.PUBLIC)
-                        .addStatement("super()")
-                        .build());
-                defaultTraversalClass.addMethod(MethodSpec.constructorBuilder()
-                        .addModifiers(Modifier.PUBLIC)
-                        .addParameter(Graph.class, "graph")
-                        .addStatement("super($N)", "graph")
-                        .build());
-                defaultTraversalClass.addMethod(MethodSpec.constructorBuilder()
-                        .addModifiers(Modifier.PUBLIC)
-                        .addParameter(ctx.traversalSourceClassName, "traversalSource")
-                        .addStatement("super($N)", "traversalSource")
-                        .build());
-
-                // add the override
-                defaultTraversalClass.addMethod(MethodSpec.methodBuilder("iterate")
-                        .addModifiers(Modifier.PUBLIC)
-                        .addAnnotation(Override.class)
-                        .addStatement("return ($T) super.iterate()", ctx.traversalClassName)
-                        .returns(ParameterizedTypeName.get(ctx.traversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
-                        .build());
-                defaultTraversalClass.addMethod(MethodSpec.methodBuilder("asAdmin")
-                        .addModifiers(Modifier.PUBLIC)
-                        .addAnnotation(Override.class)
-                        .addStatement("return ($T) super.asAdmin()", GraphTraversal.Admin.class)
-                        .returns(ParameterizedTypeName.get(ctx.graphTraversalAdminClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
-                        .build());
-                defaultTraversalClass.addMethod(MethodSpec.methodBuilder("clone")
-                        .addModifiers(Modifier.PUBLIC)
-                        .addAnnotation(Override.class)
-                        .addStatement("return ($T) super.clone()", ctx.defaultTraversalClassName)
-                        .returns(ParameterizedTypeName.get(ctx.defaultTraversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
-                        .build());
-
-                final JavaFile defaultTraversalJavaFile = JavaFile.builder(ctx.packageName, defaultTraversalClass.build()).build();
-                defaultTraversalJavaFile.writeTo(filer);
-                // END write of the "DefaultTraversal" class
+                // create the "DefaultTraversal" class which implements the above generated "Traversal" and can then
+                // be used by the "TraversalSource" generated below to spawn new traversal instances
+                generateDefaultTraversal(ctx);
 
                 // START write "TraversalSource" class
                 final TypeElement graphTraversalSourceElement = elementUtils.getTypeElement(GraphTraversalSource.class.getCanonicalName());
@@ -225,6 +182,53 @@ public class GremlinDslProcessor extends AbstractProcessor {
         return true;
     }
 
+    private void generateDefaultTraversal(final Context ctx) throws IOException {
+        final TypeSpec.Builder defaultTraversalClass = TypeSpec.classBuilder(ctx.defaultTraversalClazz)
+                .addModifiers(Modifier.PUBLIC)
+                .addTypeVariables(Arrays.asList(TypeVariableName.get("S"), TypeVariableName.get("E")))
+                .superclass(TypeName.get(elementUtils.getTypeElement(DefaultTraversal.class.getCanonicalName()).asType()))
+                .addSuperinterface(ParameterizedTypeName.get(ctx.traversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")));
+
+        // add the required constructors for instantiation
+        defaultTraversalClass.addMethod(MethodSpec.constructorBuilder()
+                .addModifiers(Modifier.PUBLIC)
+                .addStatement("super()")
+                .build());
+        defaultTraversalClass.addMethod(MethodSpec.constructorBuilder()
+                .addModifiers(Modifier.PUBLIC)
+                .addParameter(Graph.class, "graph")
+                .addStatement("super($N)", "graph")
+                .build());
+        defaultTraversalClass.addMethod(MethodSpec.constructorBuilder()
+                .addModifiers(Modifier.PUBLIC)
+                .addParameter(ctx.traversalSourceClassName, "traversalSource")
+                .addStatement("super($N)", "traversalSource")
+                .build());
+
+        // add the override
+        defaultTraversalClass.addMethod(MethodSpec.methodBuilder("iterate")
+                .addModifiers(Modifier.PUBLIC)
+                .addAnnotation(Override.class)
+                .addStatement("return ($T) super.iterate()", ctx.traversalClassName)
+                .returns(ParameterizedTypeName.get(ctx.traversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
+                .build());
+        defaultTraversalClass.addMethod(MethodSpec.methodBuilder("asAdmin")
+                .addModifiers(Modifier.PUBLIC)
+                .addAnnotation(Override.class)
+                .addStatement("return ($T) super.asAdmin()", GraphTraversal.Admin.class)
+                .returns(ParameterizedTypeName.get(ctx.graphTraversalAdminClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
+                .build());
+        defaultTraversalClass.addMethod(MethodSpec.methodBuilder("clone")
+                .addModifiers(Modifier.PUBLIC)
+                .addAnnotation(Override.class)
+                .addStatement("return ($T) super.clone()", ctx.defaultTraversalClassName)
+                .returns(ParameterizedTypeName.get(ctx.defaultTraversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
+                .build());
+
+        final JavaFile defaultTraversalJavaFile = JavaFile.builder(ctx.packageName, defaultTraversalClass.build()).build();
+        defaultTraversalJavaFile.writeTo(filer);
+    }
+
     private void generateTraversalInterface(final Context ctx) throws IOException {
         final TypeSpec.Builder traversalInterface = TypeSpec.interfaceBuilder(ctx.traversalClazz)
                 .addModifiers(Modifier.PUBLIC)


[18/45] tinkerpop git commit: TINKERPOP-786 Add option for no default method generation on GremlinDsl

Posted by sp...@apache.org.
TINKERPOP-786 Add option for no default method generation on GremlinDsl


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/7790716a
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/7790716a
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/7790716a

Branch: refs/heads/tp32-glv
Commit: 7790716acac24d8c7d274c5a0b53f5440887be17
Parents: f437275
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Sat Apr 29 06:40:59 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../process/traversal/dsl/GremlinDsl.java       | 13 +++
 .../traversal/dsl/GremlinDslProcessor.java      | 88 ++++++++++----------
 .../traversal/dsl/GremlinDslProcessorTest.java  |  8 ++
 .../dsl/SocialNoDefaultMethodsTraversalDsl.java | 37 ++++++++
 4 files changed, 104 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7790716a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
index 15b93d6..df96007 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
@@ -60,4 +60,17 @@ public @interface GremlinDsl {
      * this value is not supplied the generated "source" will simply extend from {@link GraphTraversalSource}.
      */
     public String traversalSource() default "org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource";
+
+    /**
+     * When set to {@code true}, which is the default, the following methods will be generated to the DSL
+     * implementation of the {@link GraphTraversalSource}:
+     *
+     * <ul>
+     *   <li>{@link GraphTraversalSource#addV()}</li>
+     *   <li>{@link GraphTraversalSource#addV(String)}</li>
+     *   <li>{@link GraphTraversalSource#V(Object...)}</li>
+     *   <li>{@link GraphTraversalSource#E(Object...)}</li>
+     * </ul>
+     */
+    public boolean generateDefaultMethods() default true;
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7790716a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index 9e23410..f8a3266 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -177,48 +177,50 @@ public class GremlinDslProcessor extends AbstractProcessor {
             }
         }
 
-        // override methods that return GraphTraversal
-        traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
-                .addModifiers(Modifier.PUBLIC)
-                .addAnnotation(Override.class)
-                .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
-                .addStatement("clone.getBytecode().addStep($T.addV)", GraphTraversal.Symbols.class)
-                .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
-                .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, null))", ctx.traversalClassName, AddVertexStartStep.class)
-                .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
-                .build());
-        traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
-                .addModifiers(Modifier.PUBLIC)
-                .addAnnotation(Override.class)
-                .addParameter(String.class, "label")
-                .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
-                .addStatement("clone.getBytecode().addStep($T.addV, label)", GraphTraversal.Symbols.class)
-                .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
-                .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, label))", ctx.traversalClassName, AddVertexStartStep.class)
-                .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
-                .build());
-        traversalSourceClass.addMethod(MethodSpec.methodBuilder("V")
-                .addModifiers(Modifier.PUBLIC)
-                .addAnnotation(Override.class)
-                .addParameter(Object[].class, "vertexIds")
-                .varargs(true)
-                .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
-                .addStatement("clone.getBytecode().addStep($T.V, vertexIds)", GraphTraversal.Symbols.class)
-                .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
-                .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, vertexIds))", ctx.traversalClassName, GraphStep.class, Vertex.class)
-                .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
-                .build());
-        traversalSourceClass.addMethod(MethodSpec.methodBuilder("E")
-                .addModifiers(Modifier.PUBLIC)
-                .addAnnotation(Override.class)
-                .addParameter(Object[].class, "edgeIds")
-                .varargs(true)
-                .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
-                .addStatement("clone.getBytecode().addStep($T.E, edgeIds)", GraphTraversal.Symbols.class)
-                .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
-                .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, edgeIds))", ctx.traversalClassName, GraphStep.class, Edge.class)
-                .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Edge.class), ClassName.get(Edge.class)))
-                .build());
+        if (ctx.generateDefaultMethods) {
+            // override methods that return GraphTraversal
+            traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
+                    .addModifiers(Modifier.PUBLIC)
+                    .addAnnotation(Override.class)
+                    .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
+                    .addStatement("clone.getBytecode().addStep($T.addV)", GraphTraversal.Symbols.class)
+                    .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
+                    .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, null))", ctx.traversalClassName, AddVertexStartStep.class)
+                    .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
+                    .build());
+            traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
+                    .addModifiers(Modifier.PUBLIC)
+                    .addAnnotation(Override.class)
+                    .addParameter(String.class, "label")
+                    .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
+                    .addStatement("clone.getBytecode().addStep($T.addV, label)", GraphTraversal.Symbols.class)
+                    .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
+                    .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, label))", ctx.traversalClassName, AddVertexStartStep.class)
+                    .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
+                    .build());
+            traversalSourceClass.addMethod(MethodSpec.methodBuilder("V")
+                    .addModifiers(Modifier.PUBLIC)
+                    .addAnnotation(Override.class)
+                    .addParameter(Object[].class, "vertexIds")
+                    .varargs(true)
+                    .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
+                    .addStatement("clone.getBytecode().addStep($T.V, vertexIds)", GraphTraversal.Symbols.class)
+                    .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
+                    .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, vertexIds))", ctx.traversalClassName, GraphStep.class, Vertex.class)
+                    .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
+                    .build());
+            traversalSourceClass.addMethod(MethodSpec.methodBuilder("E")
+                    .addModifiers(Modifier.PUBLIC)
+                    .addAnnotation(Override.class)
+                    .addParameter(Object[].class, "edgeIds")
+                    .varargs(true)
+                    .addStatement("$N clone = this.clone()", ctx.traversalSourceClazz)
+                    .addStatement("clone.getBytecode().addStep($T.E, edgeIds)", GraphTraversal.Symbols.class)
+                    .addStatement("$N traversal = new $N(clone)", ctx.defaultTraversalClazz, ctx.defaultTraversalClazz)
+                    .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, edgeIds))", ctx.traversalClassName, GraphStep.class, Edge.class)
+                    .returns(ParameterizedTypeName.get(ctx.traversalClassName, ClassName.get(Edge.class), ClassName.get(Edge.class)))
+                    .build());
+        }
 
         final JavaFile traversalSourceJavaFile = JavaFile.builder(ctx.packageName, traversalSourceClass.build()).build();
         traversalSourceJavaFile.writeTo(filer);
@@ -393,12 +395,14 @@ public class GremlinDslProcessor extends AbstractProcessor {
         private final ClassName defaultTraversalClassName;
         private final ClassName graphTraversalAdminClassName;
         private final TypeElement traversalSourceDslType;
+        private final boolean generateDefaultMethods;
 
         public Context(final TypeElement dslElement) {
             annotatedDslType = dslElement;
 
             // gets the annotation on the dsl class/interface
             GremlinDsl gremlinDslAnnotation = dslElement.getAnnotation(GremlinDsl.class);
+            generateDefaultMethods = gremlinDslAnnotation.generateDefaultMethods();
 
             traversalSourceDslType = elementUtils.getTypeElement(gremlinDslAnnotation.traversalSource());
             packageName = getPackageName(dslElement, gremlinDslAnnotation);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7790716a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
index d0d7d6f..982ec5b 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
@@ -56,4 +56,12 @@ public class GremlinDslProcessorTest {
                 .processedWith(new GremlinDslProcessor())
                 .compilesWithoutError();
     }
+
+    @Test
+    public void shouldCompileWithNoDefaultMethods() {
+        ASSERT.about(javaSource())
+                .that(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialNoDefaultMethodsTraversalDsl.java")))
+                .processedWith(new GremlinDslProcessor())
+                .compilesWithoutError();
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7790716a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialNoDefaultMethodsTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialNoDefaultMethodsTraversalDsl.java b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialNoDefaultMethodsTraversalDsl.java
new file mode 100644
index 0000000..4eb15bd
--- /dev/null
+++ b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialNoDefaultMethodsTraversalDsl.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDsl;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@GremlinDsl(generateDefaultMethods = false)
+public interface SocialNoDefaultMethodsTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+    public default GraphTraversal<S, Vertex> knows(final String personName) {
+        return out("knows").hasLabel("person").has("name", personName);
+    }
+
+    public default <E2 extends Number> GraphTraversal<S, E2> meanAgeOfFriends() {
+        return out("knows").hasLabel("person").values("age").mean();
+    }
+}


[04/45] tinkerpop git commit: TINKERPOP-786 Used templating language instead of string concat

Posted by sp...@apache.org.
TINKERPOP-786 Used templating language instead of string concat


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/2d574fbd
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/2d574fbd
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/2d574fbd

Branch: refs/heads/tp32-glv
Commit: 2d574fbddc8aefd671880427c421b610da0f3b4d
Parents: a98471c
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu May 4 10:28:29 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../gremlin/process/traversal/dsl/GremlinDslProcessor.java   | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2d574fbd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index f8a3266..e246765 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -154,7 +154,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
 
                 boolean added = false;
                 final List<? extends VariableElement> parameters = templateMethod.getParameters();
-                String body = "return new " + ctx.defaultTraversalClassName + "(clone, super." + elementOfGraphTraversalSource.getSimpleName().toString() + "(";
+                String body = "return new $T (clone, super.$L(";
                 for (VariableElement param : parameters) {
                     methodToAdd.addParameter(ParameterSpec.get(param));
 
@@ -170,7 +170,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
 
                 body = body + ").asAdmin())";
                 methodToAdd.addStatement("$T clone = this.clone()", ctx.traversalSourceClassName)
-                        .addStatement(body)
+                        .addStatement(body, ctx.defaultTraversalClassName, elementOfGraphTraversalSource.getSimpleName())
                         .returns(getReturnTypeDefinition(ctx.traversalClassName, templateMethod));
 
                 traversalSourceClass.addMethod(methodToAdd.build());
@@ -344,7 +344,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
         boolean added = false;
         final List<? extends VariableElement> parameters = templateMethod.getParameters();
         final String parentCall = parent.isEmpty() ? "" : parent + ".";
-        String body = "return (" + returnClazz.simpleName() + ") " + parentCall + "super." + methodName + "(";
+        String body = "return ($T) " + parentCall + "super.$L(";
         for (VariableElement param : parameters) {
             methodToAdd.addParameter(ParameterSpec.get(param));
 
@@ -359,7 +359,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
         if (added) body = body.substring(0, body.length() - 1);
 
         body = body + ")";
-        methodToAdd.addStatement(body);
+        methodToAdd.addStatement(body, returnClazz, methodName);
 
         return Optional.of(methodToAdd.build());
     }


[13/45] tinkerpop git commit: TINKERPOP-786 Removed some commented out config in the pom.xml

Posted by sp...@apache.org.
TINKERPOP-786 Removed some commented out config in the pom.xml


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/62cfbc95
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/62cfbc95
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/62cfbc95

Branch: refs/heads/tp32-glv
Commit: 62cfbc952e427a1a0babd124f2c2fcec6ace7fea
Parents: ef359dd
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Sat Apr 29 06:57:46 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 gremlin-core/pom.xml | 14 --------------
 1 file changed, 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/62cfbc95/gremlin-core/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-core/pom.xml b/gremlin-core/pom.xml
index 0efadfa..f3bff75 100644
--- a/gremlin-core/pom.xml
+++ b/gremlin-core/pom.xml
@@ -107,20 +107,6 @@ limitations under the License.
             <version>0.10</version>
             <scope>test</scope>
         </dependency>
-        <!--
-        <dependency>
-            <groupId>com.google.truth</groupId>
-            <artifactId>truth</artifactId>
-            <version>0.25</version>
-            <exclusions>
-                truth comes in through compile-testing and has a self-conflict - produces further conflict with hadoop-gremlin
-                <exclusion>
-                    <groupId>com.google.guava</groupId>
-                    <artifactId>guava</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
--->
     </dependencies>
     <build>
         <directory>${basedir}/target</directory>


[38/45] tinkerpop git commit: Improved memory usage when deserializing TinkerGraph from GraphSON

Posted by sp...@apache.org.
Improved memory usage when deserializing TinkerGraph from GraphSON

Streamed vertices/edges rather than reading them all into memory at once. CTR


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/7ea38751
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/7ea38751
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/7ea38751

Branch: refs/heads/tp32-glv
Commit: 7ea38751871f6eddd4c4bcfe8ac82300a08f5a7d
Parents: afa3432
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 23 11:01:55 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 23 11:01:55 2017 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../structure/TinkerIoRegistryV2d0.java         | 40 +++++++++-----------
 2 files changed, 18 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7ea38751/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 7057aac..be8059d 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Reduced memory usage for TinkerGraph deserialization in GraphSON by streaming vertices and edges.
 * Now using Groovy `[...]` map notation in `GroovyTranslator` instead of `new LinkedHashMap(){{ }}`.
 * Maintained type information on `Traversal.promise()`.
 * Propagated exception to `Future` instead of calling thread in `RemoteConnection`.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7ea38751/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV2d0.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV2d0.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV2d0.java
index 727931c..394216b 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV2d0.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV2d0.java
@@ -26,7 +26,6 @@ import org.apache.tinkerpop.gremlin.structure.io.AbstractIoRegistry;
 import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONIo;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONUtil;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.TinkerPopJacksonModule;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader;
@@ -37,12 +36,11 @@ import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
 import org.apache.tinkerpop.shaded.jackson.core.JsonGenerator;
 import org.apache.tinkerpop.shaded.jackson.core.JsonParser;
 import org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException;
+import org.apache.tinkerpop.shaded.jackson.core.JsonToken;
 import org.apache.tinkerpop.shaded.jackson.databind.DeserializationContext;
 import org.apache.tinkerpop.shaded.jackson.databind.SerializerProvider;
 import org.apache.tinkerpop.shaded.jackson.databind.deser.std.StdDeserializer;
-import org.apache.tinkerpop.shaded.jackson.databind.jsontype.TypeSerializer;
 import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdScalarSerializer;
-import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer;
 import org.apache.tinkerpop.shaded.kryo.Kryo;
 import org.apache.tinkerpop.shaded.kryo.Serializer;
 import org.apache.tinkerpop.shaded.kryo.io.Input;
@@ -53,7 +51,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -201,26 +198,23 @@ public final class TinkerIoRegistryV2d0 extends AbstractIoRegistry {
             conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list");
             final TinkerGraph graph = TinkerGraph.open(conf);
 
-            final List<? extends Edge> edges;
-            final List<? extends Vertex> vertices;
-
-            jsonParser.nextToken();
-            final Map<String, Object> graphData = deserializationContext.readValue(jsonParser, Map.class);
-            vertices = (List<DetachedVertex>) graphData.get(GraphSONTokens.VERTICES);
-            edges = (List<DetachedEdge>) graphData.get(GraphSONTokens.EDGES);
-
-
-            vertices.forEach(e -> {
-                if (e instanceof DetachedVertex) {
-                    ((DetachedVertex)e).attach(Attachable.Method.getOrCreate(graph));
+            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
+                if (jsonParser.getCurrentName().equals("vertices")) {
+                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
+                        if (jsonParser.currentToken() == JsonToken.START_OBJECT) {
+                            final DetachedVertex v = (DetachedVertex) deserializationContext.readValue(jsonParser, Vertex.class);
+                            v.attach(Attachable.Method.getOrCreate(graph));
+                        }
+                    }
+                } else if (jsonParser.getCurrentName().equals("edges")) {
+                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
+                        if (jsonParser.currentToken() == JsonToken.START_OBJECT) {
+                            final DetachedEdge e = (DetachedEdge) deserializationContext.readValue(jsonParser, Edge.class);
+                            e.attach(Attachable.Method.getOrCreate(graph));
+                        }
+                    }
                 }
-            });
-
-            edges.forEach(e -> {
-                if (e instanceof DetachedEdge) {
-                    ((DetachedEdge) e).attach(Attachable.Method.getOrCreate(graph));
-                }
-            });
+            }
 
             return graph;
         }


[11/45] tinkerpop git commit: TINKERPOP-786 Made override of iterate() automatic

Posted by sp...@apache.org.
TINKERPOP-786 Made override of iterate() automatic


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/21b92b8f
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/21b92b8f
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/21b92b8f

Branch: refs/heads/tp32-glv
Commit: 21b92b8faec44eb07b7abebc2a47d9d61f8e890d
Parents: 06d6d13
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 27 15:16:16 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../src/main/java/SocialTraversalDsl.java       |  6 --
 .../traversal/dsl/GremlinDslProcessor.java      | 69 ++++++++++++--------
 .../traversal/dsl/SocialMoveTraversalDsl.java   |  6 --
 .../traversal/dsl/SocialTraversalDsl.java       |  6 --
 4 files changed, 43 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21b92b8f/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
index 546a328..fb2a3f6 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
@@ -32,10 +32,4 @@ public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
     public default <E2 extends Number> GraphTraversal<S, E2> youngestFriendsAge() {
         return out("knows").hasLabel("person").values("age").min();
     }
-
-    @Override
-    public default GraphTraversal<S, E> iterate() {
-        GraphTraversal.Admin.super.iterate();
-        return this;
-    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21b92b8f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index d96ae01..5a1a6bd 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -56,6 +56,7 @@ import javax.lang.model.type.TypeMirror;
 import javax.lang.model.util.Elements;
 import javax.lang.model.util.Types;
 import javax.tools.Diagnostic;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Optional;
@@ -88,33 +89,11 @@ public class GremlinDslProcessor extends AbstractProcessor {
         try {
             for (Element dslElement : roundEnv.getElementsAnnotatedWith(GremlinDsl.class)) {
                 validateDSL(dslElement);
-                final TypeElement annotatedDslType = (TypeElement) dslElement;
-                final Context ctx = new Context(annotatedDslType);
+                final Context ctx = new Context((TypeElement) dslElement);
 
-                // START write "Traversal" class
-                final TypeSpec.Builder traversalInterface = TypeSpec.interfaceBuilder(ctx.traversalClazz)
-                        .addModifiers(Modifier.PUBLIC)
-                        .addTypeVariables(Arrays.asList(TypeVariableName.get("S"), TypeVariableName.get("E")))
-                        .addSuperinterface(TypeName.get(dslElement.asType()));
-
-                // process the methods of the GremlinDsl annotated class
-                for (Element elementOfDsl : annotatedDslType.getEnclosedElements()) {
-                    tryConstructMethod(elementOfDsl, ctx.traversalClassName, ctx.dslName, null,
-                            Modifier.PUBLIC, Modifier.DEFAULT).ifPresent(traversalInterface::addMethod);
-                }
-
-                // process the methods of GraphTraversal
-                final TypeElement graphTraversalElement = elementUtils.getTypeElement(GraphTraversal.class.getCanonicalName());
-                for (Element elementOfGraphTraversal : graphTraversalElement.getEnclosedElements()) {
-                    tryConstructMethod(elementOfGraphTraversal, ctx.traversalClassName, ctx.dslName,
-                            e -> e.getSimpleName().contentEquals("asAdmin") || e.getSimpleName().contentEquals("iterate"),
-                            Modifier.PUBLIC, Modifier.DEFAULT)
-                            .ifPresent(traversalInterface::addMethod);
-                }
-
-                final JavaFile traversalJavaFile = JavaFile.builder(ctx.packageName, traversalInterface.build()).build();
-                traversalJavaFile.writeTo(filer);
-                // END write "Traversal" class
+                // creates the "Traversal" interface using an extension of the GraphTraversal class that has the
+                // GremlinDsl annotation on it
+                generateTraversalInterface(ctx);
 
                 // START write of the "DefaultTraversal" class
                 final TypeSpec.Builder defaultTraversalClass = TypeSpec.classBuilder(ctx.defaultTraversalClazz)
@@ -246,6 +225,41 @@ public class GremlinDslProcessor extends AbstractProcessor {
         return true;
     }
 
+    private void generateTraversalInterface(final Context ctx) throws IOException {
+        final TypeSpec.Builder traversalInterface = TypeSpec.interfaceBuilder(ctx.traversalClazz)
+                .addModifiers(Modifier.PUBLIC)
+                .addTypeVariables(Arrays.asList(TypeVariableName.get("S"), TypeVariableName.get("E")))
+                .addSuperinterface(TypeName.get(ctx.annotatedDslType.asType()));
+
+        // process the methods of the GremlinDsl annotated class
+        for (Element elementOfDsl : ctx.annotatedDslType.getEnclosedElements()) {
+            tryConstructMethod(elementOfDsl, ctx.traversalClassName, ctx.dslName, null,
+                    Modifier.PUBLIC, Modifier.DEFAULT).ifPresent(traversalInterface::addMethod);
+        }
+
+        // process the methods of GraphTraversal
+        final TypeElement graphTraversalElement = elementUtils.getTypeElement(GraphTraversal.class.getCanonicalName());
+        for (Element elementOfGraphTraversal : graphTraversalElement.getEnclosedElements()) {
+            tryConstructMethod(elementOfGraphTraversal, ctx.traversalClassName, ctx.dslName,
+                    e -> e.getSimpleName().contentEquals("asAdmin") || e.getSimpleName().contentEquals("iterate"),
+                    Modifier.PUBLIC, Modifier.DEFAULT)
+                    .ifPresent(traversalInterface::addMethod);
+        }
+
+        // there are weird things with generics that require this method to be implemented if it isn't already present
+        // in the GremlinDsl annotated class extending from GraphTraversal
+        traversalInterface.addMethod(MethodSpec.methodBuilder("iterate")
+                .addModifiers(Modifier.PUBLIC, Modifier.DEFAULT)
+                .addAnnotation(Override.class)
+                .addStatement("$T.super.iterate()", ClassName.get(ctx.annotatedDslType))
+                .addStatement("return this")
+                .returns(ParameterizedTypeName.get(ctx.traversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
+                .build());
+
+        final JavaFile traversalJavaFile = JavaFile.builder(ctx.packageName, traversalInterface.build()).build();
+        traversalJavaFile.writeTo(filer);
+    }
+
     private Optional<MethodSpec> tryConstructMethod(final Element element, final ClassName returnClazz, final String parent,
                                                     final Predicate<ExecutableElement> ignore, final Modifier... modifiers) {
         if (element.getKind() != ElementKind.METHOD) return Optional.empty();
@@ -303,6 +317,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
     }
 
     private class Context {
+        private final TypeElement annotatedDslType;
         private final String packageName;
         private final String dslName;
         private final String traversalClazz;
@@ -314,6 +329,8 @@ public class GremlinDslProcessor extends AbstractProcessor {
         private final ClassName graphTraversalAdminClassName;
 
         public Context(final TypeElement dslElement) {
+            annotatedDslType = dslElement;
+
             // gets the annotation on the dsl class/interface
             GremlinDsl gremlinDslAnnotation = dslElement.getAnnotation(GremlinDsl.class);
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21b92b8f/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
index 1392e30..1db1dff 100644
--- a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
+++ b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
@@ -34,10 +34,4 @@ public interface SocialMoveTraversalDsl<S, E> extends GraphTraversal.Admin<S, E>
     public default <E2 extends Number> GraphTraversal<S, E2> meanAgeOfFriends() {
         return out("knows").hasLabel("person").properties("age").mean();
     }
-
-    @Override
-    public default GraphTraversal<S, E> iterate() {
-        GraphTraversal.Admin.super.iterate();
-        return this;
-    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21b92b8f/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
index af53dd2..fc4921f 100644
--- a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
+++ b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
@@ -34,10 +34,4 @@ public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
     public default <E2 extends Number> GraphTraversal<S, E2> meanAgeOfFriends() {
         return out("knows").hasLabel("person").properties("age").mean();
     }
-
-    @Override
-    public default GraphTraversal<S, E> iterate() {
-        GraphTraversal.Admin.super.iterate();
-        return this;
-    }
 }


[14/45] tinkerpop git commit: TINKERPOP-786 Deleted an unused interface

Posted by sp...@apache.org.
TINKERPOP-786 Deleted an unused interface


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/f437275e
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/f437275e
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/f437275e

Branch: refs/heads/tp32-glv
Commit: f437275e6b21aecddf150fe2fca70de5cd3fb837
Parents: ffe4c05
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Apr 28 16:07:52 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../dsl/GremlinDslAnnotatedInterface.java       | 32 --------------------
 1 file changed, 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f437275e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslAnnotatedInterface.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslAnnotatedInterface.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslAnnotatedInterface.java
deleted file mode 100644
index 2f6db74..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslAnnotatedInterface.java
+++ /dev/null
@@ -1,32 +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;
-
-import javax.lang.model.element.TypeElement;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-class GremlinDslAnnotatedInterface {
-    private final TypeElement annotatedInterfaceElement;
-
-    public GremlinDslAnnotatedInterface(final TypeElement interfaceElement) {
-        annotatedInterfaceElement = interfaceElement;
-    }
-}


[41/45] tinkerpop git commit: Improved error messaging in addV() CTR

Posted by sp...@apache.org.
Improved error messaging in addV() CTR


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/1ee5b375
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/1ee5b375
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/1ee5b375

Branch: refs/heads/tp32-glv
Commit: 1ee5b37535467cf60c7d4671ab3728af18d3e057
Parents: 7bf6883
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu May 25 08:19:36 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu May 25 08:19:36 2017 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                                               | 1 +
 .../process/traversal/dsl/graph/GraphTraversalSource.java        | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1ee5b375/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index be8059d..31a4064 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Improved error messaging on the `g.addV(Object...)` when passing an invalid arguments.
 * Reduced memory usage for TinkerGraph deserialization in GraphSON by streaming vertices and edges.
 * Now using Groovy `[...]` map notation in `GroovyTranslator` instead of `new LinkedHashMap(){{ }}`.
 * Maintained type information on `Traversal.promise()`.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1ee5b375/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
index af78add..1b6a218 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
@@ -41,6 +41,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Transaction;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 
 import java.util.ArrayList;
@@ -263,16 +264,15 @@ public class GraphTraversalSource implements TraversalSource {
      */
     @Deprecated
     public GraphTraversal<Vertex, Vertex> addV(final Object... keyValues) {
+        ElementHelper.legalPropertyKeyValueArray(keyValues);
         if (keyValues.length != 0 && keyValues[0].equals(T.label)) {
             final GraphTraversal<Vertex, Vertex> traversal = this.addV(keyValues[1].toString());
-            this.addV(keyValues[1].toString());
             for (int i = 2; i < keyValues.length; i = i + 2) {
                 traversal.property(keyValues[i], keyValues[i + 1]);
             }
             return traversal;
         } else {
             final GraphTraversal<Vertex, Vertex> traversal = this.addV();
-            this.addV(keyValues[1].toString());
             for (int i = 0; i < keyValues.length; i = i + 2) {
                 traversal.property(keyValues[i], keyValues[i + 1]);
             }


[21/45] tinkerpop git commit: TINKERPOP-786 Improved the TraversalSource definition in the archetype

Posted by sp...@apache.org.
TINKERPOP-786 Improved the TraversalSource definition in the archetype


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b47b25cd
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b47b25cd
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b47b25cd

Branch: refs/heads/tp32-glv
Commit: b47b25cda2ee3b38159c127e3f0218e7a9a55e37
Parents: df012d3
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 13:47:31 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:51 2017 -0400

----------------------------------------------------------------------
 .../src/main/java/SocialTraversalSourceDsl.java     | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b47b25cd/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
index 3bd8297..d14b843 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
@@ -52,17 +52,15 @@ public class SocialTraversalSourceDsl extends GraphTraversalSource {
      */
     public GraphTraversal<Vertex, Vertex> persons(String... names) {
         GraphTraversalSource clone = this.clone();
-        clone.getBytecode().addStep(GraphTraversal.Symbols.V);
-        clone.getBytecode().addStep(GraphTraversal.Symbols.hasLabel, "person");
 
-        GraphTraversal.Admin<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
-        traversal.addStep(new GraphStep<>(traversal, Vertex.class, true));
-        TraversalHelper.addHasContainer(traversal, new HasContainer(T.label.getAccessor(), P.eq("person")));
+        // Manually add a "start" step for the traversal in this case the equivalent of V(). GraphStep is marked
+        // as a "start" step by passing "true" in the constructor.
+        clone.getBytecode().addStep(GraphTraversal.Symbols.V);
+        GraphTraversal<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
+        traversal.asAdmin().addStep(new GraphStep<>(traversal.asAdmin(), Vertex.class, true));
 
-        if (names.length > 0) {
-            clone.getBytecode().addStep(GraphTraversal.Symbols.has, P.within(names));
-            TraversalHelper.addHasContainer(traversal, new HasContainer("name", P.within(names)));
-        }
+        traversal = traversal.hasLabel("person");
+        if (names.length > 0) traversal = traversal.has("name", P.within(names));
 
         return traversal;
     }


[25/45] tinkerpop git commit: TINKERPOP-786 Refactored the processor a bit.

Posted by sp...@apache.org.
TINKERPOP-786 Refactored the processor a bit.

Trying to get this guy more organized. Lots of duplicate code to remove still.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/fbf8f0df
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/fbf8f0df
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/fbf8f0df

Branch: refs/heads/tp32-glv
Commit: fbf8f0dffbbc332ff15171d1fced011d4a66e805
Parents: 404ee8c
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 12 08:16:33 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:31 2017 -0400

----------------------------------------------------------------------
 .../traversal/dsl/GremlinDslProcessor.java      | 48 ++++++++++----------
 1 file changed, 23 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fbf8f0df/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index 04e59b4..1717053 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -135,10 +135,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 .build());
 
         // process the methods of the GremlinDsl annotated class
-        for (Element element : ctx.annotatedDslType.getEnclosedElements()) {
-            if (element.getKind() != ElementKind.METHOD) continue;
-
-            final ExecutableElement templateMethod = (ExecutableElement) element;
+        for (ExecutableElement templateMethod : findMethodsOfElement(ctx.annotatedDslType)) {
             final String methodName = templateMethod.getSimpleName().toString();
 
             final TypeName returnType = getReturnTypeDefinition(ctx.traversalClassName, templateMethod);
@@ -150,8 +147,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
             templateMethod.getTypeParameters().forEach(tp -> methodToAdd.addTypeVariable(TypeVariableName.get(tp)));
 
             // might have to deal with an "S" (in __ it's usually an "A") - how to make this less bound to that convention?
-            final DeclaredType returnTypeMirror = (DeclaredType) templateMethod.getReturnType();
-            final List<? extends TypeMirror> returnTypeArguments = returnTypeMirror.getTypeArguments();
+            final List<? extends TypeMirror> returnTypeArguments = getTypeArguments(templateMethod);
             returnTypeArguments.stream().filter(rtm -> rtm instanceof TypeVariable).forEach(rtm -> {
                 if (((TypeVariable) rtm).asElement().getSimpleName().contentEquals("S"))
                     methodToAdd.addTypeVariable(TypeVariableName.get(((TypeVariable) rtm).asElement().getSimpleName().toString()));
@@ -182,10 +178,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
 
         // use methods from __ to template them into the DSL __
         final Element anonymousTraversal = elementUtils.getTypeElement(__.class.getCanonicalName());
-        for (Element element : anonymousTraversal.getEnclosedElements()) {
-            if (element.getKind() != ElementKind.METHOD) continue;
-
-            final ExecutableElement templateMethod = (ExecutableElement) element;
+        for (ExecutableElement templateMethod : findMethodsOfElement(anonymousTraversal)) {
             final String methodName = templateMethod.getSimpleName().toString();
 
             // ignore start() from __ - that's not proxied
@@ -258,7 +251,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
 
         // override methods to return a the DSL TraversalSource. find GraphTraversalSource class somewhere in the hierarchy
         final Element tinkerPopsGraphTraversalSource = findClassAsElement(graphTraversalSourceElement, GraphTraversalSource.class);
-        for (Element elementOfGraphTraversalSource : tinkerPopsGraphTraversalSource.getEnclosedElements()) {
+        for (ExecutableElement elementOfGraphTraversalSource : findMethodsOfElement(tinkerPopsGraphTraversalSource)) {
             // first copy/override methods that return a GraphTraversalSource so that we can instead return
             // the DSL TraversalSource class.
             tryConstructMethod(elementOfGraphTraversalSource, ctx.traversalSourceClassName, "",
@@ -269,11 +262,8 @@ public class GremlinDslProcessor extends AbstractProcessor {
 
         // override methods that return GraphTraversal that come from the user defined extension of GraphTraversal
         if (!graphTraversalSourceElement.getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())) {
-            for (Element elementOfGraphTraversalSource : graphTraversalSourceElement.getEnclosedElements()) {
-                if (elementOfGraphTraversalSource.getKind() != ElementKind.METHOD) continue;
-
-                final ExecutableElement templateMethod = (ExecutableElement) elementOfGraphTraversalSource;
-                final MethodSpec.Builder methodToAdd = MethodSpec.methodBuilder(elementOfGraphTraversalSource.getSimpleName().toString())
+            for (ExecutableElement templateMethod : findMethodsOfElement(graphTraversalSourceElement)) {
+                final MethodSpec.Builder methodToAdd = MethodSpec.methodBuilder(templateMethod.getSimpleName().toString())
                         .addModifiers(Modifier.PUBLIC)
                         .addAnnotation(Override.class);
 
@@ -295,7 +285,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
 
                 body = body + ").asAdmin())";
                 methodToAdd.addStatement("$T clone = this.clone()", ctx.traversalSourceClassName)
-                        .addStatement(body, ctx.defaultTraversalClassName, elementOfGraphTraversalSource.getSimpleName())
+                        .addStatement(body, ctx.defaultTraversalClassName, templateMethod.getSimpleName())
                         .returns(getReturnTypeDefinition(ctx.traversalClassName, templateMethod));
 
                 traversalSourceClass.addMethod(methodToAdd.build());
@@ -420,15 +410,15 @@ public class GremlinDslProcessor extends AbstractProcessor {
                 .addSuperinterface(TypeName.get(ctx.annotatedDslType.asType()));
 
         // process the methods of the GremlinDsl annotated class
-        for (Element elementOfDsl : ctx.annotatedDslType.getEnclosedElements()) {
-            tryConstructMethod(elementOfDsl, ctx.traversalClassName, ctx.dslName, null,
+        for (ExecutableElement templateMethod : findMethodsOfElement(ctx.annotatedDslType)) {
+            tryConstructMethod(templateMethod, ctx.traversalClassName, ctx.dslName, null,
                     Modifier.PUBLIC, Modifier.DEFAULT).ifPresent(traversalInterface::addMethod);
         }
 
         // process the methods of GraphTraversal
         final TypeElement graphTraversalElement = elementUtils.getTypeElement(GraphTraversal.class.getCanonicalName());
-        for (Element elementOfGraphTraversal : graphTraversalElement.getEnclosedElements()) {
-            tryConstructMethod(elementOfGraphTraversal, ctx.traversalClassName, ctx.dslName,
+        for (ExecutableElement templateMethod : findMethodsOfElement(graphTraversalElement)) {
+            tryConstructMethod(templateMethod, ctx.traversalClassName, ctx.dslName,
                     e -> e.getSimpleName().contentEquals("asAdmin") || e.getSimpleName().contentEquals("iterate"),
                     Modifier.PUBLIC, Modifier.DEFAULT)
                     .ifPresent(traversalInterface::addMethod);
@@ -450,8 +440,6 @@ public class GremlinDslProcessor extends AbstractProcessor {
 
     private Optional<MethodSpec> tryConstructMethod(final Element element, final ClassName returnClazz, final String parent,
                                                     final Predicate<ExecutableElement> ignore, final Modifier... modifiers) {
-        if (element.getKind() != ElementKind.METHOD) return Optional.empty();
-
         final ExecutableElement templateMethod = (ExecutableElement) element;
         final String methodName = templateMethod.getSimpleName().toString();
 
@@ -490,8 +478,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
     }
 
     private TypeName getReturnTypeDefinition(final ClassName returnClazz, final ExecutableElement templateMethod) {
-        final DeclaredType returnTypeMirror = (DeclaredType) templateMethod.getReturnType();
-        final List<? extends TypeMirror> returnTypeArguments = returnTypeMirror.getTypeArguments();
+        final List<? extends TypeMirror> returnTypeArguments = getTypeArguments(templateMethod);
 
         // build a return type with appropriate generic declarations (if such declarations are present)
         return returnTypeArguments.isEmpty() ?
@@ -508,6 +495,17 @@ public class GremlinDslProcessor extends AbstractProcessor {
             throw new ProcessorException(dslElement, "The interface %s is not public.", typeElement.getQualifiedName());
     }
 
+    private List<ExecutableElement> findMethodsOfElement(final Element element) {
+        return element.getEnclosedElements().stream()
+                .filter(ee -> ee.getKind() == ElementKind.METHOD)
+                .map(ee -> (ExecutableElement) ee).collect(Collectors.toList());
+    }
+
+    private List<? extends TypeMirror> getTypeArguments(final ExecutableElement templateMethod) {
+        final DeclaredType returnTypeMirror = (DeclaredType) templateMethod.getReturnType();
+        return returnTypeMirror.getTypeArguments();
+    }
+
     private class Context {
         private final TypeElement annotatedDslType;
         private final String packageName;


[19/45] tinkerpop git commit: TINKERPOP-786 Added some initial documentation for DSLs

Posted by sp...@apache.org.
TINKERPOP-786 Added some initial documentation for DSLs


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/50f2dac9
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/50f2dac9
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/50f2dac9

Branch: refs/heads/tp32-glv
Commit: 50f2dac9d897d5776a2cdd4ae3a7b56a4ed6339a
Parents: e661359
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 13:57:48 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:51 2017 -0400

----------------------------------------------------------------------
 docs/src/reference/the-traversal.asciidoc | 154 +++++++++++++++++++++++++
 1 file changed, 154 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/50f2dac9/docs/src/reference/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/the-traversal.asciidoc b/docs/src/reference/the-traversal.asciidoc
index 2612309..1be365d 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -2939,3 +2939,157 @@ g.V().outE().inV().
     by().
     by('name')
 ----
+
+[[dsl]]
+Domain Specific Languages
+-------------------------
+
+Gremlin is a link:http://en.wikipedia.org/wiki/Domain-specific_language[domain specific language] (DSL) for traversing
+graphs. It operates in the language of vertices, edges and properties. Typically, applications built with Gremlin are
+not of the graph domain, but instead model their domain within a graph. For example, the "modern" toy graph models
+software and person domain objects with the relationships between them (i.e. a person "knows" another person and a
+person "created" software).
+
+image::tinkerpop-modern.png[width=350]
+
+An analyst who wanted to find all the people who "marko" knows could write the following Gremlin:
+
+[source,java]
+----
+g.V().hasLabel('person').has('name','marko').out('knows')
+----
+
+While this method achieves the desired answer, it requires the analyst to traverse the graph in the domain language
+of the graph rather than the domain language of the social network. A more natural way for the analyst to write this
+traversal might be:
+
+[source,java]
+----
+g.persons('marko').knows()
+----
+
+In the statement above, the traversal is written in the language of the domain, abstracting away the underlying
+graph structure from the query. The two traversal results are equivalent and, indeed, the "Social Network DSL" produces
+the same set of traversal steps as the "Graph DSL" thus producing equivalent strategy application and performance
+runtimes.
+
+The following sections explain how to develop application specific DSLs for different <<gremlin-variants,Gremlin Language Variants>>.
+
+[[gremlin-java-dsl]
+Gremlin-Java
+~~~~~~~~~~~~
+
+Creating a DSL in Java requires the `@GremlinDsl` Java annotation in `gremlin-core`. This annotation should be applied
+to a "DSL interface" that extends `GraphTraversal.Admin`.
+
+[source,java]
+----
+@GremlinDsl
+public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+}
+----
+
+IMPORTANT: The name of the DSL interface should be suffixed with "TraversalDSL". All characters in the interface name
+before that become the "name" of the DSL.
+
+In this interface, define the methods that the DSL will be composed of:
+
+[source,java]
+----
+@GremlinDsl
+public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+    public default GraphTraversal<S, Vertex> knows(String personName) {
+        return out("knows").hasLabel("person").has("name", personName);
+    }
+
+    public default <E2 extends Number> GraphTraversal<S, E2> youngestFriendsAge() {
+        return out("knows").hasLabel("person").values("age").min();
+    }
+}
+----
+
+The `@GremlinDsl` annotation is used by the link:https://docs.oracle.com/javase/8/docs/api/index.html?javax/annotation/processing/Processor.html[Java Annotation Processor]
+to generate the boilerplate class structure required to properly use the DSL within the TinkerPop framework. These
+classes can be generated and maintained by hand, but it would be time consuming, monotonous and error-prone to do so.
+Typically, the Java compilation process is automatically configured to detect annotation processors on the classpath
+and will automatically use them when found. If that does not happen, it may be necessary to make configuration changes
+to the build to allow for the compilation process to be aware of the following `javax.annotation.processing.Processor`
+implementation:
+
+[source,java]
+----
+org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDslProcessor
+----
+
+The annotation processor will generate several classes for the DSL:
+
+* `SocialTraversal` - A `Traversal` interface that extends the `SocialTraversalDsl` proxying methods to its underlying
+interfaces (such as `GraphTraversal`) to instead return a `SocialTraversal`
+* `DefaultSocialTraversal` - A default implementation of `SocialTraversal` (typically not used directly by the user)
+* `SocialTraversalSource` - Spawns `DefaultSocialTraversal` instances.
+
+Using the DSL then just involves telling the `Graph` to use it:
+
+[source,java]
+----
+SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
+social.V().has("name","marko").knows("josh");
+----
+
+The `SocialTraversalSource` can also be customized with DSL functions. As an additional step, include a class that
+extends from `GraphTraversalSource` and with a name that is suffixed with "TraversalSourceDsl". Include in this class,
+any custom methods required by the DSL:
+
+[source,java]
+----
+public class SocialTraversalSourceDsl extends GraphTraversalSource {
+
+    public SocialTraversalSourceDsl(final Graph graph, final TraversalStrategies traversalStrategies) {
+        super(graph, traversalStrategies);
+    }
+
+    public SocialTraversalSourceDsl(final Graph graph) {
+        super(graph);
+    }
+
+    public GraphTraversal<Vertex, Vertex> persons(String... names) {
+        GraphTraversalSource clone = this.clone();
+
+        // Manually add a "start" step for the traversal in this case the equivalent of V(). GraphStep is marked
+        // as a "start" step by passing "true" in the constructor.
+        clone.getBytecode().addStep(GraphTraversal.Symbols.V);
+        GraphTraversal<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
+        traversal.asAdmin().addStep(new GraphStep<>(traversal.asAdmin(), Vertex.class, true));
+
+        traversal = traversal.hasLabel("person");
+        if (names.length > 0) traversal = traversal.has("name", P.within(names));
+
+        return traversal;
+    }
+}
+----
+
+Then, back in the `SocialTraversal` interface, update the `GremlinDsl` annotation with the `traversalSource` argument
+to point to the fully qualified class name of the `SocialTraversalSourceDsl`:
+
+[source,java]
+----
+@GremlinDsl(traversalSource = "com.company.SocialTraversalSourceDsl")
+public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+    ...
+}
+----
+
+It is then possible to use the `persons()` method to start traversals:
+
+[source,java]
+----
+SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
+social.persons().count();
+----
+
+NOTE: Using Maven, as shown in the `gremlin-archetype-dsl` module, makes developing DSLs with the annotation processor
+straightforward in that it sets up appropriate paths to the generated code automatically.
+
+Gremlin-Python
+~~~~~~~~~~~~~~


[09/45] tinkerpop git commit: TINKERPOP-768 Implemented basic DSL tooling WIP

Posted by sp...@apache.org.
TINKERPOP-768 Implemented basic DSL tooling WIP


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/844393d3
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/844393d3
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/844393d3

Branch: refs/heads/tp32-glv
Commit: 844393d3067cbfbc5dc94e928be5c3d0537e15af
Parents: 2dbaaa1
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 26 07:01:53 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 gremlin-archetype/gremlin-archetype-dsl/pom.xml |  44 +++
 .../META-INF/maven/archetype-metadata.xml       |  38 +++
 .../archetype-resources/README.asciidoc         |  33 ++
 .../main/resources/archetype-resources/pom.xml  |  63 ++++
 .../src/main/java/SocialTraversalDsl.java       |  41 +++
 .../src/test/java/SocialDslTest.java            |  46 +++
 .../projects/standard/archetype.properties      |  21 ++
 .../test/resources/projects/standard/goal.txt   |   1 +
 gremlin-archetype/pom.xml                       |   1 +
 gremlin-core/pom.xml                            |  36 +++
 .../process/traversal/dsl/GremlinDsl.java       |  36 +++
 .../dsl/GremlinDslAnnotatedInterface.java       |  32 ++
 .../traversal/dsl/GremlinDslProcessor.java      | 318 +++++++++++++++++++
 .../traversal/dsl/ProcessorException.java       |  37 +++
 .../javax.annotation.processing.Processor       |   1 +
 .../traversal/dsl/GremlinDslProcessorTest.java  |  39 +++
 .../traversal/dsl/SocialTraversalDsl.java       |  43 +++
 17 files changed, 830 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-archetype/gremlin-archetype-dsl/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/pom.xml b/gremlin-archetype/gremlin-archetype-dsl/pom.xml
new file mode 100644
index 0000000..d4922f5
--- /dev/null
+++ b/gremlin-archetype/gremlin-archetype-dsl/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>gremlin-archetype</artifactId>
+        <groupId>org.apache.tinkerpop</groupId>
+        <version>3.2.5-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>gremlin-archetype-dsl</artifactId>
+    <name>Apache TinkerPop :: Archetype - TinkerGraph</name>
+    <packaging>jar</packaging>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-archetype-plugin</artifactId>
+                <version>2.4</version>
+            </plugin>
+        </plugins>
+
+        <!-- apply variable substitution on the following files using variables from this pom -->
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+                <includes>
+                    <include>archetype-resources/pom.xml</include>
+                    <include>archetype-resources/README.asciidoc</include>
+                </includes>
+            </resource>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>false</filtering>
+                <excludes>
+                    <exclude>archetype-resources/pom.xml</exclude>
+                    <exclude>archetype-resources/README.asciidoc</exclude>
+                </excludes>
+            </resource>
+        </resources>
+    </build>
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/META-INF/maven/archetype-metadata.xml
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/META-INF/maven/archetype-metadata.xml b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/META-INF/maven/archetype-metadata.xml
new file mode 100644
index 0000000..a159ee3
--- /dev/null
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -0,0 +1,38 @@
+<!--
+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.
+-->
+<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="gremlin-archetype-tinkergraph"
+                      xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
+                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <fileSets>
+        <fileSet filtered="true">
+            <directory></directory>
+            <includes>
+                <include>README.asciidoc</include>
+            </includes>
+            <excludes>
+                <exclude>**/*.xml</exclude>
+            </excludes>
+        </fileSet>
+        <fileSet filtered="true" packaged="true">
+            <directory>src/main/java</directory>
+        </fileSet>
+        <fileSet filtered="true" packaged="true">
+            <directory>src/test/java</directory>
+        </fileSet>
+    </fileSets>
+
+</archetype-descriptor>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc
new file mode 100644
index 0000000..1e131b1
--- /dev/null
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/README.asciidoc
@@ -0,0 +1,33 @@
+////
+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.
+////
+Gremlin DSL
+===========
+
+XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+
+Prerequisites
+-------------
+
+* Java 8 Update 40+
+* link:https://maven.apache.org/[Maven 3.x]
+
+Building and Running
+--------------------
+
+[source,text]
+mvn clean package
+mvn exec:java -Dexec.mainClass="${package}.App"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/pom.xml b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/pom.xml
new file mode 100644
index 0000000..d7bb31c
--- /dev/null
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/pom.xml
@@ -0,0 +1,63 @@
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>${groupId}</groupId>
+    <artifactId>\${artifactId}</artifactId>
+    <version>${version}</version>
+
+    <name>Social DSL: Modern Graph</name>
+
+    <packaging>jar</packaging>
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tinkerpop</groupId>
+            <artifactId>tinkergraph-gremlin</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>${slf4j.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <!-- TinkerPop3 requires Java 8 -->
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.3</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
new file mode 100644
index 0000000..546a328
--- /dev/null
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
@@ -0,0 +1,41 @@
+/*
+ * 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 ${package};
+
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDsl;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+@GremlinDsl
+public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+    public default GraphTraversal<S, Vertex> knows(final String personName) {
+        return out("knows").hasLabel("person").has("name", personName);
+    }
+
+    public default <E2 extends Number> GraphTraversal<S, E2> youngestFriendsAge() {
+        return out("knows").hasLabel("person").values("age").min();
+    }
+
+    @Override
+    public default GraphTraversal<S, E> iterate() {
+        GraphTraversal.Admin.super.iterate();
+        return this;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
new file mode 100644
index 0000000..ddd584c
--- /dev/null
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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 ${package};
+
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class SocialDslTest {
+
+    private Graph graph = TinkerFactory.createModern();
+
+    @Test
+    public void shouldValidateThatMarkoKnowsJosh() {
+        SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
+        assertTrue(social.V().has("name","marko").knows("josh").hasNext());
+    }
+
+    @Test
+    public void shouldGetAgeOfYoungestFriendOfMarko() {
+        SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
+        assertEquals(27, social.V().has("name","marko").youngestFriendsAge().next().intValue());
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-archetype/gremlin-archetype-dsl/src/test/resources/projects/standard/archetype.properties
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/test/resources/projects/standard/archetype.properties b/gremlin-archetype/gremlin-archetype-dsl/src/test/resources/projects/standard/archetype.properties
new file mode 100644
index 0000000..cf98705
--- /dev/null
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/test/resources/projects/standard/archetype.properties
@@ -0,0 +1,21 @@
+# 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.
+
+groupId=org.apache.tinkerpop
+artifactId=gremlin-archetype-dsl
+package=com.test.example
+version=1.0.0-SNAPSHOT
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-archetype/gremlin-archetype-dsl/src/test/resources/projects/standard/goal.txt
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/test/resources/projects/standard/goal.txt b/gremlin-archetype/gremlin-archetype-dsl/src/test/resources/projects/standard/goal.txt
new file mode 100644
index 0000000..4a1a71d
--- /dev/null
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/test/resources/projects/standard/goal.txt
@@ -0,0 +1 @@
+verify
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-archetype/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-archetype/pom.xml b/gremlin-archetype/pom.xml
index fbe808f..961fabc 100644
--- a/gremlin-archetype/pom.xml
+++ b/gremlin-archetype/pom.xml
@@ -30,6 +30,7 @@ limitations under the License.
     <modules>
         <module>gremlin-archetype-tinkergraph</module>
         <module>gremlin-archetype-server</module>
+        <module>gremlin-archetype-dsl</module>
     </modules>
 
     <build>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-core/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-core/pom.xml b/gremlin-core/pom.xml
index 55047ab..989bf83 100644
--- a/gremlin-core/pom.xml
+++ b/gremlin-core/pom.xml
@@ -60,6 +60,11 @@ limitations under the License.
                 </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>com.squareup</groupId>
+            <artifactId>javapoet</artifactId>
+            <version>1.8.0</version>
+        </dependency>
         <!-- LOGGING -->
         <dependency>
             <groupId>org.slf4j</groupId>
@@ -96,6 +101,24 @@ limitations under the License.
             <artifactId>commons-collections</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>com.google.testing.compile</groupId>
+            <artifactId>compile-testing</artifactId>
+            <version>0.8</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.truth</groupId>
+            <artifactId>truth</artifactId>
+            <version>0.25</version>
+            <exclusions>
+                <!-- truth comes in through compile-testing and has a self-conflict - produces further conflict with hadoop-gremlin -->
+                <exclusion>
+                    <groupId>com.google.guava</groupId>
+                    <artifactId>guava</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
     </dependencies>
     <build>
         <directory>${basedir}/target</directory>
@@ -115,6 +138,19 @@ limitations under the License.
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-failsafe-plugin</artifactId>
             </plugin>
+            <!-- disable annotation processing - testing of the GremlinDslProcessor is handled separately -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                    <compilerArgs>
+                        <arg>-parameters</arg>
+                        <arg>-proc:none</arg>
+                    </compilerArgs>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 </project>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
new file mode 100644
index 0000000..370ad9b
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * An annotation that specifies that an interface is meant to be used a DSL extension to a {@link GraphTraversal}.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.CLASS)
+public @interface GremlinDsl {
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslAnnotatedInterface.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslAnnotatedInterface.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslAnnotatedInterface.java
new file mode 100644
index 0000000..2f6db74
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslAnnotatedInterface.java
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+import javax.lang.model.element.TypeElement;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+class GremlinDslAnnotatedInterface {
+    private final TypeElement annotatedInterfaceElement;
+
+    public GremlinDslAnnotatedInterface(final TypeElement interfaceElement) {
+        annotatedInterfaceElement = interfaceElement;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
new file mode 100644
index 0000000..d2bcc65
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -0,0 +1,318 @@
+/*
+ * 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;
+
+import com.squareup.javapoet.ClassName;
+import com.squareup.javapoet.JavaFile;
+import com.squareup.javapoet.MethodSpec;
+import com.squareup.javapoet.ParameterSpec;
+import com.squareup.javapoet.ParameterizedTypeName;
+import com.squareup.javapoet.TypeName;
+import com.squareup.javapoet.TypeSpec;
+import com.squareup.javapoet.TypeVariableName;
+import jdk.nashorn.internal.codegen.types.Type;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+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.step.map.AddVertexStartStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep;
+import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Filer;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.TypeParameterElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.util.Elements;
+import javax.lang.model.util.Types;
+import javax.tools.Diagnostic;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@SupportedAnnotationTypes("org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDsl")
+@SupportedSourceVersion(SourceVersion.RELEASE_8)
+public class GremlinDslProcessor extends AbstractProcessor {
+    private Messager messager;
+    private Elements elementUtils;
+    private Filer filer;
+    private Types typeUtils;
+
+    @Override
+    public synchronized void init(final ProcessingEnvironment processingEnv) {
+        super.init(processingEnv);
+        messager = processingEnv.getMessager();
+        elementUtils = processingEnv.getElementUtils();
+        filer = processingEnv.getFiler();
+        typeUtils = processingEnv.getTypeUtils();
+    }
+
+    @Override
+    public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
+        try {
+            for (Element dslElement : roundEnv.getElementsAnnotatedWith(GremlinDsl.class)) {
+                validateDSL(dslElement);
+
+                final TypeElement annotatedDslType = (TypeElement) dslElement;
+                final String packageName = elementUtils.getPackageOf(dslElement).getQualifiedName().toString();
+
+                // create the Traversal implementation interface
+                final String dslName = dslElement.getSimpleName().toString();
+                final String dslPrefix = dslName.substring(0, dslName.length() - "TraversalDSL".length()); // chop off "TraversalDSL"
+                final String traversalClazz = dslPrefix + "Traversal";
+                final ClassName traversalClassName = ClassName.get(packageName, traversalClazz);
+                final String traversalSourceClazz = dslPrefix + "TraversalSource";
+                final ClassName traversalSourceClassName = ClassName.get(packageName, traversalSourceClazz);
+                final String defaultTraversalClazz = "Default" + traversalClazz;
+                final ClassName defaultTraversalClassName = ClassName.get(packageName, defaultTraversalClazz);
+                final ClassName graphTraversalAdminClassName = ClassName.get(GraphTraversal.Admin.class);
+
+                // START write "Traversal" class
+                final TypeSpec.Builder traversalInterface = TypeSpec.interfaceBuilder(traversalClazz)
+                        .addModifiers(Modifier.PUBLIC)
+                        .addTypeVariables(Arrays.asList(TypeVariableName.get("S"), TypeVariableName.get("E")))
+                        .addSuperinterface(TypeName.get(dslElement.asType()));
+
+                // process the methods of the GremlinDsl annotated class
+                for (Element elementOfDsl : annotatedDslType.getEnclosedElements()) {
+                    tryConstructMethod(elementOfDsl, traversalClassName, dslName, null,
+                            Modifier.PUBLIC, Modifier.DEFAULT).ifPresent(traversalInterface::addMethod);
+                }
+
+                // process the methods of GraphTraversal
+                final TypeElement graphTraversalElement = elementUtils.getTypeElement(GraphTraversal.class.getCanonicalName());
+                for (Element elementOfGraphTraversal : graphTraversalElement.getEnclosedElements()) {
+                    tryConstructMethod(elementOfGraphTraversal, traversalClassName, dslName,
+                            e -> e.getSimpleName().contentEquals("asAdmin") || e.getSimpleName().contentEquals("iterate"),
+                            Modifier.PUBLIC, Modifier.DEFAULT)
+                            .ifPresent(traversalInterface::addMethod);
+                }
+
+                final JavaFile traversalJavaFile = JavaFile.builder(packageName, traversalInterface.build()).build();
+                traversalJavaFile.writeTo(filer);
+                // END write "Traversal" class
+
+                // START write of the "DefaultTraversal" class
+                final TypeSpec.Builder defaultTraversalClass = TypeSpec.classBuilder(defaultTraversalClazz)
+                        .addModifiers(Modifier.PUBLIC)
+                        .addTypeVariables(Arrays.asList(TypeVariableName.get("S"), TypeVariableName.get("E")))
+                        .superclass(TypeName.get(elementUtils.getTypeElement(DefaultTraversal.class.getCanonicalName()).asType()))
+                        .addSuperinterface(ParameterizedTypeName.get(traversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")));
+
+                // add the required constructors for instantiation
+                defaultTraversalClass.addMethod(MethodSpec.constructorBuilder()
+                        .addModifiers(Modifier.PUBLIC)
+                        .addStatement("super()")
+                        .build());
+                defaultTraversalClass.addMethod(MethodSpec.constructorBuilder()
+                        .addModifiers(Modifier.PUBLIC)
+                        .addParameter(Graph.class, "graph")
+                        .addStatement("super($N)", "graph")
+                        .build());
+                defaultTraversalClass.addMethod(MethodSpec.constructorBuilder()
+                        .addModifiers(Modifier.PUBLIC)
+                        .addParameter(traversalSourceClassName, "traversalSource")
+                        .addStatement("super($N)", "traversalSource")
+                        .build());
+
+                // add the override
+                defaultTraversalClass.addMethod(MethodSpec.methodBuilder("iterate")
+                        .addModifiers(Modifier.PUBLIC)
+                        .addAnnotation(Override.class)
+                        .addStatement("return ($T) super.iterate()", traversalClassName)
+                        .returns(ParameterizedTypeName.get(traversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
+                        .build());
+                defaultTraversalClass.addMethod(MethodSpec.methodBuilder("asAdmin")
+                        .addModifiers(Modifier.PUBLIC)
+                        .addAnnotation(Override.class)
+                        .addStatement("return ($T) super.asAdmin()", GraphTraversal.Admin.class)
+                        .returns(ParameterizedTypeName.get(graphTraversalAdminClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
+                        .build());
+                defaultTraversalClass.addMethod(MethodSpec.methodBuilder("clone")
+                        .addModifiers(Modifier.PUBLIC)
+                        .addAnnotation(Override.class)
+                        .addStatement("return ($T) super.clone()", defaultTraversalClassName)
+                        .returns(ParameterizedTypeName.get(defaultTraversalClassName, TypeVariableName.get("S"), TypeVariableName.get("E")))
+                        .build());
+
+                final JavaFile defaultTraversalJavaFile = JavaFile.builder(packageName, defaultTraversalClass.build()).build();
+                defaultTraversalJavaFile.writeTo(filer);
+                // END write of the "DefaultTraversal" class
+
+                // START write "TraversalSource" class
+                final TypeElement graphTraversalSourceElement = elementUtils.getTypeElement(GraphTraversalSource.class.getCanonicalName());
+                final TypeSpec.Builder traversalSourceClass = TypeSpec.classBuilder(traversalSourceClazz)
+                        .addModifiers(Modifier.PUBLIC)
+                        .superclass(TypeName.get(graphTraversalSourceElement.asType()));
+
+                // add the required constructors for instantiation
+                traversalSourceClass.addMethod(MethodSpec.constructorBuilder()
+                        .addModifiers(Modifier.PUBLIC)
+                        .addParameter(Graph.class, "graph")
+                        .addStatement("super($N)", "graph")
+                        .build());
+                traversalSourceClass.addMethod(MethodSpec.constructorBuilder()
+                        .addModifiers(Modifier.PUBLIC)
+                        .addParameter(Graph.class, "graph")
+                        .addParameter(TraversalStrategies.class, "strategies")
+                        .addStatement("super($N, $N)", "graph", "strategies")
+                        .build());
+
+                // override methods to return a the DSL TraversalSource
+                for (Element elementOfGraphTraversal : graphTraversalSourceElement.getEnclosedElements()) {
+                    // first copy/override methods that return a GraphTraversalSource so that we can instead return
+                    // the DSL TraversalSource class.
+                    tryConstructMethod(elementOfGraphTraversal, traversalSourceClassName, "",
+                            e -> !(e.getReturnType().getKind() == TypeKind.DECLARED && ((DeclaredType) e.getReturnType()).asElement().getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())),
+                            Modifier.PUBLIC)
+                            .ifPresent(traversalSourceClass::addMethod);
+                }
+
+                // override methods that return GraphTraversal
+                traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
+                        .addModifiers(Modifier.PUBLIC)
+                        .addAnnotation(Override.class)
+                        .addStatement("$N clone = this.clone()", traversalSourceClazz)
+                        .addStatement("clone.bytecode.addStep($T.addV)", GraphTraversal.Symbols.class)
+                        .addStatement("$N traversal = new $N(clone)", defaultTraversalClazz, defaultTraversalClazz)
+                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, null))", traversalClassName, AddVertexStartStep.class)
+                        .returns(ParameterizedTypeName.get(traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
+                        .build());
+                traversalSourceClass.addMethod(MethodSpec.methodBuilder("addV")
+                        .addModifiers(Modifier.PUBLIC)
+                        .addAnnotation(Override.class)
+                        .addParameter(String.class, "label")
+                        .addStatement("$N clone = this.clone()", traversalSourceClazz)
+                        .addStatement("clone.bytecode.addStep($T.addV, label)", GraphTraversal.Symbols.class)
+                        .addStatement("$N traversal = new $N(clone)", defaultTraversalClazz, defaultTraversalClazz)
+                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, label))", traversalClassName, AddVertexStartStep.class)
+                        .returns(ParameterizedTypeName.get(traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
+                        .build());
+                traversalSourceClass.addMethod(MethodSpec.methodBuilder("V")
+                        .addModifiers(Modifier.PUBLIC)
+                        .addAnnotation(Override.class)
+                        .addParameter(Object[].class, "vertexIds")
+                        .varargs(true)
+                        .addStatement("$N clone = this.clone()", traversalSourceClazz)
+                        .addStatement("clone.bytecode.addStep($T.V, vertexIds)", GraphTraversal.Symbols.class)
+                        .addStatement("$N traversal = new $N(clone)", defaultTraversalClazz, defaultTraversalClazz)
+                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, vertexIds))", traversalClassName, GraphStep.class, Vertex.class)
+                        .returns(ParameterizedTypeName.get(traversalClassName, ClassName.get(Vertex.class), ClassName.get(Vertex.class)))
+                        .build());
+                traversalSourceClass.addMethod(MethodSpec.methodBuilder("E")
+                        .addModifiers(Modifier.PUBLIC)
+                        .addAnnotation(Override.class)
+                        .addParameter(Object[].class, "edgeIds")
+                        .varargs(true)
+                        .addStatement("$N clone = this.clone()", traversalSourceClazz)
+                        .addStatement("clone.bytecode.addStep($T.E, edgeIds)", GraphTraversal.Symbols.class)
+                        .addStatement("$N traversal = new $N(clone)", defaultTraversalClazz, defaultTraversalClazz)
+                        .addStatement("return ($T) traversal.asAdmin().addStep(new $T(traversal, $T.class, true, edgeIds))", traversalClassName, GraphStep.class, Edge.class)
+                        .returns(ParameterizedTypeName.get(traversalClassName, ClassName.get(Edge.class), ClassName.get(Edge.class)))
+                        .build());
+
+                final JavaFile traversalSourceJavaFile = JavaFile.builder(packageName, traversalSourceClass.build()).build();
+                traversalSourceJavaFile.writeTo(filer);
+                // END write "TraversalSource" class
+            }
+        } catch (Exception ex) {
+            messager.printMessage(Diagnostic.Kind.ERROR, ex.getMessage());
+        }
+
+        return true;
+    }
+
+    private Optional<MethodSpec> tryConstructMethod(final Element element, final ClassName returnClazz, final String parent,
+                                                    final Predicate<ExecutableElement> ignore, final Modifier... modifiers) {
+        if (element.getKind() != ElementKind.METHOD) return Optional.empty();
+
+        final ExecutableElement templateMethod = (ExecutableElement) element;
+        final String methodName = templateMethod.getSimpleName().toString();
+
+        if (ignore != null && ignore.test(templateMethod)) return Optional.empty();
+
+        final DeclaredType returnTypeMirror = (DeclaredType) templateMethod.getReturnType();
+        final List<? extends TypeMirror> returnTypeArguments = returnTypeMirror.getTypeArguments();
+
+        // build a return type with appropriate generic declarations (if such declarations are present)
+        final TypeName returnType = returnTypeArguments.isEmpty() ?
+                returnClazz :
+                ParameterizedTypeName.get(returnClazz, returnTypeArguments.stream().map(TypeName::get).collect(Collectors.toList()).toArray(new TypeName[returnTypeArguments.size()]));
+        final MethodSpec.Builder methodToAdd = MethodSpec.methodBuilder(methodName)
+                .addModifiers(modifiers)
+                .addAnnotation(Override.class)
+                .addExceptions(templateMethod.getThrownTypes().stream().map(TypeName::get).collect(Collectors.toList()))
+                .returns(returnType);
+
+        templateMethod.getTypeParameters().forEach(tp -> methodToAdd.addTypeVariable(TypeVariableName.get(tp)));
+
+        boolean added = false;
+        final List<? extends VariableElement> parameters = templateMethod.getParameters();
+        final String parentCall = parent.isEmpty() ? "" : parent + ".";
+        String body = "return (" + returnClazz.simpleName() + ") " + parentCall + "super." + methodName + "(";
+        for (VariableElement param : parameters) {
+            methodToAdd.addParameter(ParameterSpec.get(param));
+
+            body = body + param.getSimpleName() + ",";
+            added = true;
+        }
+
+        // treat a final array as a varargs param
+        if (!parameters.isEmpty() && parameters.get(parameters.size() - 1).asType().getKind() == TypeKind.ARRAY)
+            methodToAdd.varargs(true);
+
+        if (added) body = body.substring(0, body.length() - 1);
+
+        body = body + ")";
+        methodToAdd.addStatement(body);
+
+        return Optional.of(methodToAdd.build());
+    }
+
+    private void validateDSL(final Element dslElement) throws ProcessorException {
+        if (dslElement.getKind() != ElementKind.INTERFACE)
+            throw new ProcessorException(dslElement, "Only interfaces can be annotated with @%s", GremlinDsl.class.getSimpleName());
+
+        final TypeElement typeElement = (TypeElement) dslElement;
+        if (!typeElement.getModifiers().contains(Modifier.PUBLIC))
+            throw new ProcessorException(dslElement, "The interface %s is not public.", typeElement.getQualifiedName());
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/ProcessorException.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/ProcessorException.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/ProcessorException.java
new file mode 100644
index 0000000..c84278e
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/ProcessorException.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+import javax.lang.model.element.Element;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class ProcessorException extends Exception {
+    private Element element;
+
+    public ProcessorException(final Element element, final String msg, final Object... args) {
+        super(String.format(msg, args));
+        this.element = element;
+    }
+
+    public Element getElement() {
+        return element;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-core/src/main/resources/META-INF/services/javax.annotation.processing.Processor
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/gremlin-core/src/main/resources/META-INF/services/javax.annotation.processing.Processor
new file mode 100644
index 0000000..bd34c93
--- /dev/null
+++ b/gremlin-core/src/main/resources/META-INF/services/javax.annotation.processing.Processor
@@ -0,0 +1 @@
+org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDslProcessor
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
new file mode 100644
index 0000000..c3c62cd
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+import com.google.testing.compile.JavaFileObjects;
+import org.junit.Test;
+
+import static com.google.common.truth.Truth.ASSERT;
+import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class GremlinDslProcessorTest {
+
+    @Test
+    public void shouldCompile() {
+        ASSERT.about(javaSource())
+                .that(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialTraversalDsl.java")))
+                .processedWith(new GremlinDslProcessor())
+                .compilesWithoutError();
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/844393d3/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
new file mode 100644
index 0000000..af53dd2
--- /dev/null
+++ b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
@@ -0,0 +1,43 @@
+/*
+ * 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.util.dsl;
+
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDsl;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@GremlinDsl
+public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
+    public default GraphTraversal<S, Vertex> knows(final String personName) {
+        return out("knows").hasLabel("person").has("name", personName);
+    }
+
+    public default <E2 extends Number> GraphTraversal<S, E2> meanAgeOfFriends() {
+        return out("knows").hasLabel("person").properties("age").mean();
+    }
+
+    @Override
+    public default GraphTraversal<S, E> iterate() {
+        GraphTraversal.Admin.super.iterate();
+        return this;
+    }
+}


[39/45] tinkerpop git commit: TINKERPOP-786 Updated upgrade docs with DSL info

Posted by sp...@apache.org.
TINKERPOP-786 Updated upgrade docs with DSL info


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/869ba9a4
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/869ba9a4
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/869ba9a4

Branch: refs/heads/tp32-glv
Commit: 869ba9a45ee8ef897e40fa65d61ce1ac4598bea5
Parents: db9343f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed May 24 05:10:22 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed May 24 05:10:22 2017 -0400

----------------------------------------------------------------------
 .../upgrade/release-3.2.x-incubating.asciidoc   | 25 ++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/869ba9a4/docs/src/upgrade/release-3.2.x-incubating.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.2.x-incubating.asciidoc b/docs/src/upgrade/release-3.2.x-incubating.asciidoc
index a2045e4..eeb193e 100644
--- a/docs/src/upgrade/release-3.2.x-incubating.asciidoc
+++ b/docs/src/upgrade/release-3.2.x-incubating.asciidoc
@@ -32,6 +32,27 @@ Please see the link:https://github.com/apache/tinkerpop/blob/3.2.5/CHANGELOG.asc
 Upgrading for Users
 ~~~~~~~~~~~~~~~~~~~
 
+DSL Support
+^^^^^^^^^^^
+
+It has always been possible to construct Domain Specific Languages (DSLs) with Gremlin, but the approach has required
+a somewhat deep understanding of the TinkerPop code base and it is not something that has had a recommeded method
+for implementation. With this release, TinkerPop simplifies DSL development and provides the best practices for their
+implementation.
+
+[source,java]
+----
+// standard Gremlin
+g.V().hasLabel('person').
+  where(outE("created").count().is(P.gte(2))).count()
+
+// the same traversal as above written as a DSL
+social.persons().where(createdAtLeast(2)).count()
+----
+
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-786[TINKERPOP-786],
+link:http://tinkerpop.apache.org/docs/3.2.5/dev/reference/#dsl[Reference Documentation]
+
 Authentication Configuration
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
@@ -40,7 +61,7 @@ authentication handler and channelizer classes to use. This has been deprecated
 A class that extends `AbstractAuthenticationHandler` may also now be provided as `authentication.authenticationHandler`
 to be used in either of the provided channelizer classes to handle the provided authenticator
 
-See: https://issues.apache.org/jira/browse/TINKERPOP-1657[TINKERPOP-1657]
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-1657[TINKERPOP-1657]
 
 Default Maximum Parameters
 ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -72,7 +93,7 @@ be helpful in understanding usage problems. As `GremlinScriptEngine` instances a
 are naturally exposed as part of the standard link:http://tinkerpop.apache.org/docs/current/reference/#_metrics[metrics]
 set. Note that metrics are captured for both sessionless requests as well as for each individual session that is opened.
 
-See: https://issues.apache.org/jira/browse/TINKERPOP-1644[TINKERPOP-1644]
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-1644[TINKERPOP-1644]
 
 Additional Error Information
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^


[31/45] tinkerpop git commit: TINKERPOP-786 Made python DSL example like the java example

Posted by sp...@apache.org.
TINKERPOP-786 Made python DSL example like the java example


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/5e09caf1
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/5e09caf1
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/5e09caf1

Branch: refs/heads/tp32-glv
Commit: 5e09caf175e8c89695718a4987bff8fd241f8147
Parents: a3d42d5
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu May 11 08:55:51 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:31 2017 -0400

----------------------------------------------------------------------
 gremlin-python/src/main/jython/tests/process/test_dsl.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5e09caf1/gremlin-python/src/main/jython/tests/process/test_dsl.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/process/test_dsl.py b/gremlin-python/src/main/jython/tests/process/test_dsl.py
index 92196fe..04313ab 100644
--- a/gremlin-python/src/main/jython/tests/process/test_dsl.py
+++ b/gremlin-python/src/main/jython/tests/process/test_dsl.py
@@ -57,16 +57,21 @@ class SocialTraversalSource(GraphTraversalSource):
         super(SocialTraversalSource, self).__init__(*args, **kwargs)
         self.graph_traversal = SocialTraversal
 
-    def persons(self):
+    def persons(self, *args):
         traversal = self.get_graph_traversal()
         traversal.bytecode.add_step("V")
         traversal.bytecode.add_step("hasLabel", "person")
+
+        if len(args) > 0:
+            traversal.bytecode.add_step("has", "name", P.within(args))
+
         return traversal
 
 
 def test_dsl(remote_connection):
     social = Graph().traversal(SocialTraversalSource).withRemote(remote_connection)
-    assert social.V().has("name", "marko").knows("josh").next()
-    assert social.V().has("name", "marko").youngestFriendsAge().next() == 27
+    assert social.persons("marko").knows("josh").next()
+    assert social.persons("marko").youngestFriendsAge().next() == 27
     assert social.persons().count().next() == 4
+    assert social.persons("marko", "josh").count().next() == 2
     assert social.persons().filter(___.createdAtLeast(2)).count().next() == 1


[42/45] tinkerpop git commit: Merge branch 'pr-609' into tp32

Posted by sp...@apache.org.
Merge branch 'pr-609' into tp32


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/8812f85a
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/8812f85a
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/8812f85a

Branch: refs/heads/tp32-glv
Commit: 8812f85a022a9de0592bae5de8a0dd5503a9c86b
Parents: 1ee5b37 6813e9e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu May 25 09:53:20 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu May 25 09:53:20 2017 -0400

----------------------------------------------------------------------
 .../remote/traversal/step/map/RemoteStep.java    | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------



[20/45] tinkerpop git commit: TINKERPOP-786 Improved TraversalSource for testing purposes

Posted by sp...@apache.org.
TINKERPOP-786 Improved TraversalSource for testing purposes


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e661359a
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e661359a
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e661359a

Branch: refs/heads/tp32-glv
Commit: e661359a9a760bb398b590c9c1bffa8268463f78
Parents: b47b25c
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 13:52:42 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:51 2017 -0400

----------------------------------------------------------------------
 .../dsl/SocialPackageTraversalSourceDsl.java         | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e661359a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java
index 143a5c9..64859eb 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialPackageTraversalSourceDsl.java
@@ -44,11 +44,16 @@ public class SocialPackageTraversalSourceDsl extends GraphTraversalSource {
         super(graph);
     }
 
-    public GraphTraversal<Vertex, Vertex> persons() {
-        final GraphTraversalSource clone = this.clone();
+    public GraphTraversal<Vertex, Vertex> persons(String... names) {
+        GraphTraversalSource clone = this.clone();
+
         clone.getBytecode().addStep(GraphTraversal.Symbols.V);
-        clone.getBytecode().addStep(GraphTraversal.Symbols.hasLabel, "person");
-        final GraphTraversal.Admin<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
-        return TraversalHelper.addHasContainer(traversal.addStep(new GraphStep<>(traversal, Vertex.class, true)), new HasContainer(T.label.getAccessor(), P.eq("person")));
+        GraphTraversal<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
+        traversal.asAdmin().addStep(new GraphStep<>(traversal.asAdmin(), Vertex.class, true));
+
+        traversal = traversal.hasLabel("person");
+        if (names.length > 0) traversal = traversal.has("name", P.within(names));
+
+        return traversal;
     }
 }


[12/45] tinkerpop git commit: TINKERPOP-786 Fixed gremlin syntax in test DSL files

Posted by sp...@apache.org.
TINKERPOP-786 Fixed gremlin syntax in test DSL files


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/fe702fe7
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/fe702fe7
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/fe702fe7

Branch: refs/heads/tp32-glv
Commit: fe702fe7e8c01065adccde0271851a39e5af5a23
Parents: be3ed44
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 27 15:40:41 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java      | 2 +-
 .../gremlin/process/traversal/dsl/SocialTraversalDsl.java          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fe702fe7/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
index 1db1dff..1ef5ca8 100644
--- a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
+++ b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialMoveTraversalDsl.java
@@ -32,6 +32,6 @@ public interface SocialMoveTraversalDsl<S, E> extends GraphTraversal.Admin<S, E>
     }
 
     public default <E2 extends Number> GraphTraversal<S, E2> meanAgeOfFriends() {
-        return out("knows").hasLabel("person").properties("age").mean();
+        return out("knows").hasLabel("person").values("age").mean();
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fe702fe7/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
index fc4921f..c3c40a3 100644
--- a/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
+++ b/gremlin-core/src/test/resources/org/apache/tinkerpop/gremlin/process/traversal/dsl/SocialTraversalDsl.java
@@ -32,6 +32,6 @@ public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
     }
 
     public default <E2 extends Number> GraphTraversal<S, E2> meanAgeOfFriends() {
-        return out("knows").hasLabel("person").properties("age").mean();
+        return out("knows").hasLabel("person").values("age").mean();
     }
 }


[30/45] tinkerpop git commit: TINKERPOP-786 Added a note to docs about generic naming

Posted by sp...@apache.org.
TINKERPOP-786 Added a note to docs about generic naming


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/911d17fe
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/911d17fe
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/911d17fe

Branch: refs/heads/tp32-glv
Commit: 911d17fe09aa16304c386b8e031ec9a677751be7
Parents: e0505d1
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed May 10 15:27:56 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:31 2017 -0400

----------------------------------------------------------------------
 docs/src/reference/the-traversal.asciidoc | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/911d17fe/docs/src/reference/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/the-traversal.asciidoc b/docs/src/reference/the-traversal.asciidoc
index 7da4015..ec0bed9 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -3008,6 +3008,9 @@ public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
 }
 ----
 
+IMPORTANT: Follow the TinkerPop convention of using `<S,E>` in naming generics as those conventions are taken into
+account when generating the anonymous traversal class.
+
 The `@GremlinDsl` annotation is used by the link:https://docs.oracle.com/javase/8/docs/api/index.html?javax/annotation/processing/Processor.html[Java Annotation Processor]
 to generate the boilerplate class structure required to properly use the DSL within the TinkerPop framework. These
 classes can be generated and maintained by hand, but it would be time consuming, monotonous and error-prone to do so.


[17/45] tinkerpop git commit: TINKERPOP-786 Bumped to 0.10 of google compile-test

Posted by sp...@apache.org.
TINKERPOP-786 Bumped to 0.10 of google compile-test


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/ef359dda
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/ef359dda
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/ef359dda

Branch: refs/heads/tp32-glv
Commit: ef359ddabaf673e26bc5a4d099c6106abb4d44d9
Parents: 7790716
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Sat Apr 29 06:53:15 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 gremlin-core/pom.xml                            |  6 ++-
 .../traversal/dsl/GremlinDslProcessorTest.java  | 41 ++++++++++----------
 2 files changed, 25 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef359dda/gremlin-core/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-core/pom.xml b/gremlin-core/pom.xml
index 989bf83..0efadfa 100644
--- a/gremlin-core/pom.xml
+++ b/gremlin-core/pom.xml
@@ -104,21 +104,23 @@ limitations under the License.
         <dependency>
             <groupId>com.google.testing.compile</groupId>
             <artifactId>compile-testing</artifactId>
-            <version>0.8</version>
+            <version>0.10</version>
             <scope>test</scope>
         </dependency>
+        <!--
         <dependency>
             <groupId>com.google.truth</groupId>
             <artifactId>truth</artifactId>
             <version>0.25</version>
             <exclusions>
-                <!-- truth comes in through compile-testing and has a self-conflict - produces further conflict with hadoop-gremlin -->
+                truth comes in through compile-testing and has a self-conflict - produces further conflict with hadoop-gremlin
                 <exclusion>
                     <groupId>com.google.guava</groupId>
                     <artifactId>guava</artifactId>
                 </exclusion>
             </exclusions>
         </dependency>
+-->
     </dependencies>
     <build>
         <directory>${basedir}/target</directory>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef359dda/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
index 982ec5b..5df010d 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessorTest.java
@@ -18,13 +18,14 @@
  */
 package org.apache.tinkerpop.gremlin.process.traversal.dsl;
 
+import com.google.testing.compile.Compilation;
 import com.google.testing.compile.JavaFileObjects;
 import org.junit.Test;
 
 import javax.tools.StandardLocation;
 
-import static com.google.common.truth.Truth.ASSERT;
-import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource;
+import static com.google.testing.compile.CompilationSubject.assertThat;
+import static com.google.testing.compile.Compiler.javac;
 
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
@@ -33,35 +34,35 @@ public class GremlinDslProcessorTest {
 
     @Test
     public void shouldCompileToDefaultPackage() {
-        ASSERT.about(javaSource())
-                .that(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialTraversalDsl.java")))
-                .processedWith(new GremlinDslProcessor())
-                .compilesWithoutError();
+        Compilation compilation = javac()
+                .withProcessors(new GremlinDslProcessor())
+                .compile(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialTraversalDsl.java")));
+        assertThat(compilation).succeededWithoutWarnings();
     }
 
     @Test
     public void shouldCompileAndMovePackage() {
-        ASSERT.about(javaSource())
-                .that(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialMoveTraversalDsl.java")))
-                .processedWith(new GremlinDslProcessor())
-                .compilesWithoutError()
-                .and()
-                .generatesFileNamed(StandardLocation.SOURCE_OUTPUT, "org.apache.tinkerpop.gremlin.process.traversal.dsl.social", "SocialMoveTraversal.java");
+        Compilation compilation = javac()
+                .withProcessors(new GremlinDslProcessor())
+                .compile(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialMoveTraversalDsl.java")));
+        assertThat(compilation).succeededWithoutWarnings();
+        assertThat(compilation)
+                .generatedFile(StandardLocation.SOURCE_OUTPUT, "org.apache.tinkerpop.gremlin.process.traversal.dsl.social", "SocialMoveTraversal.java");
     }
 
     @Test
     public void shouldCompileTraversalAndTraversalSourceToDefaultPackage() {
-        ASSERT.about(javaSource())
-                .that(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialPackageTraversalDsl.java")))
-                .processedWith(new GremlinDslProcessor())
-                .compilesWithoutError();
+        Compilation compilation = javac()
+                .withProcessors(new GremlinDslProcessor())
+                .compile(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialPackageTraversalDsl.java")));
+        assertThat(compilation).succeededWithoutWarnings();
     }
 
     @Test
     public void shouldCompileWithNoDefaultMethods() {
-        ASSERT.about(javaSource())
-                .that(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialNoDefaultMethodsTraversalDsl.java")))
-                .processedWith(new GremlinDslProcessor())
-                .compilesWithoutError();
+        Compilation compilation = javac()
+                .withProcessors(new GremlinDslProcessor())
+                .compile(JavaFileObjects.forResource(GremlinDsl.class.getResource("SocialNoDefaultMethodsTraversalDsl.java")));
+        assertThat(compilation).succeededWithoutWarnings();
     }
 }


[36/45] tinkerpop git commit: Merge branch 'tp31' into tp32

Posted by sp...@apache.org.
Merge branch 'tp31' into tp32


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/afa3432e
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/afa3432e
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/afa3432e

Branch: refs/heads/tp32-glv
Commit: afa3432e4046a0c450ac5c71106ab056c3131926
Parents: abe23d4 07bca45
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon May 22 09:50:54 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon May 22 09:50:54 2017 -0400

----------------------------------------------------------------------
 docs/src/reference/the-graph.asciidoc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/afa3432e/docs/src/reference/the-graph.asciidoc
----------------------------------------------------------------------


[16/45] tinkerpop git commit: TINKERPOP-786 Added a bunch of javadoc

Posted by sp...@apache.org.
TINKERPOP-786 Added a bunch of javadoc


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/ffe4c05d
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/ffe4c05d
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/ffe4c05d

Branch: refs/heads/tp32-glv
Commit: ffe4c05d47cf6e976c1b29a1528fd2498e718966
Parents: cf53e13
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Apr 28 16:07:00 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../process/traversal/dsl/GremlinDsl.java        | 19 +++++++++++++++++--
 .../traversal/dsl/GremlinDslProcessor.java       |  2 ++
 .../traversal/dsl/ProcessorException.java        |  2 ++
 3 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ffe4c05d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
index d08736e..15b93d6 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDsl.java
@@ -27,7 +27,21 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
 /**
- * An annotation that specifies that an interface is meant to be used a DSL extension to a {@link GraphTraversal}.
+ * An annotation that specifies that an interface is meant to be used to produce Gremlin DSL. This annotation should
+ * be applied to an interface that extends {@link GraphTraversal}. This interface should be suffixed with
+ * {@code TraversalDsl}. The DSL classes will be generated to the package of the annotated class or the to the value
+ * specified in the {@link #packageName()} and will use the part of the interface name up to the suffix to generate
+ * the classes. Therefore, assuming an interface, annotated with {@code GremlinDsl}, called {@code SocialTraversalDsl},
+ * there will be three classes generated:
+ *
+ * <ul>
+ *     <li>{@code SocialTraversal} - an interface that is an extension to {@code SocialTraversalDsl}</li>
+ *     <li>{@code DefaultSocialTraversal} - an implementation of the {@code SocialTraversal}</li>
+ *     <li>{@code SocialTraversalSource} - an extension of {@link GraphTraversalSource} which spawns {@code DefaultSocialTraversal} instances</li>
+ * </ul>
+ *
+ * Together these generated classes provide all the infrastructure required to properly Gremlin traversals enhanced
+ * with domain specific steps.
  *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
@@ -42,7 +56,8 @@ public @interface GremlinDsl {
     public String packageName() default "";
 
     /**
-     * Defines the optional canonical name of the {@link GraphTraversalSource} that this DSL should extend from.
+     * Defines the optional canonical name of the {@link GraphTraversalSource} that this DSL should extend from. If
+     * this value is not supplied the generated "source" will simply extend from {@link GraphTraversalSource}.
      */
     public String traversalSource() default "org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource";
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ffe4c05d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index 6a09ef5..9e23410 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -65,6 +65,8 @@ import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
 /**
+ * A custom Java annotation processor for the {@link GremlinDsl} annotation that helps to generate DSLs classes.
+ *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 @SupportedAnnotationTypes("org.apache.tinkerpop.gremlin.process.traversal.dsl.GremlinDsl")

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ffe4c05d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/ProcessorException.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/ProcessorException.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/ProcessorException.java
index c84278e..3051890 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/ProcessorException.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/ProcessorException.java
@@ -21,6 +21,8 @@ package org.apache.tinkerpop.gremlin.process.traversal.dsl;
 import javax.lang.model.element.Element;
 
 /**
+ * Exception thrown by the {@link GremlinDslProcessor}.
+ *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class ProcessorException extends Exception {


[28/45] tinkerpop git commit: TINKERPOP-786 Updated reference docs for dsl archetype

Posted by sp...@apache.org.
TINKERPOP-786 Updated reference docs for dsl archetype


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/a96544f0
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/a96544f0
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/a96544f0

Branch: refs/heads/tp32-glv
Commit: a96544f08ebc44dcfb14971682c7ef1a39d878a8
Parents: 3142aee
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu May 11 11:43:17 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:31 2017 -0400

----------------------------------------------------------------------
 docs/src/reference/gremlin-applications.asciidoc | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a96544f0/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc
index 7e25585..e62ce86 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -2129,6 +2129,7 @@ Gremlin Archetypes
 TinkerPop has a number of link:https://maven.apache.org/guides/introduction/introduction-to-archetypes.html[Maven archetypes],
 which provide example project templates to quickly get started with TinkerPop. The available archetypes are as follows:
 
+* `gremlin-archetype-dsl` - An example project that demonstrates how to build Domain Specific Languages with Gremlin in Java.
 * `gremlin-archetype-server` - An example project that demonstrates the basic structure of a
 <<gremlin-server,Gremlin Server>> project, how to connect with the Gremlin Driver, and how to embed Gremlin Server in
 a testing framework.


[23/45] tinkerpop git commit: TINKERPOP-786 Updated changelog for DSL work

Posted by sp...@apache.org.
TINKERPOP-786 Updated changelog for DSL work


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/5c7f0cbd
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/5c7f0cbd
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/5c7f0cbd

Branch: refs/heads/tp32-glv
Commit: 5c7f0cbd1f8a294d0a98f257cd62a327cc4fd345
Parents: 50f2dac
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 13:58:05 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:30 2017 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5c7f0cbd/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 7057aac..dbfe181 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,8 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Added the `gremlin-archetype-dsl` to demonstrate how to structure a Maven project for a DSL.
+* Developed and documented patterns for Domain Specific Language implementations.
 * Now using Groovy `[...]` map notation in `GroovyTranslator` instead of `new LinkedHashMap(){{ }}`.
 * Maintained type information on `Traversal.promise()`.
 * Propagated exception to `Future` instead of calling thread in `RemoteConnection`.


[32/45] tinkerpop git commit: TINKERPOP-786 Refactoring the DSL processor

Posted by sp...@apache.org.
TINKERPOP-786 Refactoring the DSL processor

Abstracted some duplicate code to a single method to clean up a bit more.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/db9343f0
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/db9343f0
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/db9343f0

Branch: refs/heads/tp32-glv
Commit: db9343f09bff33d4d8f178afc4f3ddc2a9cdbf51
Parents: 7963dc2
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 12 10:31:39 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:31 2017 -0400

----------------------------------------------------------------------
 .../traversal/dsl/GremlinDslProcessor.java      | 103 +++++--------------
 1 file changed, 27 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/db9343f0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
index 3358143..5088d21 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/GremlinDslProcessor.java
@@ -152,26 +152,7 @@ public class GremlinDslProcessor extends AbstractProcessor {
                     methodToAdd.addTypeVariable(TypeVariableName.get(((TypeVariable) rtm).asElement().getSimpleName().toString()));
             });
 
-            boolean added = false;
-            final List<? extends VariableElement> parameters = templateMethod.getParameters();
-            String body = "return __.<S>start().$L(";
-            for (VariableElement param : parameters) {
-                methodToAdd.addParameter(ParameterSpec.get(param));
-
-                body = body + param.getSimpleName() + ",";
-                added = true;
-            }
-
-            // treat a final array as a varargs param
-            if (!parameters.isEmpty() && parameters.get(parameters.size() - 1).asType().getKind() == TypeKind.ARRAY)
-                methodToAdd.varargs(true);
-
-            if (added) body = body.substring(0, body.length() - 1);
-
-            body = body + ")";
-
-            methodToAdd.addStatement(body, methodName);
-
+            addMethodBody(methodToAdd, templateMethod, "return __.<S>start().$L(", ")", methodName);
             anonymousClass.addMethod(methodToAdd.build());
         }
 
@@ -189,37 +170,17 @@ public class GremlinDslProcessor extends AbstractProcessor {
 
             templateMethod.getTypeParameters().forEach(tp -> methodToAdd.addTypeVariable(TypeVariableName.get(tp)));
 
-            boolean added = false;
-            final List<? extends VariableElement> parameters = templateMethod.getParameters();
-            String body;
             if (methodName.equals("__")) {
-                for (VariableElement param : parameters) {
+                for (VariableElement param : templateMethod.getParameters()) {
                     methodToAdd.addParameter(ParameterSpec.get(param));
                 }
 
                 methodToAdd.varargs(true);
-
-                body = "return inject(starts)";
+                methodToAdd.addStatement("return inject(starts)", methodName);
             } else {
-                body = "return __.<A>start().$L(";
-                for (VariableElement param : parameters) {
-                    methodToAdd.addParameter(ParameterSpec.get(param));
-
-                    body = body + param.getSimpleName() + ",";
-                    added = true;
-                }
-
-                // treat a final array as a varargs param
-                if (!parameters.isEmpty() && parameters.get(parameters.size() - 1).asType().getKind() == TypeKind.ARRAY)
-                    methodToAdd.varargs(true);
-
-                if (added) body = body.substring(0, body.length() - 1);
-
-                body = body + ")";
+                addMethodBody(methodToAdd, templateMethod, "return __.<A>start().$L(", ")", methodName);
             }
 
-            methodToAdd.addStatement(body, methodName);
-
             anonymousClass.addMethod(methodToAdd.build());
         }
 
@@ -262,26 +223,10 @@ public class GremlinDslProcessor extends AbstractProcessor {
                         .addModifiers(Modifier.PUBLIC)
                         .addAnnotation(Override.class);
 
-                boolean added = false;
-                final List<? extends VariableElement> parameters = templateMethod.getParameters();
-                String body = "return new $T (clone, super.$L(";
-                for (VariableElement param : parameters) {
-                    methodToAdd.addParameter(ParameterSpec.get(param));
-
-                    body = body + param.getSimpleName() + ",";
-                    added = true;
-                }
-
-                // treat a final array as a varargs param
-                if (!parameters.isEmpty() && parameters.get(parameters.size() - 1).asType().getKind() == TypeKind.ARRAY)
-                    methodToAdd.varargs(true);
-
-                if (added) body = body.substring(0, body.length() - 1);
-
-                body = body + ").asAdmin())";
-                methodToAdd.addStatement("$T clone = this.clone()", ctx.traversalSourceClassName)
-                        .addStatement(body, ctx.defaultTraversalClassName, templateMethod.getSimpleName())
-                        .returns(getReturnTypeDefinition(ctx.traversalClassName, templateMethod));
+                methodToAdd.addStatement("$T clone = this.clone()", ctx.traversalSourceClassName);
+                addMethodBody(methodToAdd, templateMethod, "return new $T (clone, super.$L(", ").asAdmin())",
+                        ctx.defaultTraversalClassName, templateMethod.getSimpleName());
+                methodToAdd.returns(getReturnTypeDefinition(ctx.traversalClassName, templateMethod));
 
                 traversalSourceClass.addMethod(methodToAdd.build());
             }
@@ -446,27 +391,33 @@ public class GremlinDslProcessor extends AbstractProcessor {
 
         templateMethod.getTypeParameters().forEach(tp -> methodToAdd.addTypeVariable(TypeVariableName.get(tp)));
 
-        boolean added = false;
-        final List<? extends VariableElement> parameters = templateMethod.getParameters();
         final String parentCall = parent.isEmpty() ? "" : parent + ".";
-        String body = "return ($T) " + parentCall + "super.$L(";
-        for (VariableElement param : parameters) {
-            methodToAdd.addParameter(ParameterSpec.get(param));
+        final String body = "return ($T) " + parentCall + "super.$L(";
+        addMethodBody(methodToAdd, templateMethod, body, ")", returnClazz, methodName);
+
+        return methodToAdd.build();
+    }
+
+    private void addMethodBody(final MethodSpec.Builder methodToAdd, final ExecutableElement templateMethod,
+                               final String startBody, final String endBody, final Object... statementArgs) {
+        final List<? extends VariableElement> parameters = templateMethod.getParameters();
+        String body = startBody;
 
-            body = body + param.getSimpleName() + ",";
-            added = true;
+        final int numberOfParams = parameters.size();
+        for (int ix = 0; ix < numberOfParams; ix++) {
+            final VariableElement param = parameters.get(ix);
+            methodToAdd.addParameter(ParameterSpec.get(param));
+            body = body + param.getSimpleName();
+            if (ix < numberOfParams - 1) body = body + ",";
         }
 
+        body = body + endBody;
+
         // treat a final array as a varargs param
         if (!parameters.isEmpty() && parameters.get(parameters.size() - 1).asType().getKind() == TypeKind.ARRAY)
             methodToAdd.varargs(true);
 
-        if (added) body = body.substring(0, body.length() - 1);
-
-        body = body + ")";
-        methodToAdd.addStatement(body, returnClazz, methodName);
-
-        return methodToAdd.build();
+        methodToAdd.addStatement(body, statementArgs);
     }
 
     private TypeName getReturnTypeDefinition(final ClassName returnClazz, final ExecutableElement templateMethod) {


[33/45] tinkerpop git commit: updated pattern for defining anonymous dsl traversals

Posted by sp...@apache.org.
updated pattern for defining anonymous dsl traversals


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/404ee8ce
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/404ee8ce
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/404ee8ce

Branch: refs/heads/tp32-glv
Commit: 404ee8ced4165d188799f6904ff5aed7ca7adee3
Parents: a96544f
Author: davebshow <da...@gmail.com>
Authored: Thu May 11 12:02:45 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:31 2017 -0400

----------------------------------------------------------------------
 .../python/GraphTraversalSourceGenerator.groovy |  15 +-
 .../gremlin_python/process/graph_traversal.py   | 555 ++++++++++---------
 .../src/main/jython/tests/process/test_dsl.py   |  23 +-
 3 files changed, 299 insertions(+), 294 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/404ee8ce/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy b/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
index c2e733f..086b8ea 100644
--- a/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
+++ b/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
@@ -162,11 +162,12 @@ under the License.
 ////////////////////////
         pythonClass.append(
                 """class __(object):
-  @staticmethod
-  def start():
+  graph_traversal = GraphTraversal
+  @classmethod
+  def start(cls):
     return GraphTraversal(None, None, Bytecode())
-  @staticmethod
-  def __(*args):
+  @classmethod
+  def __(cls, *args):
     return __.inject(*args)
 """)
         __.class.getMethods().
@@ -178,9 +179,9 @@ under the License.
                 sort { a, b -> a <=> b }.
                 forEach { method ->
                     pythonClass.append(
-                            """  @staticmethod
-  def ${method}(*args):
-    return GraphTraversal(None, None, Bytecode()).${method}(*args)
+                            """  @classmethod
+  def ${method}(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).${method}(*args)
 """)
                 };
         pythonClass.append("\n\n")

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/404ee8ce/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
index ef49443..1c940aa 100644
--- a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
+++ b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
@@ -396,285 +396,286 @@ class GraphTraversal(Traversal):
 
 
 class __(object):
-  @staticmethod
-  def start():
+  graph_traversal = GraphTraversal
+  @classmethod
+  def start(cls):
     return GraphTraversal(None, None, Bytecode())
-  @staticmethod
-  def __(*args):
+  @classmethod
+  def __(cls, *args):
     return __.inject(*args)
-  @staticmethod
-  def V(*args):
-    return GraphTraversal(None, None, Bytecode()).V(*args)
-  @staticmethod
-  def addE(*args):
-    return GraphTraversal(None, None, Bytecode()).addE(*args)
-  @staticmethod
-  def addInE(*args):
-    return GraphTraversal(None, None, Bytecode()).addInE(*args)
-  @staticmethod
-  def addOutE(*args):
-    return GraphTraversal(None, None, Bytecode()).addOutE(*args)
-  @staticmethod
-  def addV(*args):
-    return GraphTraversal(None, None, Bytecode()).addV(*args)
-  @staticmethod
-  def aggregate(*args):
-    return GraphTraversal(None, None, Bytecode()).aggregate(*args)
-  @staticmethod
-  def and_(*args):
-    return GraphTraversal(None, None, Bytecode()).and_(*args)
-  @staticmethod
-  def as_(*args):
-    return GraphTraversal(None, None, Bytecode()).as_(*args)
-  @staticmethod
-  def barrier(*args):
-    return GraphTraversal(None, None, Bytecode()).barrier(*args)
-  @staticmethod
-  def both(*args):
-    return GraphTraversal(None, None, Bytecode()).both(*args)
-  @staticmethod
-  def bothE(*args):
-    return GraphTraversal(None, None, Bytecode()).bothE(*args)
-  @staticmethod
-  def bothV(*args):
-    return GraphTraversal(None, None, Bytecode()).bothV(*args)
-  @staticmethod
-  def branch(*args):
-    return GraphTraversal(None, None, Bytecode()).branch(*args)
-  @staticmethod
-  def cap(*args):
-    return GraphTraversal(None, None, Bytecode()).cap(*args)
-  @staticmethod
-  def choose(*args):
-    return GraphTraversal(None, None, Bytecode()).choose(*args)
-  @staticmethod
-  def coalesce(*args):
-    return GraphTraversal(None, None, Bytecode()).coalesce(*args)
-  @staticmethod
-  def coin(*args):
-    return GraphTraversal(None, None, Bytecode()).coin(*args)
-  @staticmethod
-  def constant(*args):
-    return GraphTraversal(None, None, Bytecode()).constant(*args)
-  @staticmethod
-  def count(*args):
-    return GraphTraversal(None, None, Bytecode()).count(*args)
-  @staticmethod
-  def cyclicPath(*args):
-    return GraphTraversal(None, None, Bytecode()).cyclicPath(*args)
-  @staticmethod
-  def dedup(*args):
-    return GraphTraversal(None, None, Bytecode()).dedup(*args)
-  @staticmethod
-  def drop(*args):
-    return GraphTraversal(None, None, Bytecode()).drop(*args)
-  @staticmethod
-  def emit(*args):
-    return GraphTraversal(None, None, Bytecode()).emit(*args)
-  @staticmethod
-  def filter(*args):
-    return GraphTraversal(None, None, Bytecode()).filter(*args)
-  @staticmethod
-  def flatMap(*args):
-    return GraphTraversal(None, None, Bytecode()).flatMap(*args)
-  @staticmethod
-  def fold(*args):
-    return GraphTraversal(None, None, Bytecode()).fold(*args)
-  @staticmethod
-  def group(*args):
-    return GraphTraversal(None, None, Bytecode()).group(*args)
-  @staticmethod
-  def groupCount(*args):
-    return GraphTraversal(None, None, Bytecode()).groupCount(*args)
-  @staticmethod
-  def groupV3d0(*args):
-    return GraphTraversal(None, None, Bytecode()).groupV3d0(*args)
-  @staticmethod
-  def has(*args):
-    return GraphTraversal(None, None, Bytecode()).has(*args)
-  @staticmethod
-  def hasId(*args):
-    return GraphTraversal(None, None, Bytecode()).hasId(*args)
-  @staticmethod
-  def hasKey(*args):
-    return GraphTraversal(None, None, Bytecode()).hasKey(*args)
-  @staticmethod
-  def hasLabel(*args):
-    return GraphTraversal(None, None, Bytecode()).hasLabel(*args)
-  @staticmethod
-  def hasNot(*args):
-    return GraphTraversal(None, None, Bytecode()).hasNot(*args)
-  @staticmethod
-  def hasValue(*args):
-    return GraphTraversal(None, None, Bytecode()).hasValue(*args)
-  @staticmethod
-  def id(*args):
-    return GraphTraversal(None, None, Bytecode()).id(*args)
-  @staticmethod
-  def identity(*args):
-    return GraphTraversal(None, None, Bytecode()).identity(*args)
-  @staticmethod
-  def inE(*args):
-    return GraphTraversal(None, None, Bytecode()).inE(*args)
-  @staticmethod
-  def inV(*args):
-    return GraphTraversal(None, None, Bytecode()).inV(*args)
-  @staticmethod
-  def in_(*args):
-    return GraphTraversal(None, None, Bytecode()).in_(*args)
-  @staticmethod
-  def inject(*args):
-    return GraphTraversal(None, None, Bytecode()).inject(*args)
-  @staticmethod
-  def is_(*args):
-    return GraphTraversal(None, None, Bytecode()).is_(*args)
-  @staticmethod
-  def key(*args):
-    return GraphTraversal(None, None, Bytecode()).key(*args)
-  @staticmethod
-  def label(*args):
-    return GraphTraversal(None, None, Bytecode()).label(*args)
-  @staticmethod
-  def limit(*args):
-    return GraphTraversal(None, None, Bytecode()).limit(*args)
-  @staticmethod
-  def local(*args):
-    return GraphTraversal(None, None, Bytecode()).local(*args)
-  @staticmethod
-  def loops(*args):
-    return GraphTraversal(None, None, Bytecode()).loops(*args)
-  @staticmethod
-  def map(*args):
-    return GraphTraversal(None, None, Bytecode()).map(*args)
-  @staticmethod
-  def mapKeys(*args):
-    return GraphTraversal(None, None, Bytecode()).mapKeys(*args)
-  @staticmethod
-  def mapValues(*args):
-    return GraphTraversal(None, None, Bytecode()).mapValues(*args)
-  @staticmethod
-  def match(*args):
-    return GraphTraversal(None, None, Bytecode()).match(*args)
-  @staticmethod
-  def max(*args):
-    return GraphTraversal(None, None, Bytecode()).max(*args)
-  @staticmethod
-  def mean(*args):
-    return GraphTraversal(None, None, Bytecode()).mean(*args)
-  @staticmethod
-  def min(*args):
-    return GraphTraversal(None, None, Bytecode()).min(*args)
-  @staticmethod
-  def not_(*args):
-    return GraphTraversal(None, None, Bytecode()).not_(*args)
-  @staticmethod
-  def optional(*args):
-    return GraphTraversal(None, None, Bytecode()).optional(*args)
-  @staticmethod
-  def or_(*args):
-    return GraphTraversal(None, None, Bytecode()).or_(*args)
-  @staticmethod
-  def order(*args):
-    return GraphTraversal(None, None, Bytecode()).order(*args)
-  @staticmethod
-  def otherV(*args):
-    return GraphTraversal(None, None, Bytecode()).otherV(*args)
-  @staticmethod
-  def out(*args):
-    return GraphTraversal(None, None, Bytecode()).out(*args)
-  @staticmethod
-  def outE(*args):
-    return GraphTraversal(None, None, Bytecode()).outE(*args)
-  @staticmethod
-  def outV(*args):
-    return GraphTraversal(None, None, Bytecode()).outV(*args)
-  @staticmethod
-  def path(*args):
-    return GraphTraversal(None, None, Bytecode()).path(*args)
-  @staticmethod
-  def project(*args):
-    return GraphTraversal(None, None, Bytecode()).project(*args)
-  @staticmethod
-  def properties(*args):
-    return GraphTraversal(None, None, Bytecode()).properties(*args)
-  @staticmethod
-  def property(*args):
-    return GraphTraversal(None, None, Bytecode()).property(*args)
-  @staticmethod
-  def propertyMap(*args):
-    return GraphTraversal(None, None, Bytecode()).propertyMap(*args)
-  @staticmethod
-  def range(*args):
-    return GraphTraversal(None, None, Bytecode()).range(*args)
-  @staticmethod
-  def repeat(*args):
-    return GraphTraversal(None, None, Bytecode()).repeat(*args)
-  @staticmethod
-  def sack(*args):
-    return GraphTraversal(None, None, Bytecode()).sack(*args)
-  @staticmethod
-  def sample(*args):
-    return GraphTraversal(None, None, Bytecode()).sample(*args)
-  @staticmethod
-  def select(*args):
-    return GraphTraversal(None, None, Bytecode()).select(*args)
-  @staticmethod
-  def sideEffect(*args):
-    return GraphTraversal(None, None, Bytecode()).sideEffect(*args)
-  @staticmethod
-  def simplePath(*args):
-    return GraphTraversal(None, None, Bytecode()).simplePath(*args)
-  @staticmethod
-  def store(*args):
-    return GraphTraversal(None, None, Bytecode()).store(*args)
-  @staticmethod
-  def subgraph(*args):
-    return GraphTraversal(None, None, Bytecode()).subgraph(*args)
-  @staticmethod
-  def sum(*args):
-    return GraphTraversal(None, None, Bytecode()).sum(*args)
-  @staticmethod
-  def tail(*args):
-    return GraphTraversal(None, None, Bytecode()).tail(*args)
-  @staticmethod
-  def timeLimit(*args):
-    return GraphTraversal(None, None, Bytecode()).timeLimit(*args)
-  @staticmethod
-  def times(*args):
-    return GraphTraversal(None, None, Bytecode()).times(*args)
-  @staticmethod
-  def to(*args):
-    return GraphTraversal(None, None, Bytecode()).to(*args)
-  @staticmethod
-  def toE(*args):
-    return GraphTraversal(None, None, Bytecode()).toE(*args)
-  @staticmethod
-  def toV(*args):
-    return GraphTraversal(None, None, Bytecode()).toV(*args)
-  @staticmethod
-  def tree(*args):
-    return GraphTraversal(None, None, Bytecode()).tree(*args)
-  @staticmethod
-  def unfold(*args):
-    return GraphTraversal(None, None, Bytecode()).unfold(*args)
-  @staticmethod
-  def union(*args):
-    return GraphTraversal(None, None, Bytecode()).union(*args)
-  @staticmethod
-  def until(*args):
-    return GraphTraversal(None, None, Bytecode()).until(*args)
-  @staticmethod
-  def value(*args):
-    return GraphTraversal(None, None, Bytecode()).value(*args)
-  @staticmethod
-  def valueMap(*args):
-    return GraphTraversal(None, None, Bytecode()).valueMap(*args)
-  @staticmethod
-  def values(*args):
-    return GraphTraversal(None, None, Bytecode()).values(*args)
-  @staticmethod
-  def where(*args):
-    return GraphTraversal(None, None, Bytecode()).where(*args)
+  @classmethod
+  def V(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).V(*args)
+  @classmethod
+  def addE(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).addE(*args)
+  @classmethod
+  def addInE(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).addInE(*args)
+  @classmethod
+  def addOutE(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).addOutE(*args)
+  @classmethod
+  def addV(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).addV(*args)
+  @classmethod
+  def aggregate(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).aggregate(*args)
+  @classmethod
+  def and_(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).and_(*args)
+  @classmethod
+  def as_(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).as_(*args)
+  @classmethod
+  def barrier(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).barrier(*args)
+  @classmethod
+  def both(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).both(*args)
+  @classmethod
+  def bothE(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).bothE(*args)
+  @classmethod
+  def bothV(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).bothV(*args)
+  @classmethod
+  def branch(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).branch(*args)
+  @classmethod
+  def cap(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).cap(*args)
+  @classmethod
+  def choose(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).choose(*args)
+  @classmethod
+  def coalesce(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).coalesce(*args)
+  @classmethod
+  def coin(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).coin(*args)
+  @classmethod
+  def constant(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).constant(*args)
+  @classmethod
+  def count(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).count(*args)
+  @classmethod
+  def cyclicPath(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).cyclicPath(*args)
+  @classmethod
+  def dedup(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).dedup(*args)
+  @classmethod
+  def drop(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).drop(*args)
+  @classmethod
+  def emit(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).emit(*args)
+  @classmethod
+  def filter(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).filter(*args)
+  @classmethod
+  def flatMap(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).flatMap(*args)
+  @classmethod
+  def fold(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).fold(*args)
+  @classmethod
+  def group(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).group(*args)
+  @classmethod
+  def groupCount(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).groupCount(*args)
+  @classmethod
+  def groupV3d0(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).groupV3d0(*args)
+  @classmethod
+  def has(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).has(*args)
+  @classmethod
+  def hasId(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).hasId(*args)
+  @classmethod
+  def hasKey(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).hasKey(*args)
+  @classmethod
+  def hasLabel(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).hasLabel(*args)
+  @classmethod
+  def hasNot(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).hasNot(*args)
+  @classmethod
+  def hasValue(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).hasValue(*args)
+  @classmethod
+  def id(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).id(*args)
+  @classmethod
+  def identity(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).identity(*args)
+  @classmethod
+  def inE(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).inE(*args)
+  @classmethod
+  def inV(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).inV(*args)
+  @classmethod
+  def in_(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).in_(*args)
+  @classmethod
+  def inject(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).inject(*args)
+  @classmethod
+  def is_(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).is_(*args)
+  @classmethod
+  def key(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).key(*args)
+  @classmethod
+  def label(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).label(*args)
+  @classmethod
+  def limit(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).limit(*args)
+  @classmethod
+  def local(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).local(*args)
+  @classmethod
+  def loops(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).loops(*args)
+  @classmethod
+  def map(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).map(*args)
+  @classmethod
+  def mapKeys(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).mapKeys(*args)
+  @classmethod
+  def mapValues(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).mapValues(*args)
+  @classmethod
+  def match(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).match(*args)
+  @classmethod
+  def max(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).max(*args)
+  @classmethod
+  def mean(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).mean(*args)
+  @classmethod
+  def min(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).min(*args)
+  @classmethod
+  def not_(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).not_(*args)
+  @classmethod
+  def optional(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).optional(*args)
+  @classmethod
+  def or_(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).or_(*args)
+  @classmethod
+  def order(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).order(*args)
+  @classmethod
+  def otherV(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).otherV(*args)
+  @classmethod
+  def out(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).out(*args)
+  @classmethod
+  def outE(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).outE(*args)
+  @classmethod
+  def outV(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).outV(*args)
+  @classmethod
+  def path(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).path(*args)
+  @classmethod
+  def project(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).project(*args)
+  @classmethod
+  def properties(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).properties(*args)
+  @classmethod
+  def property(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).property(*args)
+  @classmethod
+  def propertyMap(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).propertyMap(*args)
+  @classmethod
+  def range(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).range(*args)
+  @classmethod
+  def repeat(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).repeat(*args)
+  @classmethod
+  def sack(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).sack(*args)
+  @classmethod
+  def sample(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).sample(*args)
+  @classmethod
+  def select(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).select(*args)
+  @classmethod
+  def sideEffect(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).sideEffect(*args)
+  @classmethod
+  def simplePath(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).simplePath(*args)
+  @classmethod
+  def store(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).store(*args)
+  @classmethod
+  def subgraph(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).subgraph(*args)
+  @classmethod
+  def sum(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).sum(*args)
+  @classmethod
+  def tail(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).tail(*args)
+  @classmethod
+  def timeLimit(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).timeLimit(*args)
+  @classmethod
+  def times(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).times(*args)
+  @classmethod
+  def to(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).to(*args)
+  @classmethod
+  def toE(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).toE(*args)
+  @classmethod
+  def toV(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).toV(*args)
+  @classmethod
+  def tree(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).tree(*args)
+  @classmethod
+  def unfold(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).unfold(*args)
+  @classmethod
+  def union(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).union(*args)
+  @classmethod
+  def until(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).until(*args)
+  @classmethod
+  def value(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).value(*args)
+  @classmethod
+  def valueMap(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).valueMap(*args)
+  @classmethod
+  def values(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).values(*args)
+  @classmethod
+  def where(cls, *args):
+    return cls.graph_traversal(None, None, Bytecode()).where(*args)
 
 
 def V(*args):

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/404ee8ce/gremlin-python/src/main/jython/tests/process/test_dsl.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/process/test_dsl.py b/gremlin-python/src/main/jython/tests/process/test_dsl.py
index 0652cbb..5ec79ca 100644
--- a/gremlin-python/src/main/jython/tests/process/test_dsl.py
+++ b/gremlin-python/src/main/jython/tests/process/test_dsl.py
@@ -18,7 +18,7 @@ under the License.
 '''
 import pytest
 
-from gremlin_python.process.traversal import (Bytecode, P)
+from gremlin_python.process.traversal import Bytecode, P
 from gremlin_python.process.graph_traversal import (
     GraphTraversalSource, GraphTraversal)
 from gremlin_python.process.graph_traversal import __ as AnonymousTraversal
@@ -39,17 +39,20 @@ class SocialTraversal(GraphTraversal):
         return self.outE("created").count().is_(P.gte(number))
 
 class __(AnonymousTraversal):
-    @staticmethod
-    def knows(*args):
-        return SocialTraversal(None, None, Bytecode()).knows(*args)
 
-    @staticmethod
-    def youngestFriendsAge(*args):
-        return SocialTraversal(None, None, Bytecode()).youngestFriendsAge(*args)
+    graph_traversal = SocialTraversal
 
-    @staticmethod
-    def createdAtLeast(*args):
-        return SocialTraversal(None, None, Bytecode()).createdAtLeast(*args)
+    @classmethod
+    def knows(cls, *args):
+        return cls.graph_traversal(None, None, Bytecode()).knows(*args)
+
+    @classmethod
+    def youngestFriendsAge(cls, *args):
+        return cls.graph_traversal(None, None, Bytecode()).youngestFriendsAge(*args)
+
+    @classmethod
+    def createdAtLeast(cls, *args):
+        return cls.graph_traversal(None, None, Bytecode()).createdAtLeast(*args)
 
 
 class SocialTraversalSource(GraphTraversalSource):


[35/45] tinkerpop git commit: Fixed bad sample code in docs

Posted by sp...@apache.org.
Fixed bad sample code in docs

vertexIdKey was removed a long long time ago. Can't even find where it was last in the API going back to 3.0.x - that's been bad a long time...dah CTR


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/07bca450
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/07bca450
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/07bca450

Branch: refs/heads/tp32-glv
Commit: 07bca45002ca2392bd1e8ada1eed6ff29528c88d
Parents: 0e5725b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon May 22 09:48:05 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon May 22 09:48:05 2017 -0400

----------------------------------------------------------------------
 docs/src/reference/the-graph.asciidoc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/07bca450/docs/src/reference/the-graph.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/the-graph.asciidoc b/docs/src/reference/the-graph.asciidoc
index 09c11fa..9515cf5 100644
--- a/docs/src/reference/the-graph.asciidoc
+++ b/docs/src/reference/the-graph.asciidoc
@@ -440,7 +440,7 @@ try (final OutputStream os = new FileOutputStream("tinkerpop-modern.xml")) {
 
 final Graph newGraph = TinkerGraph.open();
 try (final InputStream stream = new FileInputStream("tinkerpop-modern.xml")) {
-    newGraph.io(IoCore.graphml()).reader().vertexIdKey("name").create().readGraph(stream, newGraph);
+    newGraph.io(IoCore.graphml()).reader().create().readGraph(stream, newGraph);
 }
 ----
 
@@ -507,7 +507,7 @@ try (final OutputStream os = new FileOutputStream("tinkerpop-modern.json")) {
 
 final Graph newGraph = TinkerGraph.open();
 try (final InputStream stream = new FileInputStream("tinkerpop-modern.json")) {
-    newGraph.io(IoCore.graphson()).reader().vertexIdKey("name").create().readGraph(stream, newGraph);
+    newGraph.io(IoCore.graphson()).reader().create().readGraph(stream, newGraph);
 }
 ----
 
@@ -719,7 +719,7 @@ try (final OutputStream os = new FileOutputStream("tinkerpop-modern.kryo")) {
 
 final Graph newGraph = TinkerGraph.open();
 try (final InputStream stream = new FileInputStream("tinkerpop-modern.kryo")) {
-    newGraph.io(IoCore.gryo()).reader().vertexIdKey("name").create().readGraph(stream, newGraph);
+    newGraph.io(IoCore.gryo()).reader().create().readGraph(stream, newGraph);
 }
 ----
 


[02/45] tinkerpop git commit: TINKERPOP-786 Improved social DSL example a bit.

Posted by sp...@apache.org.
TINKERPOP-786 Improved social DSL example a bit.

Made persons() take a varargs of names to filter with so that you can do: g.persons('marko')


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/7e0d6d4a
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/7e0d6d4a
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/7e0d6d4a

Branch: refs/heads/tp32-glv
Commit: 7e0d6d4a79e1310243638fdeb502b0813e01c9d5
Parents: e0dc97d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 9 10:24:55 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:01:50 2017 -0400

----------------------------------------------------------------------
 .../src/main/java/SocialTraversalDsl.java          |  2 +-
 .../src/main/java/SocialTraversalSourceDsl.java    | 17 +++++++++++++----
 .../src/test/java/SocialDslTest.java               |  2 ++
 3 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7e0d6d4a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
index add44aa..e8a2ded 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalDsl.java
@@ -25,7 +25,7 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
 
 @GremlinDsl(traversalSource = "${package}.SocialTraversalSourceDsl")
 public interface SocialTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
-    public default GraphTraversal<S, Vertex> knows(final String personName) {
+    public default GraphTraversal<S, Vertex> knows(String personName) {
         return out("knows").hasLabel("person").has("name", personName);
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7e0d6d4a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
index 0117914..9b5b136 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/main/java/SocialTraversalSourceDsl.java
@@ -41,11 +41,20 @@ public class SocialTraversalSourceDsl extends GraphTraversalSource {
         super(graph);
     }
 
-    public GraphTraversal<Vertex, Vertex> persons() {
-        final GraphTraversalSource clone = this.clone();
+    public GraphTraversal<Vertex, Vertex> persons(String... names) {
+        GraphTraversalSource clone = this.clone();
         clone.getBytecode().addStep(GraphTraversal.Symbols.V);
         clone.getBytecode().addStep(GraphTraversal.Symbols.hasLabel, "person");
-        final GraphTraversal.Admin<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
-        return TraversalHelper.addHasContainer(traversal.addStep(new GraphStep<>(traversal, Vertex.class, true)), new HasContainer(T.label.getAccessor(), P.eq("person")));
+
+        GraphTraversal.Admin<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone);
+        traversal.addStep(new GraphStep<>(traversal, Vertex.class, true));
+        TraversalHelper.addHasContainer(traversal, new HasContainer(T.label.getAccessor(), P.eq("person")));
+
+        if (names.length > 0) {
+            clone.getBytecode().addStep(GraphTraversal.Symbols.has, P.within(names));
+            TraversalHelper.addHasContainer(traversal, new HasContainer("name", P.within(names)));
+        }
+
+        return traversal;
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7e0d6d4a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
index be73500..5967244 100644
--- a/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
+++ b/gremlin-archetype/gremlin-archetype-dsl/src/main/resources/archetype-resources/src/test/java/SocialDslTest.java
@@ -36,12 +36,14 @@ public class SocialDslTest {
     public void shouldValidateThatMarkoKnowsJosh() {
         SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
         assertTrue(social.V().has("name","marko").knows("josh").hasNext());
+        assertTrue(social.persons("marko").knows("josh").hasNext());
     }
 
     @Test
     public void shouldGetAgeOfYoungestFriendOfMarko() {
         SocialTraversalSource social = graph.traversal(SocialTraversalSource.class);
         assertEquals(27, social.V().has("name","marko").youngestFriendsAge().next().intValue());
+        assertEquals(27, social.persons("marko").youngestFriendsAge().next().intValue());
     }
 
     @Test