tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [11/41] tinkerpop git commit: TINKERPOP-786 Allow the package name of the dsl to change
Date Fri, 26 May 2017 12:24:02 GMT
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/master
Commit: 5ae3497111a5e7dcbdaa5266e09a48b50842c2c1
Parents: 844393d
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Thu Apr 27 14:02:32 2017 -0400
Committer: Stephen Mallette <spmva@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;
+    }
+}


Mime
View raw message