tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [10/15] tinkerpop git commit: TINKERPOP-786 Extracted logic for DefaultTraversal generation for DSLs
Date Wed, 03 May 2017 13:11:08 GMT
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/94ad0a1c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/94ad0a1c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/94ad0a1c

Branch: refs/heads/TINKERPOP-786
Commit: 94ad0a1c8a4f7aa151f38e0dd18c4641bc0f39c8
Parents: 9f8cc2b
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Thu Apr 27 15:19:46 2017 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Wed May 3 09:10:40 2017 -0400

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


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/94ad0a1c/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)


Mime
View raw message