This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/master by this push:
new 52b0ed93b7 Fix Gremlin-Java DSL example to compile on 4.x
52b0ed93b7 is described below
commit 52b0ed93b71acc420b9e091d92e1ad8b03cb3434
Author: Stephen Mallette <[email protected]>
AuthorDate: Thu Sep 10 20:31:37 2026 +0000
Fix Gremlin-Java DSL example to compile on 4.x
The Domain Specific Languages example on the Gremlin-Java reference page
used
APIs that no longer compile on 4.x. Update persons() to obtain the start
step
through getGremlinLang() rather than the removed getBytecode(), and change
the
return bound of youngestFriendsAge() from Number to Comparable so it
matches the
current min() signature.
Add the import statements needed to build the interface and TraversalSource
examples, give the DSL section its own summary so it renders as its own
page,
and correct the interface-suffix note to read TraversalDsl to match the
examples.
Assisted-by: Kiro:claude-opus-4.8
---
docs/src/reference/gremlin-variants.asciidoc | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/docs/src/reference/gremlin-variants.asciidoc
b/docs/src/reference/gremlin-variants.asciidoc
index f6352aa1ad..93d7da2ba2 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -1502,6 +1502,7 @@ For an example of a simple `RequestInterceptor` that only
modifies the header of
link:https://github.com/apache/tinkerpop/blob/x.y.z/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/auth/Basic.java[basic
authentication].
[[gremlin-java-dsl]]
+[llms-summary="Creating a Domain Specific Language (DSL) in Java with the
@GremlinDsl annotation from the gremlin-annotations module: defining the DSL
interface, customizing the TraversalSource with additional start steps, and the
traversal classes generated by the annotation processor."]
=== Domain Specific Languages
Creating a <<dsl,Domain Specific Language>> (DSL) in Java requires the
`@GremlinDsl` Java annotation in the
@@ -1524,20 +1525,25 @@ 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
+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]
----
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+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;
+
@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() {
+ public default <E2 extends Comparable> GraphTraversal<S, E2>
youngestFriendsAge() {
return out("knows").hasLabel("person").values("age").min();
}
@@ -1588,6 +1594,16 @@ any custom methods required by the DSL:
[source,java]
----
+import org.apache.tinkerpop.gremlin.process.remote.RemoteConnection;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+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.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
public class SocialTraversalSourceDsl extends GraphTraversalSource {
public SocialTraversalSourceDsl(Graph graph, TraversalStrategies
traversalStrategies) {
@@ -1607,7 +1623,7 @@ public class SocialTraversalSourceDsl extends
GraphTraversalSource {
// 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);
+ clone.getGremlinLang().addStep(GraphTraversal.Symbols.V);
GraphTraversal<Vertex, Vertex> traversal = new
DefaultGraphTraversal<>(clone);
traversal.asAdmin().addStep(new GraphStep<>(traversal.asAdmin(),
Vertex.class, true));