Rename gremlin-csharp-generator to gremlin-dotnet-generator
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/3f8d2f50 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/3f8d2f50 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/3f8d2f50 Branch: refs/heads/tp32 Commit: 3f8d2f50122d4a04682ebe598bee28b5f37b813e Parents: f61227b Author: Florian Hockmann <[email protected]> Authored: Tue Jun 6 17:50:55 2017 +0200 Committer: Stephen Mallette <[email protected]> Committed: Wed Jun 28 15:13:11 2017 -0400 ---------------------------------------------------------------------- gremlin-csharp-generator/pom.xml | 75 ---------- .../csharp/AnonymousTraversalGenerator.groovy | 71 ---------- .../gremlin/csharp/CommonContentHelper.groovy | 49 ------- .../gremlin/csharp/EnumGenerator.groovy | 62 --------- .../gremlin/csharp/GenerateGremlinCSharp.groovy | 32 ----- .../csharp/GraphTraversalGenerator.groovy | 76 ---------- .../csharp/GraphTraversalSourceGenerator.groovy | 139 ------------------- .../gremlin/csharp/PredicateGenerator.groovy | 65 --------- .../gremlin/csharp/SymbolHelper.groovy | 31 ----- gremlin-dotnet-generator/pom.xml | 75 ++++++++++ .../dotnet/AnonymousTraversalGenerator.groovy | 71 ++++++++++ .../gremlin/dotnet/CommonContentHelper.groovy | 49 +++++++ .../gremlin/dotnet/EnumGenerator.groovy | 62 +++++++++ .../gremlin/dotnet/GenerateGremlinDotNet.groovy | 32 +++++ .../dotnet/GraphTraversalGenerator.groovy | 76 ++++++++++ .../dotnet/GraphTraversalSourceGenerator.groovy | 139 +++++++++++++++++++ .../gremlin/dotnet/PredicateGenerator.groovy | 65 +++++++++ .../gremlin/dotnet/SymbolHelper.groovy | 31 +++++ pom.xml | 2 +- 19 files changed, 601 insertions(+), 601 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3f8d2f50/gremlin-csharp-generator/pom.xml ---------------------------------------------------------------------- diff --git a/gremlin-csharp-generator/pom.xml b/gremlin-csharp-generator/pom.xml deleted file mode 100644 index 4e8989a..0000000 --- a/gremlin-csharp-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-csharp-generator</artifactId> - <name>Apache TinkerPop :: Gremlin-CSharp 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-csharp</id> - <phase>generate-test-resources</phase> - <goals> - <goal>java</goal> - </goals> - <configuration> - <mainClass>org.apache.tinkerpop.gremlin.csharp.GenerateGremlinCSharp</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/3f8d2f50/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/AnonymousTraversalGenerator.groovy ---------------------------------------------------------------------- diff --git a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/AnonymousTraversalGenerator.groovy b/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/AnonymousTraversalGenerator.groovy deleted file mode 100644 index ccb22fc..0000000 --- a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/AnonymousTraversalGenerator.groovy +++ /dev/null @@ -1,71 +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.csharp - -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 { - - public static void create(final String anonymousTraversalFile) { - - final StringBuilder csharpClass = new StringBuilder() - - csharpClass.append(CommonContentHelper.getLicense()) - - csharpClass.append( -""" -namespace Gremlin.Net.Process.Traversal -{ - public static class __ - { - public static GraphTraversal Start() - { - return new GraphTraversal(); - } -""") - __.getMethods(). - findAll { GraphTraversal.class.equals(it.returnType) }. - findAll { Modifier.isStatic(it.getModifiers()) }. - collect { it.name }. - findAll { !it.equals("__") && !it.equals("start") }. - unique(). - sort { a, b -> a <=> b }. - forEach { javaMethodName -> - String sharpMethodName = SymbolHelper.toCSharp(javaMethodName) - - csharpClass.append( -""" - public static GraphTraversal ${sharpMethodName}(params object[] args) - { - return new GraphTraversal().${sharpMethodName}(args); - } -""") - } - csharpClass.append("\t}\n") - csharpClass.append("}") - - final File file = new File(anonymousTraversalFile); - file.delete() - csharpClass.eachLine { file.append(it + "\n") } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3f8d2f50/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/CommonContentHelper.groovy ---------------------------------------------------------------------- diff --git a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/CommonContentHelper.groovy b/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/CommonContentHelper.groovy deleted file mode 100644 index c44bcfa..0000000 --- a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/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.csharp - -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/3f8d2f50/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/EnumGenerator.groovy ---------------------------------------------------------------------- diff --git a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/EnumGenerator.groovy b/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/EnumGenerator.groovy deleted file mode 100644 index 9214e0f..0000000 --- a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/EnumGenerator.groovy +++ /dev/null @@ -1,62 +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.csharp - -import org.apache.tinkerpop.gremlin.util.CoreImports - -class EnumGenerator { - - public static void create(final String enumDirectory) { - - for (final Class<? extends Enum> enumClass : CoreImports.getClassImports() - .findAll { Enum.class.isAssignableFrom(it) } - .sort { a, b -> a.getSimpleName() <=> b.getSimpleName() } - .collect()) { - createEnum(enumDirectory, enumClass) - } - } - - private static void createEnum(final String enumDirectory, final Class<? extends Enum> enumClass){ - 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 -> csharpEnum.append(" ${value.name()},\n"); } - 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/3f8d2f50/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/GenerateGremlinCSharp.groovy ---------------------------------------------------------------------- diff --git a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/GenerateGremlinCSharp.groovy b/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/GenerateGremlinCSharp.groovy deleted file mode 100644 index 53eba17..0000000 --- a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/GenerateGremlinCSharp.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.csharp - -public class GenerateGremlinCSharp { - - public static void main(String[] args) { - final String csharpDirectory = args[0] - GraphTraversalSourceGenerator.create(csharpDirectory + "/Process/Traversal/" + "GraphTraversalSource.cs") - GraphTraversalGenerator.create(csharpDirectory + "/Process/Traversal/" + "GraphTraversal.cs") - AnonymousTraversalGenerator.create(csharpDirectory + "/Process/Traversal/" + "__.cs") - EnumGenerator.create(csharpDirectory + "/Process/Traversal/") - PredicateGenerator.create(csharpDirectory + "/Process/Traversal/" + "P.cs") - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3f8d2f50/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/GraphTraversalGenerator.groovy ---------------------------------------------------------------------- diff --git a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/GraphTraversalGenerator.groovy b/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/GraphTraversalGenerator.groovy deleted file mode 100644 index f8ecfb1..0000000 --- a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/GraphTraversalGenerator.groovy +++ /dev/null @@ -1,76 +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.csharp - -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; - -namespace Gremlin.Net.Process.Traversal -{ - public class GraphTraversal : DefaultTraversal - { - public GraphTraversal() - : this(new List<ITraversalStrategy>(), new Bytecode()) - { - } - - public GraphTraversal(ICollection<ITraversalStrategy> traversalStrategies, Bytecode bytecode) - { - TraversalStrategies = traversalStrategies; - Bytecode = bytecode; - } -""") - GraphTraversal.getMethods(). - findAll { GraphTraversal.class.equals(it.returnType) }. - findAll { !it.name.equals("clone") && !it.name.equals("iterate") }. - collect { it.name }. - unique(). - sort { a, b -> a <=> b }. - forEach { javaMethodName -> - String sharpMethodName = SymbolHelper.toCSharp(javaMethodName) - - csharpClass.append( - """ - public GraphTraversal ${sharpMethodName}(params object[] args) - { - Bytecode.AddStep("${javaMethodName}", args); - return this; - } -""") - } - csharpClass.append("\t}\n") - csharpClass.append("}") - - final File file = new File(graphTraversalFile); - file.delete() - csharpClass.eachLine { file.append(it + "\n") } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3f8d2f50/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/GraphTraversalSourceGenerator.groovy ---------------------------------------------------------------------- diff --git a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/GraphTraversalSourceGenerator.groovy b/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/GraphTraversalSourceGenerator.groovy deleted file mode 100644 index 6b93d73..0000000 --- a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/GraphTraversalSourceGenerator.groovy +++ /dev/null @@ -1,139 +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.csharp - -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource - - -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; - -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; - } -""" - ) - - // Hold the list of methods with their overloads, so we do not create duplicates - HashMap<String, ArrayList<String>> sharpMethods = new HashMap<String, ArrayList<String>>() - - 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(). // SPAWN STEPS - findAll { GraphTraversal.class.equals(it.returnType) }. - collect { it.name }. - unique(). - sort { a, b -> a <=> b }. - forEach { javaMethodName -> - String sharpMethodName = SymbolHelper.toCSharp(javaMethodName) - - csharpClass.append( - """ - public GraphTraversal ${sharpMethodName}(params object[] args) - { - var traversal = new GraphTraversal(TraversalStrategies, new Bytecode(Bytecode)); - traversal.Bytecode.AddStep("${javaMethodName}\", args); - return traversal; - } -""") - } - - csharpClass.append("\t}\n") - csharpClass.append("}") - - 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/3f8d2f50/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/PredicateGenerator.groovy ---------------------------------------------------------------------- diff --git a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/PredicateGenerator.groovy b/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/PredicateGenerator.groovy deleted file mode 100644 index 0748ae9..0000000 --- a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/PredicateGenerator.groovy +++ /dev/null @@ -1,65 +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.csharp - -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("\t}\n") - csharpClass.append("}") - - final File file = new File(predicateFile) - file.delete() - csharpClass.eachLine { file.append(it + "\n") } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3f8d2f50/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/SymbolHelper.groovy ---------------------------------------------------------------------- diff --git a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/SymbolHelper.groovy b/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/SymbolHelper.groovy deleted file mode 100644 index 10591d7..0000000 --- a/gremlin-csharp-generator/src/main/groovy/org/apache/tinkerpop/gremlin/csharp/SymbolHelper.groovy +++ /dev/null @@ -1,31 +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.csharp - -public final class SymbolHelper { - - 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) - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3f8d2f50/gremlin-dotnet-generator/pom.xml ---------------------------------------------------------------------- diff --git a/gremlin-dotnet-generator/pom.xml b/gremlin-dotnet-generator/pom.xml new file mode 100644 index 0000000..a0a9ff6 --- /dev/null +++ b/gremlin-dotnet-generator/pom.xml @@ -0,0 +1,75 @@ +<!-- +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/3f8d2f50/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 new file mode 100644 index 0000000..ca5fadb --- /dev/null +++ b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/AnonymousTraversalGenerator.groovy @@ -0,0 +1,71 @@ +/* + * 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 { + + public static void create(final String anonymousTraversalFile) { + + final StringBuilder csharpClass = new StringBuilder() + + csharpClass.append(CommonContentHelper.getLicense()) + + csharpClass.append( +""" +namespace Gremlin.Net.Process.Traversal +{ + public static class __ + { + public static GraphTraversal Start() + { + return new GraphTraversal(); + } +""") + __.getMethods(). + findAll { GraphTraversal.class.equals(it.returnType) }. + findAll { Modifier.isStatic(it.getModifiers()) }. + collect { it.name }. + findAll { !it.equals("__") && !it.equals("start") }. + unique(). + sort { a, b -> a <=> b }. + forEach { javaMethodName -> + String sharpMethodName = SymbolHelper.toCSharp(javaMethodName) + + csharpClass.append( +""" + public static GraphTraversal ${sharpMethodName}(params object[] args) + { + return new GraphTraversal().${sharpMethodName}(args); + } +""") + } + csharpClass.append("\t}\n") + csharpClass.append("}") + + final File file = new File(anonymousTraversalFile); + file.delete() + csharpClass.eachLine { file.append(it + "\n") } + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3f8d2f50/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 new file mode 100644 index 0000000..825e230 --- /dev/null +++ b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/CommonContentHelper.groovy @@ -0,0 +1,49 @@ +/* + * 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/3f8d2f50/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 new file mode 100644 index 0000000..799e001 --- /dev/null +++ b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/EnumGenerator.groovy @@ -0,0 +1,62 @@ +/* + * 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 + +class EnumGenerator { + + public static void create(final String enumDirectory) { + + for (final Class<? extends Enum> enumClass : CoreImports.getClassImports() + .findAll { Enum.class.isAssignableFrom(it) } + .sort { a, b -> a.getSimpleName() <=> b.getSimpleName() } + .collect()) { + createEnum(enumDirectory, enumClass) + } + } + + private static void createEnum(final String enumDirectory, final Class<? extends Enum> enumClass){ + 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 -> csharpEnum.append(" ${value.name()},\n"); } + 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/3f8d2f50/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 new file mode 100644 index 0000000..0d09d5b --- /dev/null +++ b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GenerateGremlinDotNet.groovy @@ -0,0 +1,32 @@ +/* + * 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/3f8d2f50/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 new file mode 100644 index 0000000..58a3991 --- /dev/null +++ b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GraphTraversalGenerator.groovy @@ -0,0 +1,76 @@ +/* + * 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; + +namespace Gremlin.Net.Process.Traversal +{ + public class GraphTraversal : DefaultTraversal + { + public GraphTraversal() + : this(new List<ITraversalStrategy>(), new Bytecode()) + { + } + + public GraphTraversal(ICollection<ITraversalStrategy> traversalStrategies, Bytecode bytecode) + { + TraversalStrategies = traversalStrategies; + Bytecode = bytecode; + } +""") + GraphTraversal.getMethods(). + findAll { GraphTraversal.class.equals(it.returnType) }. + findAll { !it.name.equals("clone") && !it.name.equals("iterate") }. + collect { it.name }. + unique(). + sort { a, b -> a <=> b }. + forEach { javaMethodName -> + String sharpMethodName = SymbolHelper.toCSharp(javaMethodName) + + csharpClass.append( + """ + public GraphTraversal ${sharpMethodName}(params object[] args) + { + Bytecode.AddStep("${javaMethodName}", args); + return this; + } +""") + } + csharpClass.append("\t}\n") + csharpClass.append("}") + + final File file = new File(graphTraversalFile); + file.delete() + csharpClass.eachLine { file.append(it + "\n") } + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3f8d2f50/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 new file mode 100644 index 0000000..fce4b70 --- /dev/null +++ b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/GraphTraversalSourceGenerator.groovy @@ -0,0 +1,139 @@ +/* + * 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 + + +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; + +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; + } +""" + ) + + // Hold the list of methods with their overloads, so we do not create duplicates + HashMap<String, ArrayList<String>> sharpMethods = new HashMap<String, ArrayList<String>>() + + 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(). // SPAWN STEPS + findAll { GraphTraversal.class.equals(it.returnType) }. + collect { it.name }. + unique(). + sort { a, b -> a <=> b }. + forEach { javaMethodName -> + String sharpMethodName = SymbolHelper.toCSharp(javaMethodName) + + csharpClass.append( + """ + public GraphTraversal ${sharpMethodName}(params object[] args) + { + var traversal = new GraphTraversal(TraversalStrategies, new Bytecode(Bytecode)); + traversal.Bytecode.AddStep("${javaMethodName}\", args); + return traversal; + } +""") + } + + csharpClass.append("\t}\n") + csharpClass.append("}") + + 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/3f8d2f50/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 new file mode 100644 index 0000000..2633de6 --- /dev/null +++ b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/PredicateGenerator.groovy @@ -0,0 +1,65 @@ +/* + * 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("\t}\n") + csharpClass.append("}") + + final File file = new File(predicateFile) + file.delete() + csharpClass.eachLine { file.append(it + "\n") } + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3f8d2f50/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 new file mode 100644 index 0000000..6c237e8 --- /dev/null +++ b/gremlin-dotnet-generator/src/main/groovy/org/apache/tinkerpop/gremlin/dotnet/SymbolHelper.groovy @@ -0,0 +1,31 @@ +/* + * 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 SymbolHelper { + + 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) + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3f8d2f50/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index d619278..888e35d 100644 --- a/pom.xml +++ b/pom.xml @@ -121,7 +121,7 @@ limitations under the License. <module>gremlin-groovy-test</module> <module>tinkergraph-gremlin</module> <module>gremlin-python</module> - <module>gremlin-csharp-generator</module> + <module>gremlin-dotnet-generator</module> <module>gremlin-dotnet</module> <module>hadoop-gremlin</module> <module>spark-gremlin</module>
