TINKERPOP-1552 Removed the dotnet generator module Moved GLV generation to the gremlin-dotnet pom and gmaveplus plugin.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/21843ce4 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/21843ce4 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/21843ce4 Branch: refs/heads/tp32 Commit: 21843ce422aecd4bcd6b0cab9825f737f6c06f46 Parents: 1fa9a60 Author: Stephen Mallette <[email protected]> Authored: Tue Jun 13 13:07:55 2017 -0400 Committer: Stephen Mallette <[email protected]> Committed: Wed Jun 28 15:13:11 2017 -0400 ---------------------------------------------------------------------- gremlin-dotnet-generator/pom.xml | 75 ---- .../dotnet/AnonymousTraversalGenerator.groovy | 98 ----- .../gremlin/dotnet/CommonContentHelper.groovy | 49 --- .../gremlin/dotnet/EnumGenerator.groovy | 112 ------ .../gremlin/dotnet/GenerateGremlinDotNet.groovy | 32 -- .../dotnet/GraphTraversalGenerator.groovy | 90 ----- .../dotnet/GraphTraversalSourceGenerator.groovy | 142 ------- .../gremlin/dotnet/PredicateGenerator.groovy | 64 --- .../gremlin/dotnet/SymbolHelper.groovy | 89 ----- gremlin-dotnet/glv/AnonymousTraversal.template | 45 +++ gremlin-dotnet/glv/Enum.template | 33 ++ gremlin-dotnet/glv/GraphTraversal.template | 64 +++ .../glv/GraphTraversalSource.template | 88 ++++ gremlin-dotnet/glv/NamingConversions.template | 52 +++ gremlin-dotnet/glv/P.template | 39 ++ gremlin-dotnet/pom.xml | 229 ++++++++++- .../Gremlin.Net/Process/Traversal/Barrier.cs | 5 +- .../Process/Traversal/Cardinality.cs | 9 +- .../src/Gremlin.Net/Process/Traversal/Column.cs | 8 +- .../Gremlin.Net/Process/Traversal/Direction.cs | 9 +- .../Process/Traversal/GraphSONVersion.cs | 33 ++ .../Process/Traversal/GraphTraversal.cs | 399 ++++++++++--------- .../Process/Traversal/GraphTraversalSource.cs | 34 +- .../Process/Traversal/GryoVersion.cs | 33 ++ .../Process/Traversal/NamingConversions.cs | 67 ++-- .../Gremlin.Net/Process/Traversal/Operator.cs | 17 +- .../src/Gremlin.Net/Process/Traversal/Order.cs | 13 +- .../src/Gremlin.Net/Process/Traversal/P.cs | 8 +- .../src/Gremlin.Net/Process/Traversal/Pick.cs | 8 +- .../src/Gremlin.Net/Process/Traversal/Pop.cs | 9 +- .../src/Gremlin.Net/Process/Traversal/Scope.cs | 8 +- .../src/Gremlin.Net/Process/Traversal/T.cs | 10 +- .../src/Gremlin.Net/Process/Traversal/__.cs | 6 +- gremlin-dotnet/src/pom.xml | 17 + gremlin-dotnet/test/pom.xml | 16 + pom.xml | 1 - 36 files changed, 967 insertions(+), 1044 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet-generator/pom.xml ---------------------------------------------------------------------- diff --git a/gremlin-dotnet-generator/pom.xml b/gremlin-dotnet-generator/pom.xml deleted file mode 100644 index a0a9ff6..0000000 --- a/gremlin-dotnet-generator/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ -<!-- -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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.tinkerpop</groupId> - <artifactId>tinkerpop</artifactId> - <version>3.2.5-SNAPSHOT</version> - </parent> - <artifactId>gremlin-dotnet-generator</artifactId> - <name>Apache TinkerPop :: Gremlin-DotNet Generator</name> - <dependencies> - <dependency> - <groupId>org.apache.tinkerpop</groupId> - <artifactId>gremlin-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.codehaus.groovy</groupId> - <artifactId>groovy</artifactId> - <version>${groovy.version}</version> - <classifier>indy</classifier> - </dependency> - </dependencies> - <build> - <directory>${basedir}/target</directory> - <finalName>${project.artifactId}-${project.version}</finalName> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <version>1.2.1</version> - <executions> - <execution> - <id>generate-dotnet</id> - <phase>generate-test-resources</phase> - <goals> - <goal>java</goal> - </goals> - <configuration> - <mainClass>org.apache.tinkerpop.gremlin.dotnet.GenerateGremlinDotNet</mainClass> - <arguments> - <argument>${project.parent.basedir}/gremlin-dotnet/src/Gremlin.Net</argument> - </arguments> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.codehaus.gmavenplus</groupId> - <artifactId>gmavenplus-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/AnonymousTraversalGenerator.groovy ---------------------------------------------------------------------- diff --git a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/AnonymousTraversalGenerator.groovy b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/AnonymousTraversalGenerator.groovy deleted file mode 100644 index b65b2b0..0000000 --- a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/AnonymousTraversalGenerator.groovy +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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.dotnet - -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ - -import java.lang.reflect.Modifier - -class AnonymousTraversalGenerator { - - private static final Map<String, String[]> METHODS_WITH_SPECIFIC_TYPES = new HashMap<>(); - - static { - String[] useE2 = ["E2", "E2"]; - METHODS_WITH_SPECIFIC_TYPES.put("constant", useE2); - METHODS_WITH_SPECIFIC_TYPES.put("limit", useE2); - METHODS_WITH_SPECIFIC_TYPES.put("mean", useE2); - METHODS_WITH_SPECIFIC_TYPES.put("optional", useE2); - METHODS_WITH_SPECIFIC_TYPES.put("range", useE2); - METHODS_WITH_SPECIFIC_TYPES.put("select", ["IDictionary<string, E2>", "E2"] as String[]); - METHODS_WITH_SPECIFIC_TYPES.put("sum", useE2); - METHODS_WITH_SPECIFIC_TYPES.put("tail", useE2); - METHODS_WITH_SPECIFIC_TYPES.put("tree", ["object"] as String[]); - METHODS_WITH_SPECIFIC_TYPES.put("unfold", useE2); - } - - public static void create(final String anonymousTraversalFile) { - - - final StringBuilder csharpClass = new StringBuilder() - - csharpClass.append(CommonContentHelper.getLicense()) - - csharpClass.append( -""" -using System.Collections.Generic; -using Gremlin.Net.Structure; - -namespace Gremlin.Net.Process.Traversal -{ - public static class __ - { - public static GraphTraversal<object, object> Start() - { - return new GraphTraversal<object, object>(); - } -""") - __.getMethods(). - findAll { GraphTraversal.class.equals(it.returnType) }. - findAll { Modifier.isStatic(it.getModifiers()) }. - findAll { !it.name.equals("__") && !it.name.equals("start") }. - groupBy { it.name }. - // Select unique by name, with the most amount of parameters - collect { it.value.sort { a, b -> b.parameterCount <=> a.parameterCount }.first() }. - sort { it.name }. - forEach { javaMethod -> - String sharpMethodName = SymbolHelper.toCSharp(javaMethod.name); - String[] typeNames = SymbolHelper.getJavaParameterTypeNames(javaMethod); - def t2 = SymbolHelper.toCSharpType(typeNames[1]); - def tParam = SymbolHelper.getCSharpGenericTypeParam(t2); - def specificTypes = METHODS_WITH_SPECIFIC_TYPES.get(javaMethod.name); - if (specificTypes) { - t2 = specificTypes[0]; - tParam = specificTypes.length > 1 ? "<" + specificTypes[1] + ">" : ""; - } - csharpClass.append( -""" - public static GraphTraversal<object, $t2> $sharpMethodName$tParam(params object[] args) - { - return new GraphTraversal<object, object>().$sharpMethodName$tParam(args); - } -""") - } - csharpClass.append(" }\n}") - - final File file = new File(anonymousTraversalFile); - file.delete() - csharpClass.eachLine { file.append(it + "\n") } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/CommonContentHelper.groovy ---------------------------------------------------------------------- diff --git a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/CommonContentHelper.groovy b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/CommonContentHelper.groovy deleted file mode 100644 index 825e230..0000000 --- a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/CommonContentHelper.groovy +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.dotnet - -public final class CommonContentHelper { - - public static String getLicense() { - return """#region License - -/* - * 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. - */ - -#endregion -""" - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/EnumGenerator.groovy ---------------------------------------------------------------------- diff --git a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/EnumGenerator.groovy b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/EnumGenerator.groovy deleted file mode 100644 index 840b604..0000000 --- a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/EnumGenerator.groovy +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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.dotnet - -import org.apache.tinkerpop.gremlin.util.CoreImports -import org.apache.tinkerpop.gremlin.structure.Direction - -class EnumGenerator { - - public static void create(final String enumDirectory) { - - Map<String, String> enumCSharpToJavaNames = new HashMap<String, String>(); - for (final Class<? extends Enum> enumClass : CoreImports.getClassImports() - .findAll { Enum.class.isAssignableFrom(it) } - .sort { a, b -> a.getSimpleName() <=> b.getSimpleName() } - .collect()) { - createEnum(enumDirectory, enumClass, enumCSharpToJavaNames) - } - - // Write a file containing the equivalence in names between Java and C# - final String enumCSharpToJavaFile = "$enumDirectory/NamingConversions.cs" - final File file = new File(enumCSharpToJavaFile); - file.delete(); - file.append(CommonContentHelper.getLicense()); - file.append(""" -using System.Collections.Generic; - -namespace Gremlin.Net.Process.Traversal -{ - internal static class NamingConversions - { - /// <summary> - /// Gets the Java name equivalent for a given enum value - /// </summary> - internal static string GetEnumJavaName(string typeName, string value) - { - var key = \$"{typeName}.{value}"; - string javaName; - if (!CSharpToJavaEnums.TryGetValue(key, out javaName)) - { - throw new KeyNotFoundException(\$"Java name for {key} not found"); - } - return javaName; - } - - internal static readonly IDictionary<string, string> CSharpToJavaEnums = new Dictionary<string, string> - { -""" ); - def lastIndex = (enumCSharpToJavaNames.size() - 1); - enumCSharpToJavaNames.eachWithIndex{ node, i -> - file.append(""" {"$node.key", "$node.value"}${i == lastIndex ? "" : ","}\n""") - } - file.append(" };\n }\n}"); - - } - - public static String toCSharpName(final Class<? extends Enum> enumClass, String itemName) { - if (enumClass.equals(Direction.class)) { - itemName = itemName.toLowerCase(); - } - return itemName.substring(0, 1).toUpperCase() + itemName.substring(1); - } - - private static void createEnum(final String enumDirectory, final Class<? extends Enum> enumClass, - final Map<String, String> csharpToJava) { - final StringBuilder csharpEnum = new StringBuilder() - - csharpEnum.append(CommonContentHelper.getLicense()) - - csharpEnum.append( - """ -namespace Gremlin.Net.Process.Traversal -{ - public enum ${enumClass.getSimpleName()} - { -""") - enumClass.getEnumConstants(). - sort { a, b -> a.name() <=> b.name() }. - each { value -> - def csharpName = toCSharpName(enumClass, value.name()); - csharpEnum.append(" $csharpName,\n"); - csharpToJava.put(enumClass.simpleName + "." + csharpName, value.name()); - } - csharpEnum.deleteCharAt(csharpEnum.length() - 2) - - csharpEnum.append(" }\n") - csharpEnum.append("}") - - final String enumFileName = "${enumDirectory}/${enumClass.getSimpleName()}.cs" - final File file = new File(enumFileName); - file.delete() - csharpEnum.eachLine { file.append(it + "\n") } - } -} - http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GenerateGremlinDotNet.groovy ---------------------------------------------------------------------- diff --git a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GenerateGremlinDotNet.groovy b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GenerateGremlinDotNet.groovy deleted file mode 100644 index 0d09d5b..0000000 --- a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GenerateGremlinDotNet.groovy +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.dotnet - -public class GenerateGremlinDotNet { - - public static void main(String[] args) { - final String dotnetDirectory = args[0] - GraphTraversalSourceGenerator.create(dotnetDirectory + "/Process/Traversal/" + "GraphTraversalSource.cs") - GraphTraversalGenerator.create(dotnetDirectory + "/Process/Traversal/" + "GraphTraversal.cs") - AnonymousTraversalGenerator.create(dotnetDirectory + "/Process/Traversal/" + "__.cs") - EnumGenerator.create(dotnetDirectory + "/Process/Traversal/") - PredicateGenerator.create(dotnetDirectory + "/Process/Traversal/" + "P.cs") - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GraphTraversalGenerator.groovy ---------------------------------------------------------------------- diff --git a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GraphTraversalGenerator.groovy b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GraphTraversalGenerator.groovy deleted file mode 100644 index d3bade5..0000000 --- a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GraphTraversalGenerator.groovy +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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.dotnet - -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal - -class GraphTraversalGenerator { - - public static void create(final String graphTraversalFile) { - - final StringBuilder csharpClass = new StringBuilder() - - csharpClass.append(CommonContentHelper.getLicense()) - - csharpClass.append( -""" -using System.Collections.Generic; -using Gremlin.Net.Structure; - -namespace Gremlin.Net.Process.Traversal -{ - public class GraphTraversal<S, E> : DefaultTraversal<S, E> - { - public GraphTraversal() - : this(new List<ITraversalStrategy>(), new Bytecode()) - { - } - - public GraphTraversal(ICollection<ITraversalStrategy> traversalStrategies, Bytecode bytecode) - { - TraversalStrategies = traversalStrategies; - Bytecode = bytecode; - } - - private static GraphTraversal<S2, E2> Wrap<S2, E2>(GraphTraversal<S, E> traversal) - { - if (typeof(S2) == typeof(S) && typeof(E2) == typeof(E)) - { - return traversal as GraphTraversal<S2, E2>; - } - // New wrapper - return new GraphTraversal<S2, E2>(traversal.TraversalStrategies, traversal.Bytecode); - } - -""") - GraphTraversal.getMethods(). - findAll { GraphTraversal.class.equals(it.returnType) }. - findAll { !it.name.equals("clone") && !it.name.equals("iterate") }. - groupBy { it.name }. - // Select unique by name, with the most amount of parameters - collect { it.value.sort { a, b -> b.parameterCount <=> a.parameterCount }.first() }. - sort { it.name }. - forEach { javaMethod -> - String[] typeNames = SymbolHelper.getJavaParameterTypeNames(javaMethod); - def t1 = SymbolHelper.toCSharpType(typeNames[0]); - def t2 = SymbolHelper.toCSharpType(typeNames[1]); - def tParam = SymbolHelper.getCSharpGenericTypeParam(t2); - csharpClass.append( -""" - public GraphTraversal<$t1, $t2> ${SymbolHelper.toCSharp(javaMethod.name)}$tParam(params object[] args) - { - Bytecode.AddStep("$javaMethod.name", args); - return Wrap<$t1, $t2>(this); - } -""") - } - csharpClass.append(" }\n}") - - final File file = new File(graphTraversalFile); - file.delete() - csharpClass.eachLine { file.append(it + "\n") } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GraphTraversalSourceGenerator.groovy ---------------------------------------------------------------------- diff --git a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GraphTraversalSourceGenerator.groovy b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GraphTraversalSourceGenerator.groovy deleted file mode 100644 index 7cb41da..0000000 --- a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GraphTraversalSourceGenerator.groovy +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.dotnet - -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource -import java.lang.reflect.* - -class GraphTraversalSourceGenerator { - - public static void create(final String graphTraversalSourceFile) { - - final StringBuilder csharpClass = new StringBuilder() - - csharpClass.append(CommonContentHelper.getLicense()) - - csharpClass.append( -""" -using System.Collections.Generic; -using Gremlin.Net.Process.Remote; -using Gremlin.Net.Process.Traversal.Strategy.Decoration; -using Gremlin.Net.Structure; - -namespace Gremlin.Net.Process.Traversal -{ - public class GraphTraversalSource - { - public ICollection<ITraversalStrategy> TraversalStrategies { get; set; } - public Bytecode Bytecode { get; set; } - - public GraphTraversalSource() - : this(new List<ITraversalStrategy>(), new Bytecode()) - { - } - - public GraphTraversalSource(ICollection<ITraversalStrategy> traversalStrategies, Bytecode bytecode) - { - TraversalStrategies = traversalStrategies; - Bytecode = bytecode; - } -""" - ) - - GraphTraversalSource.getMethods(). // SOURCE STEPS - findAll { GraphTraversalSource.class.equals(it.returnType) }. - findAll { - !it.name.equals("clone") && - // replace by TraversalSource.Symbols.XXX - !it.name.equals("withBindings") && - !it.name.equals("withRemote") && - !it.name.equals("withComputer") - }. - collect { it.name }. - unique(). - sort { a, b -> a <=> b }. - forEach { javaMethodName -> - String sharpMethodName = SymbolHelper.toCSharp(javaMethodName) - - csharpClass.append( -""" - public GraphTraversalSource ${sharpMethodName}(params object[] args) - { - var source = new GraphTraversalSource(new List<ITraversalStrategy>(TraversalStrategies), - new Bytecode(Bytecode)); - source.Bytecode.AddSource("${javaMethodName}\", args); - return source; - } -""") - } - - csharpClass.append( - """ - public GraphTraversalSource WithBindings(object bindings) - { - return this; - } - - public GraphTraversalSource WithRemote(IRemoteConnection remoteConnection) - { - var source = new GraphTraversalSource(new List<ITraversalStrategy>(TraversalStrategies), - new Bytecode(Bytecode)); - source.TraversalStrategies.Add(new RemoteStrategy(remoteConnection)); - return source; - } - - public GraphTraversalSource WithComputer(string graphComputer = null, int? workers = null, string persist = null, - string result = null, ITraversal vertices = null, ITraversal edges = null, - Dictionary<string, dynamic> configuration = null) - { - return WithStrategies(new VertexProgramStrategy(graphComputer, workers, persist, result, vertices, edges, configuration)); - } -""") - - GraphTraversalSource.getMethods(). - findAll { GraphTraversal.class.equals(it.returnType) }. - unique{ a -> a.name }. - sort { a, b -> a.name <=> b.name }. - forEach { javaMethod -> - String sharpMethodName = SymbolHelper.toCSharp(javaMethod.name); - Type[] typeArguments = ((ParameterizedType)javaMethod.getGenericReturnType()).actualTypeArguments; - if (typeArguments.length != 2 || !(typeArguments[0] instanceof Class)) { - return; - } - def returnType = """GraphTraversal<${ - ((Class)typeArguments[0]).getSimpleName()}, ${((Class)typeArguments[1]).getSimpleName()}>"""; - - - csharpClass.append( - """ - public ${returnType} ${sharpMethodName}(params object[] args) - { - var traversal = new ${returnType}(TraversalStrategies, new Bytecode(Bytecode)); - traversal.Bytecode.AddStep("${javaMethod.name}\", args); - return traversal; - } -""") - } - - csharpClass.append(" }\n}") - - final File file = new File(graphTraversalSourceFile); - file.delete() - csharpClass.eachLine { file.append(it + "\n") } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/PredicateGenerator.groovy ---------------------------------------------------------------------- diff --git a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/PredicateGenerator.groovy b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/PredicateGenerator.groovy deleted file mode 100644 index c5c9c10..0000000 --- a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/PredicateGenerator.groovy +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.dotnet - -import org.apache.tinkerpop.gremlin.process.traversal.P - -import java.lang.reflect.Modifier - -class PredicateGenerator { - - public static void create(final String predicateFile) { - - final StringBuilder csharpClass = new StringBuilder() - - csharpClass.append(CommonContentHelper.getLicense()) - - csharpClass.append( -""" - -namespace Gremlin.Net.Process.Traversal -{ - public class P - {""") - P.class.getMethods(). - findAll { Modifier.isStatic(it.getModifiers()) }. - findAll { P.class.isAssignableFrom(it.returnType) }. - collect { it.name }. - unique(). - sort { a, b -> a <=> b }. - each { javaMethodName -> - String sharpMethodName = SymbolHelper.toCSharp(javaMethodName) - csharpClass.append( -""" - public static TraversalPredicate ${sharpMethodName}(params object[] args) - { - var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("${javaMethodName}", value); - } -""") - } - csharpClass.append(" }\n}") - - final File file = new File(predicateFile) - file.delete() - csharpClass.eachLine { file.append(it + "\n") } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/SymbolHelper.groovy ---------------------------------------------------------------------- diff --git a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/SymbolHelper.groovy b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/SymbolHelper.groovy deleted file mode 100644 index c041062..0000000 --- a/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/SymbolHelper.groovy +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.dotnet - -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; - -public final class SymbolHelper { - - private static final Map<String, String> TO_CSHARP_TYPE_MAP = new HashMap<>(); - - static { - TO_CSHARP_TYPE_MAP.put("Long", "long"); - TO_CSHARP_TYPE_MAP.put("Integer", "int"); - TO_CSHARP_TYPE_MAP.put("String", "string"); - TO_CSHARP_TYPE_MAP.put("Object", "object"); - TO_CSHARP_TYPE_MAP.put("java.util.Map<java.lang.String, E2>", "IDictionary<string, E2>"); - TO_CSHARP_TYPE_MAP.put("java.util.Map<java.lang.String, B>", "IDictionary<string, E2>") - TO_CSHARP_TYPE_MAP.put("java.util.List<E>", "IList<E>"); - TO_CSHARP_TYPE_MAP.put("java.util.List<A>", "IList<object>"); - TO_CSHARP_TYPE_MAP.put("java.util.Map<K, V>", "IDictionary<K, V>"); - TO_CSHARP_TYPE_MAP.put("java.util.Collection<E2>", "ICollection<E2>"); - TO_CSHARP_TYPE_MAP.put("java.util.Collection<B>", "ICollection<E2>") - TO_CSHARP_TYPE_MAP.put("java.util.Map<K, java.lang.Long>", "IDictionary<K, long>"); - TO_CSHARP_TYPE_MAP.put("TraversalMetrics", "E2"); - } - - public static String toCSharp(final String symbol) { - return (String) Character.toUpperCase(symbol.charAt(0)) + symbol.substring(1) - } - - public static String toJava(final String symbol) { - return (String) Character.toLowerCase(symbol.charAt(0)) + symbol.substring(1) - } - - public static String toCSharpType(final String name) { - String typeName = TO_CSHARP_TYPE_MAP.getOrDefault(name, name); - if (typeName.equals(name) && (typeName.contains("? extends") || typeName.equals("Tree"))) { - typeName = "E2"; - } - return typeName; - } - - public static String[] getJavaParameterTypeNames(final Method method) { - def typeArguments = ((ParameterizedType)method.genericReturnType).actualTypeArguments; - return typeArguments. - collect { (it instanceof Class) ? ((Class)it).simpleName : it.typeName }. - collect { name -> - if (name.equals("A")) { - name = "object"; - } - else if (name.equals("B")) { - name = "E2"; - } - name; - }; - } - - public static String getCSharpGenericTypeParam(String typeName) { - def tParam = ""; - if (typeName.contains("E2")) { - tParam = "<E2>"; - } - else if (typeName.contains("<K, V>")) { - tParam = "<K, V>"; - } - else if (typeName.contains("<K, ")) { - tParam = "<K>"; - } - return tParam; - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet/glv/AnonymousTraversal.template ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/glv/AnonymousTraversal.template b/gremlin-dotnet/glv/AnonymousTraversal.template new file mode 100644 index 0000000..33002bf --- /dev/null +++ b/gremlin-dotnet/glv/AnonymousTraversal.template @@ -0,0 +1,45 @@ +#region License + +/* + * 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. + */ + +#endregion + +using System.Collections.Generic; +using Gremlin.Net.Structure; + +namespace Gremlin.Net.Process.Traversal +{ + /// <summary> + /// THIS IS A GENERATED CLASS - DO NOT MODIFY THIS CLASS DIRECTLY - see pom.xml + /// </summary> + public static class __ + { + public static GraphTraversal<object, object> Start() + { + return new GraphTraversal<object, object>(); + } +<% anonStepMethods.each { method -> %> + public static GraphTraversal<object, <%= method.t2 %>> <%= toCSharpMethodName.call(method.methodName) %><%= method.tParam %>(params object[] args) + { + return new GraphTraversal<object, object>().<%= toCSharpMethodName.call(method.methodName) %><%= method.tParam %>(args); + } +<% } %> + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet/glv/Enum.template ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/glv/Enum.template b/gremlin-dotnet/glv/Enum.template new file mode 100644 index 0000000..664db45 --- /dev/null +++ b/gremlin-dotnet/glv/Enum.template @@ -0,0 +1,33 @@ +#region License + +/* + * 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. + */ + +#endregion + +namespace Gremlin.Net.Process.Traversal +{ + /// <summary> + /// THIS IS A GENERATED CLASS - DO NOT MODIFY THIS CLASS DIRECTLY - see pom.xml + /// </summary> + public enum <%= enumClass.simpleName %> + { + <%= constants %> + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet/glv/GraphTraversal.template ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/glv/GraphTraversal.template b/gremlin-dotnet/glv/GraphTraversal.template new file mode 100644 index 0000000..b782ffa --- /dev/null +++ b/gremlin-dotnet/glv/GraphTraversal.template @@ -0,0 +1,64 @@ +#region License + +/* + * 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. + */ + +#endregion + +using System.Collections.Generic; +using Gremlin.Net.Structure; + +namespace Gremlin.Net.Process.Traversal +{ + /// <summary> + /// THIS IS A GENERATED CLASS - DO NOT MODIFY THIS CLASS DIRECTLY - see pom.xml + /// </summary> + public class GraphTraversal<S, E> : DefaultTraversal<S, E> + { + public GraphTraversal() + : this(new List<ITraversalStrategy>(), new Bytecode()) + { + } + + public GraphTraversal(ICollection<ITraversalStrategy> traversalStrategies, Bytecode bytecode) + { + TraversalStrategies = traversalStrategies; + Bytecode = bytecode; + } + + private static GraphTraversal<S2, E2> Wrap<S2, E2>(GraphTraversal<S, E> traversal) + { + if (typeof(S2) == typeof(S) && typeof(E2) == typeof(E)) + { + return traversal as GraphTraversal<S2, E2>; + } + // New wrapper + return new GraphTraversal<S2, E2>(traversal.TraversalStrategies, traversal.Bytecode); + } + +<% graphStepMethods.each { method -> %> + public GraphTraversal< <%= method.t1 %> , <%= method.t2 %> > <%= toCSharpMethodName.call(method.methodName) %><%= method.tParam %> (params object[] args) + { + Bytecode.AddStep("<%= method.methodName %>", args); + return Wrap< <%= method.t1 %> , <%= method.t2 %> >(this); + } +<% } %> + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet/glv/GraphTraversalSource.template ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/glv/GraphTraversalSource.template b/gremlin-dotnet/glv/GraphTraversalSource.template new file mode 100644 index 0000000..880f793 --- /dev/null +++ b/gremlin-dotnet/glv/GraphTraversalSource.template @@ -0,0 +1,88 @@ +#region License + +/* + * 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. + */ + +#endregion + +using System.Collections.Generic; +using Gremlin.Net.Process.Remote; +using Gremlin.Net.Process.Traversal.Strategy.Decoration; +using Gremlin.Net.Structure; + +namespace Gremlin.Net.Process.Traversal +{ + /// <summary> + /// THIS IS A GENERATED CLASS - DO NOT MODIFY THIS CLASS DIRECTLY - see pom.xml + /// </summary> + public class GraphTraversalSource + { + public ICollection<ITraversalStrategy> TraversalStrategies { get; set; } + public Bytecode Bytecode { get; set; } + + public GraphTraversalSource() + : this(new List<ITraversalStrategy>(), new Bytecode()) + { + } + + public GraphTraversalSource(ICollection<ITraversalStrategy> traversalStrategies, Bytecode bytecode) + { + TraversalStrategies = traversalStrategies; + Bytecode = bytecode; + } + +<% sourceStepMethods.each{ method -> %> + public GraphTraversalSource <%= toCSharpMethodName.call(method) %>(params object[] args) + { + var source = new GraphTraversalSource(new List<ITraversalStrategy>(TraversalStrategies), + new Bytecode(Bytecode)); + source.Bytecode.AddSource("<%= method %>", args); + return source; + } +<% } %> + public GraphTraversalSource WithBindings(object bindings) + { + return this; + } + + public GraphTraversalSource WithRemote(IRemoteConnection remoteConnection) + { + var source = new GraphTraversalSource(new List<ITraversalStrategy>(TraversalStrategies), + new Bytecode(Bytecode)); + source.TraversalStrategies.Add(new RemoteStrategy(remoteConnection)); + return source; + } + + public GraphTraversalSource WithComputer(string graphComputer = null, int? workers = null, string persist = null, + string result = null, ITraversal vertices = null, ITraversal edges = null, + Dictionary<string, dynamic> configuration = null) + { + return WithStrategies(new VertexProgramStrategy(graphComputer, workers, persist, result, vertices, edges, configuration)); + } + +<% sourceSpawnMethods.each { method -> %> + public GraphTraversal< <%= method.typeArguments.join(",") %> > <%= toCSharpMethodName.call(method.methodName) %>(params object[] args) + { + var traversal = new GraphTraversal< <%= method.typeArguments.join(",") %> >(TraversalStrategies, new Bytecode(Bytecode)); + traversal.Bytecode.AddStep("<%= method.methodName %>", args); + return traversal; + } +<% } %> + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet/glv/NamingConversions.template ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/glv/NamingConversions.template b/gremlin-dotnet/glv/NamingConversions.template new file mode 100644 index 0000000..b997dee --- /dev/null +++ b/gremlin-dotnet/glv/NamingConversions.template @@ -0,0 +1,52 @@ +#region License + +/* + * 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. + */ + +#endregion + +using System.Collections.Generic; + +namespace Gremlin.Net.Process.Traversal +{ + /// <summary> + /// THIS IS A GENERATED CLASS - DO NOT MODIFY THIS CLASS DIRECTLY - see pom.xml + /// </summary> + internal static class NamingConversions + { + /// <summary> + /// Gets the Java name equivalent for a given enum value + /// </summary> + internal static string GetEnumJavaName(string typeName, string value) + { + var key = \$"{typeName}.{value}"; + string javaName; + if (!CSharpToJavaEnums.TryGetValue(key, out javaName)) + { + throw new KeyNotFoundException(\$"Java name for {key} not found"); + } + return javaName; + } + + internal static readonly IDictionary<string, string> CSharpToJavaEnums = new Dictionary<string, string> + { + <%= body %> + }; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet/glv/P.template ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/glv/P.template b/gremlin-dotnet/glv/P.template new file mode 100644 index 0000000..5be695d --- /dev/null +++ b/gremlin-dotnet/glv/P.template @@ -0,0 +1,39 @@ +#region License + +/* + * 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. + */ + +#endregion + +namespace Gremlin.Net.Process.Traversal +{ + /// <summary> + /// THIS IS A GENERATED CLASS - DO NOT MODIFY THIS CLASS DIRECTLY - see pom.xml + /// </summary> + public class P + { +<% pmethods.each { method -> %> + public static TraversalPredicate <%= toCSharpMethodName.call(method) %>(params object[] args) + { + var value = args.Length == 1 ? args[0] : args; + return new TraversalPredicate("<%= method %>", value); + } +<% } %> + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet/pom.xml ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/pom.xml b/gremlin-dotnet/pom.xml index ea3ae12..4bdf1e3 100644 --- a/gremlin-dotnet/pom.xml +++ b/gremlin-dotnet/pom.xml @@ -28,8 +28,8 @@ limitations under the License. <packaging>pom</packaging> <modules> - <module>test</module> <module>src</module> + <module>test</module> </modules> <build> @@ -40,6 +40,233 @@ limitations under the License. <extensions>true</extensions> <version>0.14</version> </plugin> + <plugin> + <groupId>org.codehaus.gmavenplus</groupId> + <artifactId>gmavenplus-plugin</artifactId> + <dependencies> + <dependency> + <groupId>org.apache.tinkerpop</groupId> + <artifactId>gremlin-core</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.codehaus.groovy</groupId> + <artifactId>groovy-all</artifactId> + <version>${groovy.version}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.17</version> + <scope>runtime</scope> + </dependency> + </dependencies> + <executions> + <execution> + <id>generate-dsl</id> + <phase>generate-sources</phase> + <goals> + <goal>execute</goal> + </goals> + <configuration> + <scripts> + <script><![CDATA[ +import org.apache.tinkerpop.gremlin.jsr223.CoreImports +import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource +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.P +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ +import org.apache.tinkerpop.gremlin.structure.Direction +import java.lang.reflect.Modifier + +def toCSharpTypeMap = ["Long": "long", + "Integer": "int", + "String": "string", + "Object": "object", + "java.util.Map<java.lang.String, E2>": "IDictionary<string, E2>", + "java.util.Map<java.lang.String, B>": "IDictionary<string, E2>", + "java.util.List<E>": "IList<E>", + "java.util.Map<K, V>": "IDictionary<K, V>", + "java.util.Collection<E2>": "ICollection<E2>", + "java.util.Collection<B>": "ICollection<E2>", + "java.util.Map<K, java.lang.Long>": "IDictionary<K, long>", + "TraversalMetrics": "E2"] + +def useE2 = ["E2", "E2"]; +def methodsWithSpecificTypes = ["constant": useE2, + "limit": useE2, + "mean": useE2, + "optional": useE2, + "range": useE2, + "select": ["IDictionary<string, E2>", "E2"], + "sum": useE2, + "tail": useE2, + "tree": ["object"], + "unfold": useE2] + +def getCSharpGenericTypeParam = { typeName -> + def tParam = "" + if (typeName.contains("E2")) { + tParam = "<E2>" + } + else if (typeName.contains("<K, V>")) { + tParam = "<K, V>" + } + else if (typeName.contains("<K, ")) { + tParam = "<K>" + } + return tParam +} + +def toCSharpType = { name -> + String typeName = toCSharpTypeMap.getOrDefault(name, name); + if (typeName.equals(name) && (typeName.contains("? extends") || typeName.equals("Tree"))) { + typeName = "E2" + } + return typeName; +} + +def toCSharpMethodName = { symbol -> (String) Character.toUpperCase(symbol.charAt(0)) + symbol.substring(1) } + +def getJavaParameterTypeNames = { method -> + def typeArguments = method.genericReturnType.actualTypeArguments; + return typeArguments. + collect { (it instanceof Class) ? ((Class)it).simpleName : it.typeName }. + collect { name -> + if (name.equals("A")) { + name = "object" + } + else if (name.equals("B")) { + name = "E2"; + } + name + } +} + +def binding = ["pmethods": P.class.getMethods(). + findAll { Modifier.isStatic(it.getModifiers()) }. + findAll { P.class.isAssignableFrom(it.returnType) }. + collect { it.name }. + unique(). + sort { a, b -> a <=> b }, + "sourceStepMethods": GraphTraversalSource.getMethods(). // SOURCE STEPS + findAll { GraphTraversalSource.class.equals(it.returnType) }. + findAll { + !it.name.equals("clone") && + !it.name.equals(TraversalSource.Symbols.withBindings) && + !it.name.equals(TraversalSource.Symbols.withRemote) && + !it.name.equals(TraversalSource.Symbols.withComputer) + }. + collect { it.name }. + unique(). + sort { a, b -> a <=> b }, + "sourceSpawnMethods": GraphTraversalSource.getMethods(). // SPAWN STEPS + findAll { GraphTraversal.class.equals(it.returnType) && !it.name.equals('inject')}. + collect { [methodName: it.name, typeArguments: it.genericReturnType.actualTypeArguments.collect{t -> ((java.lang.Class)t).simpleName}] }. + unique(). + sort { a, b -> a.methodName <=> b.methodName }, + "graphStepMethods": GraphTraversal.getMethods(). + findAll { GraphTraversal.class.equals(it.returnType) }. + findAll { !it.name.equals("clone") && !it.name.equals("iterate") }. + groupBy { it.name }. + // Select unique by name, with the most amount of parameters + collect { it.value.sort { a, b -> b.parameterCount <=> a.parameterCount }.first() }. + sort { a, b -> a.name <=> b.name }. + collect { javaMethod -> + def typeNames = getJavaParameterTypeNames(javaMethod) + def t1 = toCSharpType(typeNames[0]) + def t2 = toCSharpType(typeNames[1]) + def tParam = getCSharpGenericTypeParam(t2) + return ["methodName": javaMethod.name, "t1":t1, "t2":t2, "tParam":tParam] + }, + "anonStepMethods": __.class.getMethods(). + findAll { GraphTraversal.class.equals(it.returnType) }. + findAll { Modifier.isStatic(it.getModifiers()) }. + findAll { !it.name.equals("__") && !it.name.equals("start") }. + groupBy { it.name }. + // Select unique by name, with the most amount of parameters + collect { it.value.sort { a, b -> b.parameterCount <=> a.parameterCount }.first() }. + sort { it.name }. + collect { javaMethod -> + def typeNames = getJavaParameterTypeNames(javaMethod) + def t2 = toCSharpType(typeNames[1]) + def tParam = getCSharpGenericTypeParam(t2) + def specificTypes = methodsWithSpecificTypes.get(javaMethod.name) + if (specificTypes) { + t2 = specificTypes[0] + tParam = specificTypes.size() > 1 ? "<" + specificTypes[1] + ">" : "" + } + return ["methodName": javaMethod.name, "t2":t2, "tParam":tParam] + }, + "toCSharpMethodName": toCSharpMethodName] + +def engine = new groovy.text.GStringTemplateEngine() +def traversalTemplate = engine.createTemplate(new File('${project.basedir}/glv/GraphTraversal.template')).make(binding) +def traversalFile = new File('${project.basedir}/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs') +traversalFile.newWriter().withWriter{ it << traversalTemplate } + +def graphTraversalTemplate = engine.createTemplate(new File('${project.basedir}/glv/GraphTraversalSource.template')).make(binding) +def graphTraversalFile = new File('${project.basedir}/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs') +graphTraversalFile.newWriter().withWriter{ it << graphTraversalTemplate } + +def anonymousTraversalTemplate = engine.createTemplate(new File('${project.basedir}/glv/AnonymousTraversal.template')).make(binding) +def anonymousTraversalFile = new File('${project.basedir}/src/Gremlin.Net/Process/Traversal/__.cs') +anonymousTraversalFile.newWriter().withWriter{ it << anonymousTraversalTemplate } + +def pTemplate = engine.createTemplate(new File('${project.basedir}/glv/P.template')).make(binding) +def pFile = new File('${project.basedir}/src/Gremlin.Net/Process/Traversal/P.cs') +pFile.newWriter().withWriter{ it << pTemplate } + +// Process enums +def toCSharpName = { enumClass, itemName -> + if (enumClass.equals(Direction.class)) { + itemName = itemName.toLowerCase() + } + + return itemName.substring(0, 1).toUpperCase() + itemName.substring(1) +} + +def createEnum = { enumClass, csharpToJava -> + def b = ["enumClass": enumClass, + "constants": enumClass.getEnumConstants(). + sort { a, b -> a.name() <=> b.name() }. + collect { value -> + def csharpName = toCSharpName(enumClass, value.name()) + csharpToJava.put(enumClass.simpleName + "." + csharpName, value.name()) + return csharpName + }.join(",")] + + def enumTemplate = engine.createTemplate(new File('${project.basedir}/glv/Enum.template')).make(b) + def enumFile = new File('${project.basedir}/src/Gremlin.Net/Process/Traversal/' + enumClass.getSimpleName() + '.cs') + enumFile.newWriter().withWriter{ it << enumTemplate } +} + +def enumCSharpToJavaNames = [:] +CoreImports.getClassImports().findAll { Enum.class.isAssignableFrom(it) }. + sort { a, b -> a.getSimpleName() <=> b.getSimpleName() }. + each { createEnum(it, enumCSharpToJavaNames) } + +def lastIndex = (enumCSharpToJavaNames.size() - 1); +def body = new StringBuilder() +enumCSharpToJavaNames.eachWithIndex{ node, i -> + body.append("""{"$node.key", "$node.value"}""") + body.append(i == lastIndex ? "\n" : ",\n ") +} + +def namingConversionsTemplate = engine.createTemplate(new File('${project.basedir}/glv/NamingConversions.template')).make(["body":body]) +def namingConversionsFile = new File('${project.basedir}/src/Gremlin.Net/Process/Traversal/NamingConversions.cs') +namingConversionsFile.newWriter().withWriter{ it << namingConversionsTemplate } + +]]> + </script> + </scripts> + </configuration> + </execution> + </executions> + </plugin> </plugins> </build> </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Barrier.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Barrier.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Barrier.cs index 6ef1d4f..543fda6 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Barrier.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Barrier.cs @@ -23,8 +23,11 @@ namespace Gremlin.Net.Process.Traversal { + /// <summary> + /// THIS IS A GENERATED CLASS - DO NOT MODIFY THIS CLASS DIRECTLY - see pom.xml + /// </summary> public enum Barrier { NormSack } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Cardinality.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Cardinality.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Cardinality.cs index b158d09..b47dd32 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Cardinality.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Cardinality.cs @@ -23,10 +23,11 @@ namespace Gremlin.Net.Process.Traversal { + /// <summary> + /// THIS IS A GENERATED CLASS - DO NOT MODIFY THIS CLASS DIRECTLY - see pom.xml + /// </summary> public enum Cardinality { - List, - Set, - Single + List,Set,Single } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Column.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Column.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Column.cs index 0f3556c..063c26e 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Column.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Column.cs @@ -23,9 +23,11 @@ namespace Gremlin.Net.Process.Traversal { + /// <summary> + /// THIS IS A GENERATED CLASS - DO NOT MODIFY THIS CLASS DIRECTLY - see pom.xml + /// </summary> public enum Column { - Keys, - Values + Keys,Values } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Direction.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Direction.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Direction.cs index 100296c..5f6717e 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Direction.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Direction.cs @@ -23,10 +23,11 @@ namespace Gremlin.Net.Process.Traversal { + /// <summary> + /// THIS IS A GENERATED CLASS - DO NOT MODIFY THIS CLASS DIRECTLY - see pom.xml + /// </summary> public enum Direction { - Both, - In, - Out + Both,In,Out } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21843ce4/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphSONVersion.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphSONVersion.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphSONVersion.cs new file mode 100644 index 0000000..c72ae8e --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphSONVersion.cs @@ -0,0 +1,33 @@ +#region License + +/* + * 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. + */ + +#endregion + +namespace Gremlin.Net.Process.Traversal +{ + /// <summary> + /// THIS IS A GENERATED CLASS - DO NOT MODIFY THIS CLASS DIRECTLY - see pom.xml + /// </summary> + public enum GraphSONVersion + { + V1_0,V2_0 + } +} \ No newline at end of file
