You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by fl...@apache.org on 2018/10/05 15:38:52 UTC
tinkerpop git commit: TINKERPOP-1972 Fix arg handling for inject step
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1972 2a2e47ebd -> dee155e50
TINKERPOP-1972 Fix arg handling for inject step
To be precise, this affects all steps that have a params array with a
generic type parameter as the member type but currently inject is the
only step in Gremlin.Net that has such an array as an argument.
The arguments passed as such a params array were incorrectly wrapped in
one array before instead of individual arguments.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/dee155e5
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/dee155e5
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/dee155e5
Branch: refs/heads/TINKERPOP-1972
Commit: dee155e50eab747afa1d302ed0c027c8c3629e2b
Parents: 2a2e47e
Author: Florian Hockmann <fh...@florian-hockmann.de>
Authored: Fri Oct 5 17:32:09 2018 +0200
Committer: Florian Hockmann <fh...@florian-hockmann.de>
Committed: Fri Oct 5 17:32:09 2018 +0200
----------------------------------------------------------------------
gremlin-dotnet/glv/GraphTraversal.template | 5 +++--
gremlin-dotnet/glv/GraphTraversalSource.template | 5 +++--
gremlin-dotnet/glv/generate.groovy | 16 +++++++---------
.../Gremlin.Net/Process/Traversal/GraphTraversal.cs | 5 +++--
.../Process/Traversal/GraphTraversalSource.cs | 5 +++--
.../BytecodeGeneration/BytecodeGenerationTests.cs | 12 ++++++++++++
6 files changed, 31 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dee155e5/gremlin-dotnet/glv/GraphTraversal.template
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/glv/GraphTraversal.template b/gremlin-dotnet/glv/GraphTraversal.template
index 6738467..9e4b284 100644
--- a/gremlin-dotnet/glv/GraphTraversal.template
+++ b/gremlin-dotnet/glv/GraphTraversal.template
@@ -22,6 +22,7 @@
#endregion
using System.Collections.Generic;
+using System.Linq;
using Gremlin.Net.Structure;
// THIS IS A GENERATED FILE - DO NOT MODIFY THIS FILE DIRECTLY - see pom.xml
@@ -68,8 +69,8 @@ namespace Gremlin.Net.Process.Traversal
public GraphTraversal<$method.t1, $method.t2> <%= toCSharpMethodName.call(method.methodName) %><%= method.tParam %> (<%= method.parameters %>)
{
<% if (method.parameters.contains("params ")) {
- %> var args = new List<$method.argsListType>(<%= method.paramNames.init().size() %> + <%= method.paramNames.last() %>.Length) {<%= method.paramNames.init().join(", ") %>};
- args.AddRange(<%= method.paramNames.last() %>);
+ %> var args = new List<object>(<%= method.paramNames.init().size() %> + <%= method.paramNames.last() %>.Length) {<%= method.paramNames.init().join(", ") %>};
+ args.AddRange(<%= method.paramNames.last() %><% if (method.isArgsCastNecessary) { %>.Cast<object>()<% } %>);
Bytecode.AddStep("<%= method.methodName %>", args.ToArray());<%
}
else {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dee155e5/gremlin-dotnet/glv/GraphTraversalSource.template
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/glv/GraphTraversalSource.template b/gremlin-dotnet/glv/GraphTraversalSource.template
index afa4297..bbc3684 100644
--- a/gremlin-dotnet/glv/GraphTraversalSource.template
+++ b/gremlin-dotnet/glv/GraphTraversalSource.template
@@ -23,6 +23,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using Gremlin.Net.Process.Remote;
using Gremlin.Net.Process.Traversal.Strategy.Decoration;
using Gremlin.Net.Structure;
@@ -131,8 +132,8 @@ namespace Gremlin.Net.Process.Traversal
{
var traversal = new GraphTraversal<$method.typeNameString>(TraversalStrategies, new Bytecode(Bytecode));
<% if (method.parameters.contains("params ")) {
- %>var args = new List<$method.argsListType>(<%= method.paramNames.init().size() %> + <%= method.paramNames.last() %>.Length) {<%= method.paramNames.init().join(", ") %>};
- args.AddRange(<%= method.paramNames.last() %>);
+ %>var args = new List<object>(<%= method.paramNames.init().size() %> + <%= method.paramNames.last() %>.Length) {<%= method.paramNames.init().join(", ") %>};
+ args.AddRange(<%= method.paramNames.last() %><% if (method.isArgsCastNecessary) { %>.Cast<object>()<% } %>);
traversal.Bytecode.AddStep("<%= method.methodName %>", args.ToArray());<%
}
else {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dee155e5/gremlin-dotnet/glv/generate.groovy
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/glv/generate.groovy b/gremlin-dotnet/glv/generate.groovy
index 29f9ec7..2d8b005 100644
--- a/gremlin-dotnet/glv/generate.groovy
+++ b/gremlin-dotnet/glv/generate.groovy
@@ -191,14 +191,12 @@ def getParamNames = { parameters ->
}
}
-def getArgsListType = { parameterString ->
- def argsListType = "object"
+def isParamsArgCastNecessary = { parameterString ->
if (parameterString.contains("params ")) {
def paramsType = parameterString.substring(parameterString.indexOf("params ") + "params ".length(), parameterString.indexOf("[]"))
- if (paramsType == "E" || paramsType == "S")
- argsListType = paramsType
+ return paramsType == "E" || paramsType == "S"
}
- argsListType
+ return false
}
def hasMethodNoGenericCounterPartInGraphTraversal = { method ->
@@ -270,8 +268,8 @@ def binding = ["pmethods": P.class.getMethods().
def tParam = getCSharpGenericTypeParam(t2)
def parameters = getCSharpParamString(javaMethod, true)
def paramNames = getParamNames(javaMethod.parameters)
- def argsListType = getArgsListType(parameters)
- return ["methodName": javaMethod.name, "typeNameString": typeNameString, "tParam":tParam, "parameters":parameters, "paramNames":paramNames, "argsListType":argsListType]
+ def isArgsCastNecessary = isParamsArgCastNecessary(parameters)
+ return ["methodName": javaMethod.name, "typeNameString": typeNameString, "tParam":tParam, "parameters":parameters, "paramNames":paramNames, "isArgsCastNecessary":isArgsCastNecessary]
},
"graphStepMethods": GraphTraversal.getMethods().
findAll { GraphTraversal.class.equals(it.returnType) }.
@@ -286,8 +284,8 @@ def binding = ["pmethods": P.class.getMethods().
def tParam = getCSharpGenericTypeParam(t2)
def parameters = getCSharpParamString(javaMethod, true)
def paramNames = getParamNames(javaMethod.parameters)
- def argsListType = getArgsListType(parameters)
- return ["methodName": javaMethod.name, "t1":t1, "t2":t2, "tParam":tParam, "parameters":parameters, "paramNames":paramNames, "argsListType":argsListType]
+ def isArgsCastNecessary = isParamsArgCastNecessary(parameters)
+ return ["methodName": javaMethod.name, "t1":t1, "t2":t2, "tParam":tParam, "parameters":parameters, "paramNames":paramNames, "isArgsCastNecessary":isArgsCastNecessary]
},
"anonStepMethods": __.class.getMethods().
findAll { GraphTraversal.class.equals(it.returnType) }.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dee155e5/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
index c8708df..81d3c62 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
@@ -22,6 +22,7 @@
#endregion
using System.Collections.Generic;
+using System.Linq;
using Gremlin.Net.Structure;
// THIS IS A GENERATED FILE - DO NOT MODIFY THIS FILE DIRECTLY - see pom.xml
@@ -870,8 +871,8 @@ namespace Gremlin.Net.Process.Traversal
/// </summary>
public GraphTraversal<S, E> Inject (params E[] injections)
{
- var args = new List<E>(0 + injections.Length) {};
- args.AddRange(injections);
+ var args = new List<object>(0 + injections.Length) {};
+ args.AddRange(injections.Cast<object>());
Bytecode.AddStep("inject", args.ToArray());
return Wrap<S, E>(this);
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dee155e5/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs
index 7115016..9f735f4 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs
@@ -23,6 +23,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using Gremlin.Net.Process.Remote;
using Gremlin.Net.Process.Traversal.Strategy.Decoration;
using Gremlin.Net.Structure;
@@ -307,8 +308,8 @@ namespace Gremlin.Net.Process.Traversal
public GraphTraversal<S, S> Inject<S>(params S[] starts)
{
var traversal = new GraphTraversal<S, S>(TraversalStrategies, new Bytecode(Bytecode));
- var args = new List<S>(0 + starts.Length) {};
- args.AddRange(starts);
+ var args = new List<object>(0 + starts.Length) {};
+ args.AddRange(starts.Cast<object>());
traversal.Bytecode.AddStep("inject", args.ToArray());
return traversal;
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dee155e5/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/BytecodeGeneration/BytecodeGenerationTests.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/BytecodeGeneration/BytecodeGenerationTests.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/BytecodeGeneration/BytecodeGenerationTests.cs
index 266e3c6..4b13bde 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/BytecodeGeneration/BytecodeGenerationTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/BytecodeGeneration/BytecodeGenerationTests.cs
@@ -77,6 +77,18 @@ namespace Gremlin.Net.IntegrationTest.Process.Traversal.BytecodeGeneration
}
[Fact]
+ public void g_InjectX1_2_3X()
+ {
+ var g = new Graph().Traversal();
+
+ var bytecode = g.Inject(1, 2, 3).Bytecode;
+
+ Assert.Equal(1, bytecode.StepInstructions.Count);
+ Assert.Equal("inject", bytecode.StepInstructions[0].OperatorName);
+ Assert.Equal(3, bytecode.StepInstructions[0].Arguments.Length);
+ }
+
+ [Fact]
public void AnonymousTraversal_Start_EmptyBytecode()
{
var bytecode = __.Start().Bytecode;