tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [4/8] tinkerpop git commit: TINKERPOP-786 Made override of iterate() automatic
Date Fri, 28 Apr 2017 19:00:45 GMT
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/9e016fcc
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9e016fcc
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9e016fcc

Branch: refs/heads/TINKERPOP-786
Commit: 9e016fcc985fd23273b027043be41479dc99fb1f
Parents: 4d5b222
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Thu Apr 27 15:16:16 2017 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Thu Apr 27 15:16:16 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/9e016fcc/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/9e016fcc/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/9e016fcc/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/9e016fcc/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;
-    }
 }


Mime
View raw message