tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [17/41] tinkerpop git commit: TINKERPOP-786 Worked in custom GraphTraversalSource into DSL
Date Fri, 26 May 2017 12:24:08 GMT
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/master
Commit: cf53e13d66dbced6ab0695481473e8a5e8a5d5c0
Parents: fe702fe
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Fri Apr 28 14:58:52 2017 -0400
Committer: Stephen Mallette <spmva@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;


Mime
View raw message